cloudstack_client 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffd63beb8ab67704569e056c8179fa7038ae5794
4
- data.tar.gz: 26304d025eb85cce68304fec2cb4aa129fd89d94
3
+ metadata.gz: 20779611c9bf0415cd3b21dd3c66d26f3420f81e
4
+ data.tar.gz: 0c8028ee8e322b7e091acaaf4ed8dbe32e4b6bb4
5
5
  SHA512:
6
- metadata.gz: 629ca9e1c0e1625020da16904cbef4fd922ac2e2acd08aff9daa9373e994524e156ed6b0e6ca1001db4cbb0771fd93b367daa00159c283ebe3b4dce18044025b
7
- data.tar.gz: ec077e92e135282048b52432c865346bd0d4c97b38342d4c914602488d217db11c7f5ea6529beb993ef8f51dd2a699e417b202cf81dffb440d2c7035332f2598
6
+ metadata.gz: fa661e5349b428162a9553516e940328dd19f1006e97c2dabd87e1689a422840833680e4ec21a745819ce9957e251d5723c054ecbe6e37750aca40b1264286fa
7
+ data.tar.gz: a76e3df97e98cd7042a55572013fa2380bc329f237266404a9095f6232eb3c7f3c39b7c26d15faac8a4d0a2920d1658550f233292635449480a8de42d7e01d11
@@ -53,11 +53,12 @@ module CloudstackClient
53
53
  ##
54
54
  # Acquires and associates a public IP to an account.
55
55
 
56
- def associate_ip_address(network_id)
56
+ def associate_ip_address(network_id, project_id = nil)
57
57
  params = {
58
58
  'command' => 'associateIpAddress',
59
59
  'networkid' => network_id
60
60
  }
61
+ params['projectid'] = project_id if project_id
61
62
 
62
63
  json = send_async_request(params)
63
64
  json['ipaddress']
@@ -159,18 +159,74 @@ module CloudstackClient
159
159
  # Deploys a new server using the specified parameters.
160
160
 
161
161
  def create_server(args = {})
162
+ params = {'command' => 'deployVirtualMachine'}
163
+ params['keypair'] = args[:keypair] if args[:keypair]
164
+ params['size'] = args[:disk_size] if args[:disk_size]
165
+ params['group'] = args[:group] if args[:group]
166
+ params['displayname'] = args[:displayname] if args[:displayname]
167
+
168
+ if args[:account]
169
+ account = list_accounts({name: args[:account]}).first
170
+ unless account
171
+ puts "Error: Account #{args[:account]} not found."
172
+ exit 1
173
+ end
174
+ params['domainid'] = account["domainid"]
175
+ params['account'] = args[:account]
176
+ end
177
+
178
+ if args[:project]
179
+ project = get_project(args[:project])
180
+ if !project
181
+ msg = "Project '#{args[:project]}' is invalid"
182
+ puts "Error: #{msg}"
183
+ exit 1
184
+ end
185
+ params['projectid'] = project['id']
186
+ elsif args[:project_id]
187
+ params['projectid'] = args[:project_id]
188
+ end
189
+ params['name'] = args[:name] if args[:name]
190
+
162
191
  if args[:name]
163
- if get_server(args[:name])
192
+ server = params['projectid'] ?
193
+ get_server(args[:name], project_id: params['projectid']) :
194
+ get_server(args[:name])
195
+ if server
164
196
  puts "Error: Server '#{args[:name]}' already exists."
165
197
  exit 1
166
198
  end
167
199
  end
168
200
 
201
+ networks = []
202
+ if args[:networks]
203
+ args[:networks].each do |name|
204
+ network = defined?(project) ? get_network(name, project['id']) : get_network(name)
205
+ if !network
206
+ puts "Error: Network '#{name}' not found"
207
+ exit 1
208
+ end
209
+ networks << network
210
+ end
211
+ end
212
+ if networks.empty?
213
+ networks << get_default_network
214
+ end
215
+ if networks.empty?
216
+ puts "No default network found"
217
+ exit 1
218
+ end
219
+ network_ids = networks.map { |network|
220
+ network['id']
221
+ }
222
+ params['networkids'] = network_ids.join(',')
223
+
169
224
  service = get_service_offering(args[:offering])
