From d43c0ef2f3d5a8ac48e2b5eaba7f7fbd5f5a54ba Mon Sep 17 00:00:00 2001 From: rheo-chiti Date: Sat, 11 Apr 2020 20:27:57 +0530 Subject: [PATCH] added module for ECI --- ali.js | 16 +++++- compute/ali-eci.js | 133 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 compute/ali-eci.js diff --git a/ali.js b/ali.js index a9825a9..65ffe19 100644 --- a/ali.js +++ b/ali.js @@ -2,6 +2,7 @@ const ECS = require("./compute/ali-ecs"); const SLB = require("./networking/ali-slb"); const RDS = require("./database/ali-rds"); const OSS = require("./storage/ali-oss"); +const ECI = require("./compute/ali-eci"); class AliCloud { /** @@ -24,7 +25,8 @@ class AliCloud { ecs: this.ECS, slb: this.SLB, rds: this.RDS, - oss: this.OSS + oss: this.OSS, + eci: this.ECI }; } @@ -40,6 +42,18 @@ class AliCloud { ); } + /** + * Compute - ECI Wrapper + * @ECI + */ + ECI() { + return new ECI( + this.getSDK(), + this.getAccessKeyId(), + this.getSecretAccessKey() + ); + } + /** * Networking - SLB Wrapper * @SLB diff --git a/compute/ali-eci.js b/compute/ali-eci.js new file mode 100644 index 0000000..1decebb --- /dev/null +++ b/compute/ali-eci.js @@ -0,0 +1,133 @@ +class ECI { + /** + * ECI constructor + * @constructor + * @param {object} aliSdk - AliCloud SDK + * @param {string} accessKeyId - User Access Key ID + * @param {string} secretAccessKey - User Secret Access Key + */ + constructor(aliSdk, accessKeyId, secretAccessKey) { + this._aliSDK = aliSdk; + this._client = new this._aliSDK({ + accessKeyId: accessKeyId, + accessKeySecret: secretAccessKey, + endpoint: "https://eci.aliyuncs.com", + apiVersion: "2018-08-08" + }); + this._requestOption = { method: "POST" }; + } + + /** + * Create an ECI Container Group + * @createContainerGroup + * @param {object} params + */ + createContainerGroup(params) { + return new Promise((resolve, reject) => { + this._client.request("CreateContainerGroup", params, this._requestOption).then( + result => { + resolve(result); + }, + ex => { + reject(ex); + } + ); + }); + } + + /** + * List all ECI Container Groups + * @listContainerGroups + * @param {object} params + */ + listContainerGroups(params) { + return new Promise((resolve, reject) => { + this._client + .request("DescribeContainerGroups", params, this._requestOption) + .then( + result => { + resolve(result); + }, + ex => { + reject(ex); + } + ); + }); + } + + /** + * Update an ECI Container Group + * @updateContainerGroup + * @param {object} params + */ + updateContainerGroup(params) { + return new Promise((resolve, reject) => { + this._client.request("UpdateContainerGroup", params, this._requestOption).then( + result => { + resolve(result); + }, + ex => { + reject(ex); + } + ); + }); + } + + /** + * List ECI Container Group Regions + * @listRegions + * @param {object} params + */ + listRegions(params) { + return new Promise((resolve, reject) => { + this._client.request("DescribeRegions", params, this._requestOption).then( + result => { + resolve(result); + }, + ex => { + reject(ex); + } + ); + }); + } + + /** + * Restart an ECI Container Group + * @restartContainerGroup + * @param {object} params + */ + restartContainerGroup(params) { + return new Promise((resolve, reject) => { + this._client + .request("RestartContainerGroup", params, this._requestOption) + .then( + result => { + resolve(result); + }, + ex => { + reject(ex); + } + ); + }); + } + + /** + * Delete an ECI Container Group + * @deleteContainerGroup + * @param {object} params + */ + deleteContainerGroup(params) { + return new Promise((resolve, reject) => { + this._client.request("DeleteContainerGroup", params, this._requestOption).then( + result => { + resolve(result); + }, + ex => { + reject(ex); + } + ); + }); + } +} + +module.exports = ECI;