-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from masterchief01/plugin-usage
Add examples for plugin usage
- Loading branch information
Showing
6 changed files
with
348 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const nodeCloud = require('../../lib/'); | ||
const optionsProvider = { | ||
overrideProviders: false, | ||
}; | ||
const ncProviders = nodeCloud.getProviders(optionsProvider); | ||
|
||
// get containerInstance object for AliCloud | ||
const containers = ncProviders.alicloud.containerInstance(); | ||
|
||
async function createContainerGroup() { | ||
const instanceParams = { | ||
regionId: 'cn-hangzhou', | ||
containerGroupName: 'test-group-1', | ||
container: [ | ||
{ | ||
command: ['/bin/sh', '-c', 'echo 1'], | ||
cpu: 1, | ||
memory: 512, | ||
image: 'ubuntu', | ||
name: 'test-container-1', | ||
}, | ||
], | ||
}; | ||
try { | ||
const res = await containers.create(instanceParams); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function listContainerGroup() { | ||
try { | ||
const res = await containers.list({ regionId: 'cn-hangzhou' }); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function deleteContainerGroup() { | ||
try { | ||
const res = await containers.delete({ | ||
regionId: 'cn-hangzhou', | ||
containerGroupId: 'eci-bp1ikor0s871wa5pahke', | ||
}); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const nodeCloud = require('../../lib/'); | ||
const optionsProvider = { | ||
overrideProviders: false, | ||
}; | ||
const ncProviders = nodeCloud.getProviders(optionsProvider); | ||
|
||
// get compute object for AliCloud | ||
const compute = ncProviders.alicloud.computeInstance(); | ||
|
||
async function createInstance() { | ||
const instanceParams = { | ||
regionId: 'cn-hongkong', | ||
imageId: 'ubuntu_20_04_x64_20G_alibase_20220215.vhd', | ||
instanceType: 'ecs.n4.large', | ||
}; | ||
try { | ||
const res = await compute.create(instanceParams); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function listInstances() { | ||
try { | ||
const res = await compute.list({ regionId: 'cn-hongkong' }); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function destroyInstance() { | ||
try { | ||
const res = await compute.destroy({ instanceId: 'i-2zmq8q8' }); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function describeInstanceTypes() { | ||
try { | ||
const res = await compute.listInstanceTypes({ maxResults: 10 }); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function describeImageTypes() { | ||
try { | ||
const res = await compute.describeImages({ regionId: 'cn-hongkong' }); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const nodeCloud = require('../../lib/'); | ||
const optionsProvider = { | ||
overrideProviders: false, | ||
}; | ||
const ncProviders = nodeCloud.getProviders(optionsProvider); | ||
|
||
// get containerInstance object for AliCloud | ||
const nosql = ncProviders.alicloud.nosql(); | ||
|
||
async function createInstance() { | ||
const instanceParams = { | ||
regionId: 'ap-southeast-1', | ||
engine: 'MongoDB', | ||
engineVersion: '4.2', | ||
DBInstanceClass: 'dds.mongo.standard', | ||
DBInstanceStorage: 10, // GB | ||
}; | ||
try { | ||
const res = await nosql.createInstance(instanceParams); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function deleteInstance() { | ||
try { | ||
const res = await nosql.deleteInstance({ | ||
DBInstanceId: 'dds-gs58537d0d9724c4', | ||
}); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function listInstances() { | ||
try { | ||
const res = await nosql.listInstances({}); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function describeInstance() { | ||
try { | ||
const res = await nosql.describeInstance({ | ||
DBInstanceId: 'dds-gs5581f86ac37b14', | ||
}); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const nodeCloud = require('../../lib/'); | ||
const optionsProvider = { | ||
overrideProviders: false, | ||
}; | ||
const ncProviders = nodeCloud.getProviders(optionsProvider); | ||
|
||
// get containerInstance object for AliCloud | ||
const rdbms = ncProviders.alicloud.rdbms(); | ||
|
||
async function createInstance() { | ||
const instanceParams = { | ||
DBInstanceClass: 'rds.mysql.t1.small', | ||
regionId: 'ap-southeast-1', | ||
engine: 'MySQL', | ||
engineVersion: '5.6', | ||
DBInstanceStorage: 10, | ||
DBInstanceNetType: 'Intranet', | ||
securityIPList: '0.0.0.0/0', | ||
payType: 'Postpaid', | ||
DBInstanceStorageType: 'local_ssd', | ||
}; | ||
try { | ||
const res = await rdbms.createInstance(instanceParams); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function deleteInstance() { | ||
try { | ||
const res = await rdbms.deleteInstance({ | ||
DBInstanceId: 'rm-1udg1v5w25c8gmpx3', | ||
}); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function listInstances() { | ||
try { | ||
const res = await rdbms.listInstances({ regionId: 'ap-southeast-1' }); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const nodeCloud = require('../../lib/'); | ||
const optionsProvider = { | ||
overrideProviders: false, | ||
}; | ||
const ncProviders = nodeCloud.getProviders(optionsProvider); | ||
|
||
// get containerInstance object for AliCloud | ||
const loadbalancer = ncProviders.alicloud.loadbalancer(); | ||
|
||
async function createInstance() { | ||
try { | ||
const res = await loadbalancer.create( | ||
'cn-hangzhou', | ||
'test-slb', | ||
'slb.s1.small', | ||
{} | ||
); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function deleteInstance() { | ||
try { | ||
const res = await loadbalancer.delete('lb-1udjouk9sqkq5lvke5cd6', {}); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function listInstances() { | ||
try { | ||
const res = await loadbalancer.list('cn-hangzhou', {}); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function describeInstances() { | ||
try { | ||
const res = await loadbalancer.describe( | ||
'cn-hangzhou', | ||
'lb-1udjouk9sqkq5lvke5cd6', | ||
{} | ||
); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const nodeCloud = require('../../lib/'); | ||
const path = require('path'); | ||
const optionsProvider = { | ||
overrideProviders: false, | ||
}; | ||
const ncProviders = nodeCloud.getProviders(optionsProvider); | ||
|
||
// get bucketStorage object for AliCloud | ||
const bucketStorage = ncProviders.alicloud.bucketStorage(); | ||
|
||
async function createBucket() { | ||
try { | ||
const res = await bucketStorage.create('unique-test-bucket-1234', { | ||
acl: 'public-read', | ||
dataRedundancyType: 'LRS', | ||
storageClass: 'Standard', | ||
timeout: 30000, | ||
}); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function listBuckets() { | ||
try { | ||
const res = await bucketStorage.listBuckets({}); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function listBucketObjects() { | ||
try { | ||
const res = await bucketStorage.listBucketObjects( | ||
'unique-test-bucket-1234', | ||
{ | ||
'max-keys': 100, | ||
} | ||
); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} | ||
|
||
async function uploadLocalObject() { | ||
try { | ||
const headers = { | ||
// Specify the caching behavior of the web page when the object is downloaded. | ||
'Cache-Control': 'no-cache', | ||
// Specify the name of the object when the object is downloaded. | ||
'Content-Disposition': 'oss_download.txt', | ||
// Specify the content encoding format of the object when the object is downloaded. | ||
'Content-Encoding': 'UTF-8', | ||
// Specify the expiration time. | ||
Expires: 'Wed, 08 Jul 2022 16:57:01 GMT', | ||
// Specify the storage class of the object. | ||
'x-oss-storage-class': 'Standard', | ||
// Specify the access control list (ACL) of the object. | ||
'x-oss-object-acl': 'private', | ||
// Set tags for the object. You can set multiple tags at a time. | ||
'x-oss-tagging': 'Tag1=1&Tag2=2', | ||
// Specify whether the CopyObject operation overwrites the object with the same name. In this example, this parameter is set to true, which indicates that the object with the same name cannot be overwritten. | ||
'x-oss-forbid-overwrite': 'true', | ||
}; | ||
|
||
const res = await bucketStorage.uploadLocalObject( | ||
'unique-test-bucket-1234', | ||
'test.txt', | ||
path.normalize('absolute-file-path'), | ||
{ | ||
headers, //Optional, Specify the headers of the object on upload | ||
mime: 'text/plain', //Optional, Specify the content type on upload | ||
timeout: 30000, //Optional, Specify the timeout of the request on upload | ||
} | ||
); | ||
console.log('All done! ', res); | ||
} catch (err) { | ||
console.log(`Oops something happened ${err}`); | ||
} | ||
} |