170
225
  if !service
171
226
  puts "Error: Service offering '#{args[:offering]}' is invalid"
172
227
  exit 1
173
228
  end
229
+ params['serviceOfferingId'] = service['id']
174
230
 
175
231
  if args[:template]
176
232
  template = get_template(args[:template])
@@ -187,6 +243,7 @@ module CloudstackClient
187
243
  puts "Error: #{msg}"
188
244
  exit 1
189
245
  end
246
+ params['diskofferingid'] = disk_offering['id']
190
247
  end
191
248
 
192
249
  if args[:iso]
@@ -199,12 +256,14 @@ module CloudstackClient
199
256
  puts "Error: a disk offering is required when using iso"
200
257
  exit 1
201
258
  end
259
+ params['hypervisor'] = (args[:hypervisor] || 'vmware')
202
260
  end
203
261
 
204
262
  if !template && !iso
205
263
  puts "Error: Iso or Template is required"
206
264
  exit 1
207
265
  end
266
+ params['templateId'] = template ? template['id'] : iso['id']
208
267
 
209
268
  zone = args[:zone] ? get_zone(args[:zone]) : get_default_zone
210
269
  if !zone
@@ -212,65 +271,7 @@ module CloudstackClient
212
271
  puts "Error: #{msg}"
213
272
  exit 1
214
273
  end
215
-
216
- networks = []
217
- if args[:networks]
218
- args[:networks].each do |name|
219
- network = project ? get_network(name, project['id']) : get_network(name)
220
- if !network
221
- puts "Error: Network '#{name}' not found"
222
- exit 1
223
- end
224
- networks << network
225
- end
226
- end
227
- if networks.empty?
228
- networks << get_default_network
229
- end
230
- if networks.empty?
231
- puts "No default network found"
232
- exit 1
233
- end
234
- network_ids = networks.map { |network|
235
- network['id']
236
- }
237
-
238
- params = {
239
- 'command' => 'deployVirtualMachine',
240
- 'serviceOfferingId' => service['id'],
241
- 'templateId' => template ? template['id'] : iso['id'],
242
- 'zoneId' => zone['id'],
243
- 'networkids' => network_ids.join(',')
244
- }
245
- params['name'] = args[:name] if args[:name]
246
- params['diskofferingid'] = disk_offering['id'] if disk_offering
247
- params['hypervisor'] = (args[:hypervisor] || 'vmware') if iso
248
- params['keypair'] = args[:keypair] if args[:keypair]
249
- params['size'] = args[:disk_size] if args[:disk_size]
250
- params['group'] = args[:group] if args[:group]
251
- params['displayname'] = args[:displayname] if args[:displayname]
252
-
253
- if args[:account]
254
- account = list_accounts({name: args[:account]}).first
255
- unless account
256
- puts "Error: Account #{args[:account]} not found."
257
- exit 1
258
- end
259
- params['domainid'] = account["domainid"]
260
- params['account'] = args[:account]
261
- end
262
-
263
- if args[:project]
264
- project = get_project(args[:project])
265
- if !project
266
- msg = "Project '#{args[:project]}' is invalid"
267
- puts "Error: #{msg}"
268
- exit 1
269
- end
270
- params['projectid'] = project['id']
271
- elsif args[:project_id]
272
- params['projectid'] = args[:project_id]
273
- end
274
+ params['zoneid'] = zone['id']
274
275
 
275
276
  args[:sync] ? send_request(params) : send_async_request(params)['virtualmachine']
276
277
  end
@@ -1,3 +1,3 @@
1
1
  module CloudstackClient
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudstack_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nik Wolfgramm