-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathionosenterprise.js
254 lines (239 loc) · 12.8 KB
/
ionosenterprise.js
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/**
* Created by jasmin.gacic on 03/11/15.
*/
require('console.table')
var program = require('commander')
var pbclient = require('libionosenterprise')
var helpers = require('./helpers')
var fs = require('fs')
var prompt = require('prompt')
var datacenter = require('./features/datacenter')
var server = require('./features/server')
var volume = require('./features/volume')
var snapshot = require('./features/snapshot')
var loadbalancer = require('./features/loadbalancer')
var nic = require('./features/nic')
var ipblock = require('./features/ipblock')
var lan = require('./features/lan')
var drives = require('./features/drive')
var images = require('./features/image')
var request = require('./features/request')
var location = require('./features/location')
var firewall = require('./features/firewall')
var group = require('./features/group')
var user = require('./features/user')
var share = require('./features/share')
var resource = require('./features/resource')
var contract = require('./features/contract')
var s3 = require('./features/s3')
var k8s = require('./features/k8s')
global.force = false
pbclient.setdepth(5)
pbclient.setuseragent('CLI/5.1.0')
initializeCli()
parseParameters()
function initializeCli() {
program
.version('4.1.1')
.usage('[Options]')
.option('setup', 'Configures credentials for IonosEnterprise CLI')
.option('datacenter, [env]', 'Data center operations')
.option('server, [env]', 'Server operations')
.option('volume, [env]', 'Volume operations')
.option('snapshot, [env]', 'Snapshot operations')
.option('loadbalancer, [env]', 'Load Balancer operations')
.option('nic, [env]', 'NIC operations')
.option('firewall, [env]', 'Firewall Rule operations')
.option('ipblock, [env]', 'IP Block operations')
.option('drives, [env]', 'CD ROM drive operations')
.option('image, [env]', 'Image operations')
.option('lan, [env]', 'LAN operations')
.option('request, [env]', 'Request operations')
.option('location, [env]', 'Location operations')
.option('contract, [env]', 'Contract resources operations')
.option('group, [env]', 'Group operations')
.option('user, [env]', 'User operations')
.option('share, [env]', 'Share operations')
.option('resource, [env]', 'Resource operations')
.option('s3, [env]', 'S3 keys operations')
.option('k8s, [env]', 'K8S operations')
.option('-i, --id [env]', 'Id')
.option('-n, --name [env]', 'Name')
.option('-l, --location [env]', 'Location')
.option('-d, --description [env]', 'Description')
.option('-p, --path [env]', 'Path to JSON script')
.option('--datacenterid [env]', 'DatacenterId')
.option('--loadbalancerid [env]', 'LoadbalancerId')
.option('-r, --ram [env]', 'Ram size in multiples of 256 MB')
.option('-c, --cores [env]', 'Number of cores')
.option('-a, --availabilityzone [env]', 'Availability Zone')
.option('--licencetype [env]', 'Licence Type')
.option('--sshkey [env]', 'SSH key')
.option('--bootVolume [env]', 'Reference to a Volume used for booting')
.option('--bootCdrom [env]', 'Reference to a CD-ROM used for booting.')
.option('--volumeid [env]', 'Volume id')
.option('--volumesize [env]', 'Volume size')
.option('--volumename [env]', 'Volume name')
.option('--imageid [env]', 'Image id')
.option('--imagealias [env]', 'Image alias')
.option('-b --bus [env]', 'Bus type (VIRTIO or IDE)')
.option('-t --type [env]', 'The disk type.')
.option('--imagepassword [env]', 'One-time password is set on the Image for the appropriate account. Password has to contain 8-50 characters. Only these characters are allowed: [abcdefghjkmnpqrstuvxABCDEFGHJKLMNPQRSTUVX23456789]')
.option('-s, --size [env]', 'Size in GB')
.option('--cpuHotPlug', 'Volume is capable of CPU hot plug (no reboot required)')
.option('--cpuHotUnplug', 'Volume is capable of CPU hot unplug (no reboot required)')
.option('--ramHotPlug', 'Volume is capable of memory hot plug (no reboot required)')
.option('--ramHotUnplug', 'Volume is capable of memory hot unplug (no reboot required)')
.option('--nicHotPlug', 'Volume is capable of NIC hot plug (no reboot required)')
.option('--nicHotUnplug', 'Volume is capable of NIC hot unplug (no reboot required)')
.option('--discVirtioHotPlug', 'Volume is capable of Virt-IO drive hot plug (no reboot required)')
.option('--discVirtioHotUnplug', 'Volume is capable of Virt-IO drive hot unplug (no reboot required)')
.option('--discScsiHotPlug', 'Volume is capable of SCSI drive hot plug (no reboot required)')
.option('--discScsiHotUnplug', 'Volume is capable of SCSI drive hot unplug (no reboot required)')
.option('--ip [env]', 'IPv4 address of the loadbalancer.')
.option('--dhcp [env]', 'Indicates if the loadbalancer will reserve an IP using DHCP.')
.option('--serverid [env]', 'Server id')
.option('--cpufamily [env]', 'Sets the CPU type. "AMD_OPTERON" or "INTEL_XEON". Defaults to "AMD_OPTERON".')
.option('--lan [env]', 'The LAN ID the NIC will sit on. If the LAN ID does not exist it will be created.')
.option('--public [env]', 'Boolean indicating if the LAN faces the public Internet or not.')
.option('--ipfailover [env]', 'IP failover group, e.g. "ip1,nicid1;ip2,nicid2;ip3,nicid3..."')
.option('--requestid [env]', 'Request UUID')
.option('--nicid [env]', 'Network Interface UUID')
.option('--nat', 'NIC Network Address Translation')
.option('--protocol [env]', 'The protocol for the rule: TCP, UDP, ICMP, ANY.')
.option('--sourceMac [env]', 'Only traffic originating from the respective MAC address is allowed. Valid format: aa:bb:cc:dd:ee:ff. Value null allows all source MAC address.')
.option('--sourceIp [env]', 'Only traffic originating from the respective IPv4 address is allowed. Value null allows all source IPs.')
.option('--sourceIp [env]', 'Only traffic originating from the respective IPv4 address is allowed. Value null allows all source IPs.')
.option('--targetIp [env]', 'In case the target NIC has multiple IP addresses, only traffic directed to the respective IP address of the NIC is allowed. Value null allows all target IPs.')
.option('--targetIp [env]', 'In case the target NIC has multiple IP addresses, only traffic directed to the respective IP address of the NIC is allowed. Value null allows all target IPs.')
.option('--portRangeStart [env]', 'Defines the start range of the allowed port (from 1 to 65534) if protocol TCP or UDP is chosen. Leave portRangeStart and portRangeEnd value null to allow all ports.')
.option('--portRangeEnd [env]', 'Defines the end range of the allowed port (from 1 to 65534) if protocol TCP or UDP is chosen. Leave portRangeStart and portRangeEnd value null to allow all ports.')
.option('--portRangeEnd [env]', 'Defines the end range of the allowed port (from 1 to 65534) if protocol TCP or UDP is chosen. Leave portRangeStart and portRangeEnd value null to allow all ports.')
.option('--icmpType [env]', 'Defines the allowed type (from 0 to 254) if the protocol ICMP is chosen. Value null allows all types.')
.option('--icmpCode [env]', 'Defines the allowed code (from 0 to 254) if protocol ICMP is chosen. Value null allows all codes.')
.option('--groupid [env]', 'Group UUID')
.option('--resourceid [env]', 'Resource UUID')
.option('--resourcetype [env]', 'Resource type. "datacenter", "snapshot", "ipblock" or "image".')
.option('--editprivilege [env]', 'The group has permission to edit privileges on the resource.')
.option('--shareprivilege [env]', 'The group has permission to share the resource.')
.option('--createdatacenter [env]', 'Group will be allowed to create virtual data centers.')
.option('--createsnapshot [env]', 'Group will be allowed to create snapshots.')
.option('--reserveip [env]', 'Group will be allowed to reserve IP addresses.')
.option('--accessactlog [env]', 'Group will be allowed to access the activity log.')
.option('--firstname [env]', 'A first name for the user.')
.option('--lastname [env]', 'A last name for the user.')
.option('--email [env]', 'An email for the user.')
.option('--password [env]', 'A password for the user.')
.option('--admin [env]', 'Indicates if the user has administrative rights.')
.option('--forcesecauth [env]', 'Indicates if secure (two-factor) authentication should be forced for the user.')
.option('--json', 'Print results as JSON string')
.option('--addip [env]','Add IP')
.option('--removeip [env]', 'Remove IP')
.option('--adduser [env]', 'UUID of the user to add to a group')
.option('--removeuser [env]', 'UUID of the user to remove from a group')
.option('--ctresource [env]', 'Contract resources type [cores|ram|hdd|ssd|ips]')
.option('--ctresource [env]', 'Contract resources type [cores|ram|hdd|ssd|ips]')
.option('--userid [env]', 'ID of the user')
.option('--s3keyid [env]', 'S3 key ID')
.option('--k8sclusterid [env]', 'K8S cluster id')
.option('--k8sclustername [env]', 'K8S cluster name')
.option('--k8snodepoolid [env]', 'K8S node pool id')
.option('--k8snodepoolname [env]', 'K8S node pool name')
.option('--nodeCount [env]', 'Number of nodes')
.option('--storageType [env]', 'Storage type (SSD or HDD)')
.option('--storageSize [env]', 'Storage size (in Gi)')
.option('-f, --force', 'Forces execution')
.parse(process.argv)
}
function authenticate() {
prompt.start()
var schema = {
properties: {
username: {
required: true
},
password: {
hidden: true
}
}
}
prompt.get(schema, function (err, result) {
pbclient.setauth(result.username, result.password )
pbclient.listDatacenters(function (error, response, body) {
if (response && response.statusCode && response.statusCode == 200) {
helpers.toBase64(result.username, result.password)
} else {
console.error('Invalid user name or password. Please try again!')
process.exit(code = 5)
}
})
helpers.toBase64(result.username, result.password)
})
}
function parseParameters() {
if (!process.argv.slice(2).length) {
program.outputHelp()
return
}
if (program.json)
helpers.setJson(program.json)
if (program.force)
global.force = program.force
if (program.ctresource)
helpers.setContractResource(program.ctresource)
if (program.setup)
authenticate()
else {
try {
var authdata = helpers.getAuthData()
pbclient.auth(authdata)
} catch (err) {
console.log(err);
console.log("Please run 'ionosenterprise setup' to set up your authentication data.")
process.exit(code = 0)
}
if (program.datacenter)
datacenter.process(program)
else if (program.server)
server.process(program)
else if (program.volume)
volume.process(program)
else if (program.snapshot)
snapshot.process(program)
else if (program.loadbalancer)
loadbalancer.process(program)
else if (program.nic)
nic.process(program)
else if (program.ipblock)
ipblock.process(program)
else if (program.lan)
lan.process(program)
else if (program.drives)
drives.process(program)
else if (program.image)
images.process(program)
else if (program.firewall)
firewall.process(program)
else if (program.request)
request.process(program)
else if (program.group)
group.process(program)
else if (program.user)
user.process(program)
else if (program.share)
share.process(program)
else if (program.resource)
resource.process(program)
else if (program.contract)
contract.process(program)
else if (program.s3)
s3.process(program)
else if (program.k8s)
k8s.process(program)
else if (program.location){
location.process(program)
}
else
program.outputHelp()
}
}