cloudstack_client 0.9.7 → 1.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -11
  3. data/bin/cloudstack_client +5 -0
  4. data/cloudstack_client.gemspec +2 -0
  5. data/config/4.2.json +1 -0
  6. data/lib/cloudstack_client/api.rb +29 -0
  7. data/lib/cloudstack_client/cli.rb +107 -0
  8. data/lib/cloudstack_client/client.rb +34 -127
  9. data/lib/cloudstack_client/connection.rb +131 -0
  10. data/lib/cloudstack_client/error.rb +9 -0
  11. data/lib/cloudstack_client/version.rb +1 -1
  12. data/lib/cloudstack_client.rb +0 -1
  13. metadata +38 -34
  14. data/lib/cloudstack_client/commands/account.rb +0 -38
  15. data/lib/cloudstack_client/commands/affinity_group.rb +0 -39
  16. data/lib/cloudstack_client/commands/capacity.rb +0 -30
  17. data/lib/cloudstack_client/commands/cluster.rb +0 -19
  18. data/lib/cloudstack_client/commands/configuration.rb +0 -42
  19. data/lib/cloudstack_client/commands/disk_offering.rb +0 -49
  20. data/lib/cloudstack_client/commands/domain.rb +0 -22
  21. data/lib/cloudstack_client/commands/host.rb +0 -28
  22. data/lib/cloudstack_client/commands/ip_address.rb +0 -83
  23. data/lib/cloudstack_client/commands/iso.rb +0 -76
  24. data/lib/cloudstack_client/commands/job.rb +0 -29
  25. data/lib/cloudstack_client/commands/load_balancer_rule.rb +0 -61
  26. data/lib/cloudstack_client/commands/network.rb +0 -130
  27. data/lib/cloudstack_client/commands/pod.rb +0 -20
  28. data/lib/cloudstack_client/commands/port_forwarding_rule.rb +0 -49
  29. data/lib/cloudstack_client/commands/project.rb +0 -32
  30. data/lib/cloudstack_client/commands/region.rb +0 -19
  31. data/lib/cloudstack_client/commands/resource_limit.rb +0 -125
  32. data/lib/cloudstack_client/commands/router.rb +0 -100
  33. data/lib/cloudstack_client/commands/server.rb +0 -350
  34. data/lib/cloudstack_client/commands/service_offering.rb +0 -98
  35. data/lib/cloudstack_client/commands/snapshot.rb +0 -51
  36. data/lib/cloudstack_client/commands/ssh_key_pair.rb +0 -137
  37. data/lib/cloudstack_client/commands/storage_pool.rb +0 -31
  38. data/lib/cloudstack_client/commands/system_vm.rb +0 -82
  39. data/lib/cloudstack_client/commands/template.rb +0 -60
  40. data/lib/cloudstack_client/commands/user.rb +0 -32
  41. data/lib/cloudstack_client/commands/volume.rb +0 -54
  42. data/lib/cloudstack_client/commands/zone.rb +0 -57
  43. data/lib/connection_helper.rb +0 -12
