Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module for ECI #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion ali.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -24,7 +25,8 @@ class AliCloud {
ecs: this.ECS,
slb: this.SLB,
rds: this.RDS,
oss: this.OSS
oss: this.OSS,
eci: this.ECI
};
}

Expand All @@ -40,6 +42,18 @@ class AliCloud {
);
}

/**
* Compute - ECI Wrapper
* @ECI
*/
ECI() {
return new ECI(
this.getSDK(),
this.getAccessKeyId(),
this.getSecretAccessKey()
);
}

/**
* Networking - SLB Wrapper
* @SLB
Expand Down
133 changes: 133 additions & 0 deletions compute/ali-eci.js
Original file line number Diff line number Diff line change
@@ -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;