cloudstack-cli 0.3.11 → 0.4.0

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 (34) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile.lock +3 -1
  3. data/bin/cs +1 -2
  4. data/cloudstack-cli.gemspec +1 -0
  5. data/lib/{cloudstack_cli.rb → cloudstack-cli.rb} +2 -0
  6. data/lib/cloudstack-cli/commands/router.rb +3 -1
  7. data/lib/cloudstack-cli/version.rb +1 -1
  8. metadata +24 -44
  9. data/lib/cloudstack-client/client.rb +0 -136
  10. data/lib/cloudstack-client/commands/account.rb +0 -22
  11. data/lib/cloudstack-client/commands/capacity.rb +0 -19
  12. data/lib/cloudstack-client/commands/cluster.rb +0 -19
  13. data/lib/cloudstack-client/commands/disk_offering.rb +0 -49
  14. data/lib/cloudstack-client/commands/domain.rb +0 -22
  15. data/lib/cloudstack-client/commands/host.rb +0 -28
  16. data/lib/cloudstack-client/commands/ip_address.rb +0 -82
  17. data/lib/cloudstack-client/commands/iso.rb +0 -64
  18. data/lib/cloudstack-client/commands/job.rb +0 -29
  19. data/lib/cloudstack-client/commands/load_balancer_rule.rb +0 -61
  20. data/lib/cloudstack-client/commands/network.rb +0 -128
  21. data/lib/cloudstack-client/commands/pod.rb +0 -19
  22. data/lib/cloudstack-client/commands/port_forwarding_rule.rb +0 -49
  23. data/lib/cloudstack-client/commands/project.rb +0 -32
  24. data/lib/cloudstack-client/commands/router.rb +0 -89
  25. data/lib/cloudstack-client/commands/server.rb +0 -311
  26. data/lib/cloudstack-client/commands/service_offering.rb +0 -98
  27. data/lib/cloudstack-client/commands/snapshot.rb +0 -40
  28. data/lib/cloudstack-client/commands/ssh_key_pair.rb +0 -106
  29. data/lib/cloudstack-client/commands/template.rb +0 -60
  30. data/lib/cloudstack-client/commands/user.rb +0 -32
  31. data/lib/cloudstack-client/commands/volume.rb +0 -20
  32. data/lib/cloudstack-client/commands/zone.rb +0 -57
  33. data/lib/cloudstack-client/version.rb +0 -3
  34. data/lib/cloudstack_client.rb +0 -2
