UNPKG

csclient

Version:
78 lines (62 loc) 2.03 kB
var cloudstackConfig = { "url": "http://192.168.3.141:8080/client/api?" }; var CloudStackClient = require('./lib/cloudstack-client'); function test(msg, callback) { var msgContent = JSON.parse(msg.content); var params = msgContent.params; console.log(msgContent); var client = new CloudStackClient({ baseUrl: cloudstackConfig.url, apiKey: params.apiKey, secretKey: params.secretKey, singleExecutor: true, pollingTime: 2000, pollingNumber: -1 }); var args = params; delete args.apiKey; delete args.secretKey; args.response = 'json'; var callName = msgContent.call.split('_')[1]; client.on('ready', () => { client.execute(callName, args, function (err, response) { callback(err, response); }); }); } var listvolops = { content: JSON.stringify({ call: 'acs_listVolumes', params: { listall: true, "apiKey": "IOMezYL9Ys8fn7Qus4TPmz6dS06pgj2Py5SHQFE50mJZOlmFFbP_56-wMkg1GlRM8XqfhtA_1cuaqQ8sxjuJrw", "secretKey": "QTNsruK3SXyr99BR_6n4C6XctqzWNJHIGXghrGUmP-ow_8k7wGACBcatZVHbUsCy2w7ZvtM_kyFuTa4Gd5NWxQ" } }) }; var listvms = { content: JSON.stringify({ call: 'acs_listVirtualMachines', params: { listall: true, "apiKey": "IOMezYL9Ys8fn7Qus4TPmz6dS06pgj2Py5SHQFE50mJZOlmFFbP_56-wMkg1GlRM8XqfhtA_1cuaqQ8sxjuJrw", "secretKey": "QTNsruK3SXyr99BR_6n4C6XctqzWNJHIGXghrGUmP-ow_8k7wGACBcatZVHbUsCy2w7ZvtM_kyFuTa4Gd5NWxQ" } }) }; var createvolops = { content: JSON.stringify({ call: 'acs_createVolume', params: { "name": "test_disk_qq", "diskofferingid": "1851713e-a7af-442d-abf5-2ed1fe7674ee", "zoneid": "20e728a4-0e02-4d46-a779-801dbb79c82b", "apiKey": "IOMezYL9Ys8fn7Qus4TPmz6dS06pgj2Py5SHQFE50mJZOlmFFbP_56-wMkg1GlRM8XqfhtA_1cuaqQ8sxjuJrw", "secretKey": "QTNsruK3SXyr99BR_6n4C6XctqzWNJHIGXghrGUmP-ow_8k7wGACBcatZVHbUsCy2w7ZvtM_kyFuTa4Gd5NWxQ" } }) }; test (listvolops, function (err, res) { console.log(err, res); });