kitchen-cloudstack 0.22.0 → 0.23.0

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
- SHA1:
3
- metadata.gz: 865f50951ffac7b62e92d171f42fff075ad054f1
4
- data.tar.gz: 0035d0cb62d978978cad8b4ed5627eaa37347015
2
+ SHA256:
3
+ metadata.gz: 85e304a3e17949e1178d38b6a4bb8a79efee76cb9af48a0f9eeb6a942c416457
4
+ data.tar.gz: cf4363b3db44132a97cffbda84348cd553610206d3743434e34b6038033c9cc1
5
5
  SHA512:
6
- metadata.gz: 3e0e41ca07d268bba030ffc40d62ecf91cbb71222498569ab0a87b6ce368a9acd3000e66b428e0506136207ae88d320695a7657b73d9279109b339fcc151b453
7
- data.tar.gz: 4faa04395d32d79552ae715416e04cfdf8cbc33cf2283fe85ec282b3d25187f4ce2b6fd5c73b67a278c3fcec4bec54986d3671d69cc93f70f8b9731916445cf5
6
+ metadata.gz: d3100a2b43079e25074c90e61a2bf206a53267be6816ac0c0ddf93014640396a56c178bfdc956584e90e2082703df852f31403ea19a21efaec5a56ad05cc5360
7
+ data.tar.gz: 0d285e444bb04b5878c4d42e97d5d4fa5e12822c8a13c94da2c9f468d0cb224d2a9c4e374470a67a5b8de5dc013566e89362fde13c447b2e355bf2425d2cb2eb
data/README.md CHANGED
@@ -27,6 +27,7 @@ Provide, at a minimum, the required driver options in your `.kitchen.yml` file:
27
27
  keypair_search_directory: [PATH TO DIRECTORY (other than ~, ., and ~/.ssh) WITH KEYPAIR PEM FILE]
28
28
  cloudstack_project_id: [PROJECT_ID] # To deploy VMs into project.
29
29
  cloudstack_vm_public_ip: [PUBLIC_IP] # In case you use advanced networking and do static NAT manually.
30
+ associate_public_ip: [TRUE/FALSE] # If you want kitchen to automatically associate a public IP, default false.
30
31
  cloudstack_userdata: "#cloud-config\npackages:\n - htop\n" # double quote required.
31
32
 
32
33
  Then to specify different OS templates,
@@ -146,7 +146,14 @@ module Kitchen
146
146
  info("Keypair specified but not found. Using password if enabled.")
147
147
  end
148
148
 
149
- state[:hostname] = config[:cloudstack_vm_public_ip] || server_info.fetch('nic').first.fetch('ipaddress')
149
+ if config[:associate_public_ip]
150
+ info("Associating public ip...")
151
+ state[:hostname] = associate_public_ip(state, server_info)
152
+ info("Creating port forward...")
153
+ create_port_forward(state, server_info['id'])
154
+ else
155
+ state[:hostname] = default_public_ip(server_info) unless config[:associate_public_ip]
156
+ end
150
157
 
151
158
  if keypair
152
159
  debug("Using keypair: #{keypair}")
@@ -191,6 +198,10 @@ module Kitchen
191
198
 
192
199
  def destroy(state)
193
200
  return unless state[:server_id]
201
+ if config[:associate_public_ip]
202
+ delete_port_forward(state)
203
+ release_public_ip(state)
204
+ end
194
205
  debug("Destroying #{state[:server_id]}")
195
206
  server = compute.servers.get(state[:server_id])
196
207
  expunge =
@@ -302,6 +313,93 @@ module Kitchen
302
313
  Base64.encode64(user_data)
303
314
  end
304
315
  end