@@ -1,32 +0,0 @@
1
- module CloudstackClient
2
-
3
- module Project
4
-
5
- ##
6
- # Get project by name.
7
-
8
- def get_project(name)
9
- params = {
10
- 'command' => 'listProjects',
11
- 'name' => name,
12
- 'listall' => true,
13
- }
14
- json = send_request(params)
15
- json['project'] ? json['project'].first : nil
16
- end
17
-
18
- ##
19
- # Lists projects.
20
-
21
- def list_projects
22
- params = {
23
- 'command' => 'listProjects',
24
- 'listall' => true,
25
- }
26
- json = send_request(params)
27
- json['project'] || []
28
- end
29
-
30
- end
31
-
32
- end
@@ -1,89 +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
- end
88
-
89
- end
@@ -1,311 +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, project_id=nil)
9
- params = {
10
- 'command' => 'listVirtualMachines',
11
- 'name' => name
12
- }
13
- params['projectid'] = project_id if project_id
14
- json = send_request(params)
15
- machines = json['virtualmachine']
16
-
17
- if !machines || machines.empty? then
18
- return nil
19
- end
20
-
21
- machines.select {|m| m['name'] == name }.first
22
- end
23
-
24
- def get_server_state(id)
25
- params = {
26
- 'command' => 'listVirtualMachines',
27
- 'id' => id
28
- }
29
- json = send_request(params)
30
- machine_state = json['virtualmachine'][0]['state']
31
-
32
- if !machine_state || machine_state.empty?
33
- return nil
34
- end
35
-
36
- machine_state
37
- end
38
-
39
- def wait_for_server_state(id, state)
40
- while get_server_state(id) != state
41
- print '..'
42
- sleep 5
43
- end
44
- state
45
- end
46
-
47
- ##
48
- # Finds the public ip for a server
49
-
50
- def get_server_public_ip(server, cached_rules=nil)
51
- return nil unless server
52
-
53
- # find the public ip
54
- nic = get_server_default_nic(server) || {}
55
- if nic['type'] == 'Virtual'
56
- ssh_rule = get_ssh_port_forwarding_rule(server, cached_rules)
57
- ssh_rule ? ssh_rule['ipaddress'] : nil
58
- else
59
- nic['ipaddress']
60
- end
61
- end
62
-
63
- ##
64
- # Returns the fully qualified domain name for a server.
65
-
66
- def get_server_fqdn(server)
67
- return nil unless server
68
-
69
- nic = get_server_default_nic(server) || {}
70
- networks = list_networks(project_id: server['projectid']) || {}
71
-
72
- id = nic['networkid']
73
- network = networks.select { |net|
74
- net['id'] == id
75
- }.first
76
- return nil unless network
77
-
78
- "#{server['name']}.#{network['networkdomain']}"
79
- end
80
-
81
- def get_server_default_nic(server)
82
- server['nic'].each do |nic|
83
- return nic if nic['isdefault']
84
- end
85
- end
86
-
87
- ##
88
- # Lists all the servers in your account.
89
-
90
- def list_servers(options = {})
91
- params = {
92
- 'command' => 'listVirtualMachines',
93
- 'listAll' => true
94
- }
95
- params['projectid'] = options[:project_id] if options[:project_id]
96
-
97
- if options[:zone]
98
- zone = get_zone(options[:zone])
99
- unless zone
100
- puts "Error: Zone #{options[:zone]} not found"
101
- exit 1
102
- end
103
- params['zoneid'] = zone['id']
104
- end
105
-
106
- if options[:account]
107
- if account = list_accounts({name: options[:account]}).first
108
- params['domainid'] = account["domainid"]
109
- params['account'] = options[:account]
110
- end
111
- end
112
-
113
- json = send_request(params)
114
- json['virtualmachine'] || []
115
- end
116
-
117
- ##
118
- # Deploys a new server using the specified parameters.
119
-
120
- def create_server(args = {})
121
- if args[:name]
122
- if get_server(args[:name])
123
- puts "Error: Server '#{args[:name]}' already exists."
124
- exit 1
125
- end
126
- end
127
-
128
- service = get_service_offering(args[:offering])
129
- if !service
130
- puts "Error: Service offering '#{args[:offering]}' is invalid"
131
- exit 1
132
- end
133
-
134
- if args[:template]
135
- template = get_template(args[:template])
136
- if !template
137
- puts "Error: Template '#{args[:template]}' is invalid"
138
- exit 1
139
- end
140
- end
141
-
142
- if args[:disk_offering]
143
- disk_offering = get_disk_offering(args[:disk_offering])
144
- unless disk_offering
145
- msg = "Disk offering '#{args[:disk_offering]}' is invalid"
146
- puts "Error: #{msg}"
147
- exit 1
148
- end
149
- end
150
-
151
- if args[:iso]
152
- iso = get_iso(args[:iso])
153
- unless iso
154
- puts "Error: Iso '#{args[:iso]}' is invalid"
155
- exit 1
156
- end
157
- unless disk_offering
158
- puts "Error: a disk offering is required when using iso"
159
- exit 1
160
- end
161
- end
162
-
163
- if !template && !iso
164
- puts "Error: Iso or Template is required"
165
- exit 1
166
- end
167
-
168
- zone = args[:zone] ? get_zone(args[:zone]) : get_default_zone
169
- if !zone
170
- msg = args[:zone] ? "Zone '#{args[:zone]}' is invalid" : "No default zone found"
171
- puts "Error: #{msg}"
172
- exit 1
173
- end
174
-
175
- if args[:project]
176
- project = get_project(args[:project])
177
- if !project
178
- msg = "Project '#{args[:project]}' is invalid"
179
- puts "Error: #{msg}"
180
- exit 1
181
- end
182
- end
183
-
184
- networks = []
185
- if args[:networks]
186
- args[:networks].each do |name|
187
- network = project ? get_network(name, project['id']) : get_network(name)
188
- if !network
189
- puts "Error: Network '#{name}' not found"
190
- exit 1
191
- end
192
- networks << network
193
- end
194
- end
195
- if networks.empty?
196
- networks << get_default_network
197
- end
198
- if networks.empty?
199
- puts "No default network found"
200
- exit 1
201
- end
202
- network_ids = networks.map { |network|
203
- network['id']
204
- }
205
-
206
- params = {
207
- 'command' => 'deployVirtualMachine',
208
- 'serviceOfferingId' => service['id'],
209
- 'templateId' => template ? template['id'] : iso['id'],
210
- 'zoneId' => zone['id'],
211
- 'networkids' => network_ids.join(',')
212
- }
213
- params['name'] = args[:name] if args[:name]
214
- params['projectid'] = project['id'] if project
215
- params['diskofferingid'] = disk_offering['id'] if disk_offering
216
- params['hypervisor'] = (args[:hypervisor] || 'vmware') if iso
217
- params['keypair'] = args[:keypair] if args[:keypair]
218
- params['size'] = args[:disk_size] if args[:disk_size]
219
- params['group'] = args[:group] if args[:group]
220
- params['displayname'] = args[:displayname] if args[:displayname]
221
-
222
- if args[:account]
223
- account = list_accounts({name: args[:account]}).first
224
- unless account
225
- puts "Error: Account #{args[:account]} not found."
226
- exit 1
227
- end
228
- params['domainid'] = account["domainid"]
229
- params['account'] = args[:account]
230
- end
231
-
232
- args[:sync] ? send_request(params) : send_async_request(params)['virtualmachine']
233
- end
234
-
235
- ##
236
- # Stops the server with the specified name.
237
- #
238
-
239
- def stop_server(name, forced=nil)
240
- server = get_server(name)
241
- if !server || !server['id']
242
- puts "Error: Virtual machine '#{name}' does not exist"
243
- exit 1
244
- end
245
-
246
- params = {
247
- 'command' => 'stopVirtualMachine',
248
- 'id' => server['id']
249
- }
250
- params['forced'] = true if forced
251
-
252
- json = send_async_request(params)
253
- json['virtualmachine']
254
- end
255
-
256
- ##
257
- # Start the server with the specified name.
258
- #
259
-
260
- def start_server(name)
261
- server = get_server(name)
262
- if !server || !server['id']
263
- puts "Error: Virtual machine '#{name}' does not exist"
264
- exit 1
265
- end
266
-
267
- params = {
268
- 'command' => 'startVirtualMachine',
269
- 'id' => server['id']
270
- }
271
-
272
- json = send_async_request(params)
273
- json['virtualmachine']
274
- end
275
-
276
- ##
277
- # Reboot the server with the specified name.
278
- #
279
-
280
- def reboot_server(name)
281
- server = get_server(name)
282
- if !server || !server['id']
283
- puts "Error: Virtual machine '#{name}' does not exist"
284
- exit 1
285
- end
286
-
287
- params = {
288
- 'command' => 'rebootVirtualMachine',
289
- 'id' => server['id']
290
- }
291
-
292
- json = send_async_request(params)
293
- json['virtualmachine']
294
- end
295
-
296
- ##
297
- # Destroy the server with the specified name.
298
- #
299
-
300
- def destroy_server(id, async = true)
301
- params = {
302
- 'command' => 'destroyVirtualMachine',
303
- 'id' => id
304
- }
305
-
306
- async ? send_async_request(params)['virtualmachine'] : send_request(params)
307
- end
308
-
309
- end
310
-
311
- 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