@@ -1,125 +0,0 @@
1
- module CloudstackClient
2
-
3
- module ResourceLimit
4
- ##
5
- # List resource limits.
6
-
7
- def list_resource_limits(args = {})
8
- params = {
9
- 'command' => 'listResourceLimits',
10
- }
11
-
12
- if args[:account]
13
- account = list_accounts({name: args[:account]}).first
14
- unless account
15
- puts "Error: Account #{args[:account]} not found."
16
- exit 1
17
- end
18
- params['domainid'] = account['domainid']
19
- params['account'] = args[:account]
20
- end
21
-
22
- if args[:project]
23
- project = get_project(args[:project])
24
- if !project
25
- msg = "Project '#{args[:project]}' is invalid"
26
- puts "Error: #{msg}"
27
- exit 1
28
- end
29
- params['projectid'] = project['id']
30
- elsif args[:project_id]
31
- params['projectid'] = args[:project_id]
32
- end
33
-
34
- params['type'] = args[:type] if args[:type]
35
-
36
- json = send_request(params)
37
- json['resourcelimit'] || []
38
- end
39
-
40
- ##
41
- # Recalculate and update resource count for an account or domain.
42
-
43
- def update_resource_count(args = {})
44
- params = {
45
- 'command' => 'updateResourceCount',
46
- }
47
-
48
- if args[:account]
49
- account = list_accounts({name: args[:account]}).first
50
- unless account
51
- puts "Error: Account #{args[:account]} not found."
52
- exit 1
53
- end
54
- params['domainid'] = account['domainid']
55
- params['account'] = args[:account]
56
- end
57
-
58
- if args[:project]
59
- project = get_project(args[:project])
60
- if !project
61
- msg = "Project '#{args[:project]}' is invalid"
62
- puts "Error: #{msg}"
63
- exit 1
64
- end
65
- params['domainid'] = project['domainid']
66
- params['projectid'] = project['id']
67
- elsif args[:project_id]
68
- params['projectid'] = args[:project_id]
69
- end
70
-
71
- params['resourcetype'] = args[:resource_type] if args[:resource_type]
72
- params['domainid'] = args[:domain_id] if args[:domain_id]
73
-
74
- json = send_request(params)
75
- json['resourcecount'] || []
76
- end
77
-
78
- ##
79
- # Updates resource limits for an account or domain.
80
-
81
- def update_resource_limit(args = {})
82
- params = {
83
- 'command' => 'updateResourceLimit',
84
- }
85
-
86
- if args[:resource_type]
87
- params['resourcetype'] = args[:resource_type]
88
- else
89
- puts "Error: Resource Type must be specified."
90
- exit 1
91
- end
92
-
93
- if args[:account]
94
- account = list_accounts({name: args[:account]}).first
95
- unless account
96
- puts "Error: Account #{args[:account]} not found."
97
- exit 1
98
- end
99
- params['domainid'] = account['domainid']
100
- params['account'] = args[:account]
101
- end
102
-
103
- if args[:project]
104
- project = get_project(args[:project])
105
- if !project
106
- msg = "Project '#{args[:project]}' is invalid"
107
- puts "Error: #{msg}"
108
- exit 1
109
- end
110
- params['domainid'] = project['domainid']
111
- params['projectid'] = project['id']
112
- elsif args[:project_id]
113
- params['projectid'] = args[:project_id]
114
- end
115
-
116
- params['domainid'] = args[:domain_id] if args[:domain_id]
117
- params['max'] = args[:max] if args[:max]
118
-
119
- json = send_request(params)
120
- json['resourcelimit'] || []
121
- end
122
-
123
- end
124
-
125
- end
@@ -1,100 +0,0 @@
1
- module CloudstackClient
2
-
3
- module Router
4
-
5
- ##
6
- # Get a router with a given name.
7
-
8
- def get_router(name, project_id = nil)
9
- params = {
10
- 'command' => 'listRouters',
11
- 'listall' => 'true',
12
- 'name' => name
13
- }
14
- params['projectid'] = project_id if project_id
15
-
16
- json = send_request(params)
17
- json['router'] ? json['router'].first : nil
18
- end
19
-
20
- ##
21
- # Lists all virtual routers.
22
-
23
- def list_routers(args = {:account => nil, :zone => nil, :projectid => nil, :status => nil, :name => nil})
24
- params = {
25
- 'command' => 'listRouters',
26
- 'listall' => 'true',
27
- 'isrecursive' => 'true'
28
- }
29
- if args[:zone]
30
- zone = get_zone(args[:zone])
31
- unless zone
32
- puts "Error: Zone #{args[:zone]} not found"
33
- exit 1
34
- end
35
- params['zoneid'] = zone['id']
36
- end
37
- params['projectid'] = args[:projectid] if args[:projectid]
38
- params['state'] = args[:status] if args[:status]
39
- params['name'] = args[:name] if args[:name]
40
- if args[:account]
41
- account = list_accounts({name: args[:account]}).first
42
- unless account
43
- puts "Error: Account #{args[:account]} not found."
44
- exit 1
45
- end
46
- params['domainid'] = account["domainid"]
47
- params['account'] = args[:account]
48
- end
49
-
50
- json = send_request(params)
51
- json['router'] || []
52
- end
53
-
54
- ##
55
- # Destroy virtual router.
56
-
57
- def destroy_router(id, opts = {async: true})
58
- params = {
59
- 'command' => 'destroyRouter',
60
- 'id' => id
61
- }
62
- opts[:async] ? send_async_request(params)['router'] : send_request(params)
63
- end
64
-
65
- ##
66
- # Start virtual router.
67
-
68
- def start_router(id, opts = {async: true})
69
- params = {
70
- 'command' => 'startRouter',
71
- 'id' => id
72
- }
73
- opts[:async] ? send_async_request(params)['router'] : send_request(params)
74
- end
75
-
76
- ##
77
- # Stop virtual router.
78
-
79
- def stop_router(id, opts = {async: true})
80
- params = {
81
- 'command' => 'stopRouter',
82
- 'id' => id
83
- }
84
- opts[:async] ? send_async_request(params)['router'] : send_request(params)
85
- end
86
-
87
- ##
88
- # Reboot virtual router.
89
-
90
- def reboot_router(id, opts = {async: true})
91
- params = {
92
- 'command' => 'rebootRouter',
93
- 'id' => id
94
- }
95
- opts[:async] ? send_async_request(params)['router'] : send_request(params)
96
- end
97
-
98
- end
99
-
100
- end
@@ -1,350 +0,0 @@
1
- module CloudstackClient
2
-
3
- module Server
4
-
5
- ##
6
- # Finds the server with the specified name.
7
-
8
- def get_server(name, args = {})
9
- params = {
10
- 'command' => 'listVirtualMachines',
11
- 'listAll' => true,
12
- 'name' => name
13
- }
14
-
15
- params['domainid'] = args[:domain_id] if args[:domain_id]
16
- if args[:account]
17
- account = list_accounts({name: args[:account]}).first
18
- unless account
19
- puts "Error: Account #{args[:account]} not found."
20
- exit 1
21
- end
22
- params['domainid'] = account["domainid"]
23
- params['account'] = args[:account]
24
- end
25
-
26
- if args[:project_id]
27
- params['projectid'] = args[:project_id]
28
- elsif args[:project]
29
- project = get_project(args[:project])
30
- if !project
31
- msg = "Project '#{args[:project]}' is invalid"
32
- puts "Error: #{msg}"
33
- exit 1
34
- end
35
- params['projectid'] = project['id']
36
- end
37
-
38
- json = send_request(params)
39
- machines = json['virtualmachine']
40
-
41
- if !machines || machines.empty? then
42
- return nil
43
- end
44
-
45
- machines.select {|m| m['name'] == name }.first
46
- end
47
-
48
- def get_server_state(id)
49
- params = {
50
- 'command' => 'listVirtualMachines',
51
- 'id' => id
52
- }
53
- json = send_request(params)
54
- machine_state = json['virtualmachine'][0]['state']
55
-
56
- if !machine_state || machine_state.empty?
57
- return nil
58
- end
59
-
60
- machine_state
61
- end
62
-
63
- def wait_for_server_state(id, state)
64
- while get_server_state(id) != state
65
- print '..'
66
- sleep 5
67
- end
68
- state
69
- end
70
-
71
- ##
72
- # Finds the public ip for a server
73
-
74
- def get_server_public_ip(server, cached_rules=nil)
75
- return nil unless server
76
-
77
- # find the public ip
78
- nic = get_server_default_nic(server) || {}
79
- if nic['type'] == 'Virtual'
80
- ssh_rule = get_ssh_port_forwarding_rule(server, cached_rules)
81
- ssh_rule ? ssh_rule['ipaddress'] : nil
82
- else
83
- nic['ipaddress']
84
- end
85
- end
86
-
87
- ##
88
- # Returns the fully qualified domain name for a server.
89
-
90
- def get_server_fqdn(server)
91
- return nil unless server
92
-
93
- nic = get_server_default_nic(server) || {}
94
- networks = list_networks(project_id: server['projectid']) || {}
95
-
96
- id = nic['networkid']
97
- network = networks.select { |net|
98
- net['id'] == id
99
- }.first
100
- return nil unless network
101
-
102
- "#{server['name']}.#{network['networkdomain']}"
103
- end
104
-
105
- def get_server_default_nic(server)
106
- server['nic'].each do |nic|
107
- return nic if nic['isdefault']
108
- end
109
- end
110
-
111
- ##
112
- # Lists servers.
113
-
114
- def list_servers(args = {})
115
- params = {
116
- 'command' => 'listVirtualMachines',
117
- 'listAll' => true
118
- }
119
- params.merge!(args[:custom]) if args[:custom]
120
-
121
- params['state'] = args[:state] if args[:state]
122
- params['state'] = args[:status] if args[:status]
123
- params['groupid'] = args[:group_id] if args[:group_id]
124
-
125
-
126
- if args[:zone]
127
- zone = get_zone(args[:zone])
128
- unless zone
129
- puts "Error: Zone #{args[:zone]} not found"
130
- exit 1
131
- end
132
- params['zoneid'] = zone['id']
133
- end
134
-
135
- if args[:account]
136
- account = list_accounts({name: args[:account]}).first
137
- unless account
138
- puts "Error: Account #{args[:account]} not found."
139
- exit 1
140
- end
141
- params['domainid'] = account["domainid"]
142
- params['account'] = args[:account]
143
- end
144
-
145
- if args[:project]
146
- project = get_project(args[:project])
147
- if !project
148
- msg = "Project '#{args[:project]}' is invalid"
149
- puts "Error: #{msg}"
150
- exit 1
151
- end
152
- params['projectid'] = project['id']
153
- elsif args[:project_id]
154
- params['projectid'] = args[:project_id]
155
- end
156
-
157
- json = send_request(params)
158
- json['virtualmachine'] || []
159
- end
160
-
161
- ##
162
- # Deploys a new server using the specified parameters.
163
-
164
- def create_server(args = {})
165
- params = {'command' => 'deployVirtualMachine'}
166
- params['keypair'] = args[:keypair] if args[:keypair]
167
- params['size'] = args[:disk_size] if args[:disk_size]
168
- params['group'] = args[:group] if args[:group]
169
- params['displayname'] = args[:displayname] if args[:displayname]
170
-
171
- if args[:account]
172
- account = list_accounts({name: args[:account]}).first
173
- unless account
174
- puts "Error: Account #{args[:account]} not found."
175
- exit 1
176
- end
177
- params['domainid'] = account["domainid"]
178
- params['account'] = args[:account]
179
- end
180
-
181
- if args[:project]
182
- project = get_project(args[:project])
183
- if !project
184
- msg = "Project '#{args[:project]}' is invalid"
185
- puts "Error: #{msg}"
186
- exit 1
187
- end
188
- params['projectid'] = project['id']
189
- elsif args[:project_id]
190
- params['projectid'] = args[:project_id]
191
- end
192
- params['name'] = args[:name] if args[:name]
193
-
194
- if args[:name]
195
- server = get_server(args[:name], project_id: params['projectid'])
196
- if server
197
- puts "Error: Server '#{args[:name]}' already exists."
198
- exit 1
199
- end
200
- end
201
-
202
- networks = []
203
- if args[:networks]
204
- args[:networks].each do |name|
205
- network = get_network(name, params['projectid'])
206
- if !network
207
- puts "Error: Network '#{name}' not found"
208
- exit 1
209
- end
210
- networks << network
211
- end
212
- end
213
- if networks.empty?
214
- unless default_network = get_default_network
215
- puts "Error: No default network found"
216
- exit 1
217
- end
218
- networks << default_network
219
- end
220
- network_ids = networks.map { |network|
221
- network['id']
222
- }
223
- params['networkids'] = network_ids.join(',')
224
-
225
- service = get_service_offering(args[:offering])
226
- if !service
227
- puts "Error: Service offering '#{args[:offering]}' is invalid"
228
- exit 1
229
- end
230
- params['serviceOfferingId'] = service['id']
231
-
232
- if args[:template]
233
- template = get_template(args[:template])
234
- if !template
235
- puts "Error: Template '#{args[:template]}' is invalid"
236
- exit 1
237
- end
238
- end
239
-
240
- if args[:disk_offering]
241
- disk_offering = get_disk_offering(args[:disk_offering])
242
- unless disk_offering
243
- msg = "Disk offering '#{args[:disk_offering]}' is invalid"
244
- puts "Error: #{msg}"
245
- exit 1
246
- end
247
- params['diskofferingid'] = disk_offering['id']
248
- end
249
-
250
- if args[:iso]
251
- iso = get_iso(args[:iso])
252
- unless iso
253
- puts "Error: Iso '#{args[:iso]}' is invalid"
254
- exit 1
255
- end
256
- unless disk_offering
257
- puts "Error: a disk offering is required when using iso"
258
- exit 1
259
- end
260
- params['hypervisor'] = (args[:hypervisor] || 'vmware')
261
- end
262
-
263
- if !template && !iso
264
- puts "Error: Iso or Template is required"
265
- exit 1
266
- end
267
- params['templateId'] = template ? template['id'] : iso['id']
268
-
269
- zone = args[:zone] ? get_zone(args[:zone]) : get_default_zone
270
- if !zone
271
- msg = args[:zone] ? "Zone '#{args[:zone]}' is invalid" : "No default zone found"
272
- puts "Error: #{msg}"
273
- exit 1
274
- end
275
- params['zoneid'] = zone['id']
276
-
277
- args[:sync] ? send_request(params) : send_async_request(params)['virtualmachine']
278
- end
279
-
280
- ##
281
- # Stops the server with the specified name.
282
- #
283
-
284
- def stop_server(name, args = {})
285
- server = get_server(name, args)
286
- if !server || !server['id']
287
- puts "Error: Virtual machine '#{name}' does not exist"
288
- exit 1
289
- end
290
-
291
- params = {
292
- 'command' => 'stopVirtualMachine',
293
- 'id' => server['id']
294
- }
295
- params['forced'] = true if args[:forced]
296
- args[:sync] ? send_request(params) : send_async_request(params)['virtualmachine']
297
- end
298
-
299
- ##
300
- # Start the server with the specified name.
301
- #
302
-
303
- def start_server(name, args = {})
304
- server = get_server(name, args)
305
- if !server || !server['id']
306
- puts "Error: Virtual machine '#{name}' does not exist"
307
- exit 1
308
- end
309
-
310
- params = {
311
- 'command' => 'startVirtualMachine',
312
- 'id' => server['id']
313
- }
314
- args[:sync] ? send_request(params) : send_async_request(params)['virtualmachine']
315
- end
316
-
317
- ##
318
- # Reboot the server with the specified name.
319
- #
320
-
321
- def reboot_server(name, args = {})
322
- server = get_server(name, args)
323
- if !server || !server['id']
324
- puts "Error: Virtual machine '#{name}' does not exist"
325
- exit 1
326
- end
327
-
328
- params = {
329
- 'command' => 'rebootVirtualMachine',
330
- 'id' => server['id']
331
- }
332
- args[:sync] ? send_request(params) : send_async_request(params)['virtualmachine']
333
- end
334
-
335
- ##
336
- # Destroy the server with the specified name.
337
- #
338
-
339
- def destroy_server(id, args = {})
340
- params = {
341
- 'command' => 'destroyVirtualMachine',
342
- 'id' => id
343
- }
344
- params['expunge'] = true if args[:expunge]
345
- args[:sync] ? send_request(params) : send_async_request(params)['virtualmachine']
346
- end
347
-
348
- end
349
-
350
- end
@@ -1,98 +0,0 @@
1
- module CloudstackClient
2
-
3
- module ServiceOffering
4
-
5
- ##
6
- # Finds the service offering with the specified name.
7
-
8
- def get_service_offering(name)
9
-
10
- # TODO: use name parameter
11
- # listServiceOfferings in CloudStack 2.2 doesn't seem to work
12
- # when the name parameter is specified. When this is fixed,
13
- # the name parameter should be added to the request.
14
- params = {
15
- 'command' => 'listServiceOfferings'
16
- }
17
- json = send_request(params)
18
-
19
- services = json['serviceoffering']
20
- return nil unless services
21
-
22
- services.each { |s|
23
- if s['name'] == name then
24
- return s
25
- end
26
- }
27
- nil
28
- end
29
-
30
- ##
31
- # Lists all available service offerings.
32
-
33
- def list_service_offerings(domain = nil)
34
- params = {
35
- 'command' => 'listServiceOfferings'
36
- }
37
-
38
- if domain
39
- params['domainid'] = list_domains(domain).first["id"]
40
- end
41
-
42
- json = send_request(params)
43
- json['serviceoffering'] || []
44
- end
45
-
46
- ##
47
- # Create a service offering.
48
-
49
- def create_offering(args)
50
- params = {
51
- 'command' => 'createServiceOffering',
52
- 'name' => args[:name],
53
- 'cpunumber' => args[:cpunumber],
54
- 'cpuspeed' => args[:cpuspeed],
55
- 'displaytext' => args[:displaytext],
56
- 'memory' => args[:memory]
57
- }
58
-
59
- if args['domain']
60
- params['domainid'] = list_domains(args['domain']).first["id"]
61
- end
62
-
63
- params['tags'] = args[:tags] if args[:tags]
64
- params['offerha'] = 'true' if args[:ha]
65
-
66
- json = send_request(params)
67
- json['serviceoffering'].first
68
- end
69
-
70
- ##
71
- # Delete a service offering.
72
-
73
- def delete_offering(id)
74
- params = {
75
- 'command' => 'deleteServiceOffering',
76
- 'id' => id
77
- }
78
-
79
- json = send_request(params)
80
- json['success']
81
- end
82
-
83
- def update_offering(args)
84
- params = {
85
- 'command' => 'updateServiceOffering',
86
- 'id' => args['id']
87
- }
88
- params['name'] = args['name'] if args['name']
89
- params['displaytext'] = args['displaytext'] if args['displaytext']
90
- params['sortkey'] = args['sortkey'] if args['sortkey']
91
-
92
- json = send_request(params)
93
- json['serviceoffering']
94
- end
95
-
96
- end
97
-
98
- end