-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSDK.js
More file actions
127 lines (110 loc) · 3.19 KB
/
SDK.js
File metadata and controls
127 lines (110 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Author: Peter Farmer
*/
const vmFuncs = require('./SDK/virtualmachines')
const volFuncs = require('./SDK/volumes')
const templateFuncs = require('./SDK/templates')
const networkFuncs = require('./SDK/networks')
const soFuncs = require('./SDK/serviceofferings')
function VDC(url, key, secret, update) {
this.client = new (require('cloudstack'))({
apiUri: url || process.env.CLOUDSTACK_API_URI,
apiKey: key || process.env.CLOUDSTACK_API_KEY,
apiSecret: secret || process.env.CLOUDSTACK_API_SECRET,
});
this.virtualmachines = {
'ready': false,
'list': [],
'search': function (search) {
return vmFuncs.searchVMs(this, search);
},
};
this.zones = {
'ready': false,
'list': []
};
this.templates = {
'ready': false,
'list': []
}
this.serviceofferings = {
'ready': false,
'list': [],
'search': function (search, field) {
return soFuncs.search(this, search, field);
}
}
this.volumes = {
'ready': false,
'list': [],
'search': function (search) {
return volFuncs.searchVols(this, search);
},
}
this.networks = {
'ready': false,
'list': []
}
this.diskofferings = {
'ready': false,
'list': [],
}
this.lastError = "";
return this;
}
/* Virtual Machine functions */
VDC.prototype.listVirtualMachines = vmFuncs.listVirtualMachines;
/* Volume functions */
VDC.prototype.listVolumes = volFuncs.listVolumes;
VDC.prototype.createVolume = volFuncs.createVolume;
VDC.prototype.listDiskOfferings = volFuncs.listDiskOfferings;
VDC.prototype.attachVolume = volFuncs.attachVolume;
/* Service offering functions */
VDC.prototype.listServiceOfferings = soFuncs.listServiceOfferings;
/* General functions */
VDC.prototype.listZones = function (callback) {
this.zones.ready = false;
this.client.exec('listZones', {}, (error, result) => {
if (error) {
console.log(error)
this.lastError = error;
typeof callback === 'function' && callback(error, this);
}
this.zones.list = result.zone;
this.zones.ready = true;
typeof callback === 'function' && callback(null, this);
});
}
// VDC.prototype.listServiceOfferings = function (callback) {
// this.serviceofferings.ready = false;
// this.client.exec('listServiceOfferings', {}, (error, result) => {
// if (error) {
// this.lastError = error;
// typeof callback === 'function' && callback(error, this);
// }
// this.serviceofferings.list = result.serviceoffering;
// this.serviceofferings.ready = true;
// typeof callback === 'function' && callback(null, this);
// })
// }
VDC.prototype.listTemplates = templateFuncs.listTemplates;
VDC.prototype.listNetworks = networkFuncs.listNetworks;
VDC.prototype.deployVM = vmFuncs.deployVM;
// TODO: listAffinityGroups
// TODO: listAsyncJobs
// TODO: listEvents
// TODO: firewallrules
// TODO: listisos
// TODO: listnics
// TODO: listsnapshots
// TODO: listsnapshotpolicies
// TODO: listsshkeypairs
VDC.prototype.updateAll = function (callback) {
this.listZones();
this.listVirtualMachines();
this.listServiceOfferings();
this.listTemplates();
this.listNetworks();
typeof callback === 'function' && callback();
}
module.exports = VDC;