316
+
317
+ def associate_public_ip(state, server_info)
318
+ options = {
319
+ 'zoneid' => config[:cloudstack_zone_id],
320
+ 'vpcid' => get_vpc_id
321
+ }
322
+ res = compute.associate_ip_address(options)
323
+ job_status = compute.query_async_job_result(res['associateipaddressresponse']['jobid'])
324
+ if job_status['queryasyncjobresultresponse'].fetch('jobstatus').to_i == 1
325
+ save_ipaddress_id(state, job_status)
326
+ get_public_ip(res['associateipaddressresponse']['id'])
327
+ else
328
+ error(job_status['queryasyncjobresultresponse'].fetch('jobresult'))
329
+ end
330
+ end
331
+
332
+ def create_port_forward(state, virtualmachineid)
333
+ options = {
334
+ 'ipaddressid' => state[:ipaddressid],
335
+ 'privateport' => 22,
336
+ 'protocol' => "TCP",
337
+ 'publicport' => 22,
338
+ 'virtualmachineid' => virtualmachineid,
339
+ 'networkid' => config[:cloudstack_network_id],
340
+ 'openfirewall' => false
341
+ }
342
+ res = compute.create_port_forwarding_rule(options)
343
+ job_status = compute.query_async_job_result(res['createportforwardingruleresponse']['jobid'])
344
+ unless job_status['queryasyncjobresultresponse'].fetch('jobstatus').to_i == 0
345
+ error("Error creating port forwarding rules")
346
+ end
347
+ save_forwarding_port_rule_id(state, res['createportforwardingruleresponse']['id'])
348
+ end
349
+
350
+ def release_public_ip(state)
351
+ info("Disassociating public ip...")
352
+ begin
353
+ res = compute.disassociate_ip_address(state[:ipaddressid])
354
+ rescue Fog::Compute::Cloudstack::BadRequest => e
355
+ error(e) unless e.to_s.match?(/does not exist/)
356
+ else
357
+ job_status = compute.query_async_job_result(res['disassociateipaddressresponse']['jobid'])
358
+ unless job_status['queryasyncjobresultresponse'].fetch('jobstatus').to_i == 0
359
+ error("Error disassociating public ip")
360
+ end
361
+ end
362
+ end
363
+
364
+ def delete_port_forward(state)
365
+ info("Deleting port forwarding rules...")
366
+ begin
367
+ res = compute.delete_port_forwarding_rule(state[:forwardingruleid])
368
+ rescue Fog::Compute::Cloudstack::BadRequest => e
369
+ error(e) unless e.to_s.match?(/does not exist/)
370
+ else
371
+ job_status = compute.query_async_job_result(res['deleteportforwardingruleresponse']['jobid'])
372
+ unless job_status['queryasyncjobresultresponse'].fetch('jobstatus').to_i == 0
373
+ error("Error deleting port forwarding rules")
374
+ end
375
+ end
376
+ end
377
+
378
+ def get_vpc_id
379
+ compute.list_networks['listnetworksresponse']['network']
380
+ .select{|e| e['id'] == config[:cloudstack_network_id]}.first['vpcid']
381
+ end
382
+
383
+ def get_public_ip(public_ip_uuid)
384
+ compute.list_public_ip_addresses['listpublicipaddressesresponse']['publicipaddress']
385
+ .select{|e| e['id'] == public_ip_uuid}
386
+ .first['ipaddress']
387
+ end
388
+
389
+ def save_ipaddress_id(state, job_status)
390
+ state[:ipaddressid] = job_status['queryasyncjobresultresponse']
391
+ .fetch('jobresult')
392
+ .fetch('ipaddress')
393
+ .fetch('id')
394
+ end
395
+
396
+ def save_forwarding_port_rule_id(state, uuid)
397
+ state[:forwardingruleid] = uuid
398
+ end
399
+
400
+ def default_public_ip(server_info)
401
+ config[:cloudstack_vm_public_ip] || server_info.fetch('nic').first.fetch('ipaddress')
402
+ end
305
403
  end
306
404
  end
307
405
  end
@@ -21,6 +21,6 @@ module Kitchen
21
21
  module Driver
22
22
 
23
23
  # Version string for Cloudstack Kitchen driver
24
- CLOUDSTACK_VERSION = "0.22.0"
24
+ CLOUDSTACK_VERSION = "0.23.0"
25
25
  end
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-cloudstack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Moody
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-11 00:00:00.000000000 Z
11
+ date: 2018-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  version: '0'
174
174
  requirements: []
175
175
  rubyforge_project:
176
- rubygems_version: 2.5.1
176
+ rubygems_version: 2.7.6
177
177
  signing_key:
178
178
  specification_version: 4
179
179
  summary: Provides an interface for Test Kitchen to be able to run jobs against an