vagrant-cloudstack 1.3.0 → 1.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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +18 -19
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +19 -19
  5. data/CHANGELOG.md +179 -171
  6. data/Docker/.dockerignore +2 -0
  7. data/Docker/Dockerfile +51 -0
  8. data/Docker/Dockerfile.chefdk_0_17 +49 -0
  9. data/Docker/Dockerfile.latest_dependencies +49 -0
  10. data/Docker/README.md +67 -0
  11. data/Docker/vac.ps1 +29 -0
  12. data/Docker/vac.sh +30 -0
  13. data/Gemfile +20 -20
  14. data/LICENSE +8 -8
  15. data/README.md +416 -416
  16. data/Rakefile +106 -99
  17. data/bootstrap.key +27 -0
  18. data/build_rpm.sh +7 -7
  19. data/functional-tests/basic/Vagrantfile.basic_networking +45 -45
  20. data/functional-tests/basic/basic_spec.rb +21 -21
  21. data/functional-tests/networking/Vagrantfile.advanced_networking +119 -102
  22. data/functional-tests/networking/networking_spec.rb +14 -0
  23. data/functional-tests/rsync/Vagrantfile.advanced_networking +39 -56
  24. data/functional-tests/rsync/rsync_spec.rb +9 -9
  25. data/functional-tests/vmlifecycle/Vagrantfile.advanced_networking +66 -82
  26. data/functional-tests/vmlifecycle/vmlifecycle_spec.rb +13 -13
  27. data/lib/vagrant-cloudstack/action/connect_cloudstack.rb +47 -47
  28. data/lib/vagrant-cloudstack/action/is_created.rb +18 -18
  29. data/lib/vagrant-cloudstack/action/is_stopped.rb +18 -18
  30. data/lib/vagrant-cloudstack/action/message_already_created.rb +16 -16
  31. data/lib/vagrant-cloudstack/action/message_not_created.rb +16 -16
  32. data/lib/vagrant-cloudstack/action/message_will_not_destroy.rb +16 -16
  33. data/lib/vagrant-cloudstack/action/read_rdp_info.rb +76 -76
  34. data/lib/vagrant-cloudstack/action/read_ssh_info.rb +104 -87
  35. data/lib/vagrant-cloudstack/action/read_state.rb +38 -38
  36. data/lib/vagrant-cloudstack/action/read_winrm_info.rb +103 -103
  37. data/lib/vagrant-cloudstack/action/run_instance.rb +798 -703
  38. data/lib/vagrant-cloudstack/action/start_instance.rb +81 -81
  39. data/lib/vagrant-cloudstack/action/stop_instance.rb +28 -28
  40. data/lib/vagrant-cloudstack/action/terminate_instance.rb +269 -224
  41. data/lib/vagrant-cloudstack/action/timed_provision.rb +21 -21
  42. data/lib/vagrant-cloudstack/action/wait_for_state.rb +41 -41
  43. data/lib/vagrant-cloudstack/action/warn_networks.rb +19 -19
  44. data/lib/vagrant-cloudstack/action.rb +210 -210
  45. data/lib/vagrant-cloudstack/capabilities/rdp.rb +12 -12
  46. data/lib/vagrant-cloudstack/capabilities/winrm.rb +12 -12
  47. data/lib/vagrant-cloudstack/config.rb +566 -548
  48. data/lib/vagrant-cloudstack/errors.rb +27 -27
  49. data/lib/vagrant-cloudstack/exceptions/exceptions.rb +10 -10
  50. data/lib/vagrant-cloudstack/model/cloudstack_resource.rb +51 -33
  51. data/lib/vagrant-cloudstack/plugin.rb +82 -82
  52. data/lib/vagrant-cloudstack/provider.rb +58 -58
  53. data/lib/vagrant-cloudstack/service/cloudstack_resource_service.rb +64 -58
  54. data/lib/vagrant-cloudstack/util/timer.rb +17 -17
  55. data/lib/vagrant-cloudstack/version.rb +5 -5
  56. data/lib/vagrant-cloudstack.rb +17 -17
  57. data/locales/en.yml +131 -123
  58. data/spec/spec_helper.rb +8 -6
  59. data/spec/vagrant-cloudstack/action/read_ssh_info_spec.rb +80 -0
  60. data/spec/vagrant-cloudstack/config_spec.rb +355 -355
  61. data/spec/vagrant-cloudstack/model/cloudstack_resource_spec.rb +95 -73
  62. data/spec/vagrant-cloudstack/service/cloudstack_resource_service_spec.rb +43 -43
  63. data/spec/vagrant-cloudstack/support/be_a_resource.rb +6 -0
  64. data/vagrant-cloudstack.gemspec +59 -59
  65. data/vagrant-cloudstack.spec +42 -42
  66. metadata +14 -7
  67. data/dummy.box +0 -0
  68. data/example_box/README.md +0 -13
  69. data/example_box/metadata.json +0 -3
  70. data/functional-tests/networking/rsync_spec.rb +0 -12
@@ -1,81 +1,81 @@
1
- require "log4r"
2
- require "vagrant/util/retryable"
3
- require "vagrant-cloudstack/util/timer"
4
-
5
- module VagrantPlugins
6
- module Cloudstack
7
- module Action
8
- # This starts a stopped instance.
9
- class StartInstance
10
- include Vagrant::Util::Retryable
11
-
12
- def initialize(app, env)
13
- @app = app
14
- @logger = Log4r::Logger.new("vagrant_cloudstack::action::start_instance")
15
- end
16
-
17
- def call(env)
18
- # Initialize metrics if they haven't been
19
- env[:metrics] ||= {}
20
-
21
- server = env[:cloudstack_compute].servers.get(env[:machine].id)
22
-
23
- env[:ui].info(I18n.t("vagrant_cloudstack.starting"))
24
-
25
- begin
26
- server.start
27
-
28
- domain = env[:machine].provider_config.domain_id
29
- domain_config = env[:machine].provider_config.get_domain_config(domain)
30
-
31
- # Wait for the instance to be ready first
32
- env[:metrics]["instance_ready_time"] = Util::Timer.time do
33
- tries = domain_config.instance_ready_timeout / 2
34
-
35
- env[:ui].info(I18n.t("vagrant_cloudstack.waiting_for_ready"))
36
- begin
37
- retryable(:on => Fog::Errors::TimeoutError, :tries => tries) do
38
- # If we're interrupted don't worry about waiting
39
- next if env[:interrupted]
40
-
41
- # Wait for the server to be ready
42
- server.wait_for(2) { ready? }
43
- end
44
- rescue Fog::Errors::TimeoutError
45
- # Notify the user
46
- raise Errors::InstanceReadyTimeout,
47
- :timeout => domain_config.instance_ready_timeout
48
- end
49
- end
50
- rescue Fog::Compute::Cloudstack::Error => e
51
- raise Errors::FogError, :message => e.message
52
- end
53
-
54
- @logger.info("Time to instance ready: #{env[:metrics]["instance_ready_time"]}")
55
-
56
- if !env[:interrupted]
57
- env[:metrics]["instance_ssh_time"] = Util::Timer.time do
58
- # Wait for communicator to be ready.
59
- communicator = env[:machine].config.vm.communicator
60
- communicator = "SSH" if communicator.nil?
61
- env[:ui].info(I18n.t("vagrant_cloudstack.waiting_for_communicator", :communicator => communicator.to_s.upcase))
62
- while true
63
- # If we're interrupted then just back out
64
- break if env[:interrupted]
65
- break if env[:machine].communicate.ready?
66
- sleep 2
67
- end
68
- end
69
-
70
- @logger.info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}")
71
-
72
- # Ready and booted!
73
- env[:ui].info(I18n.t("vagrant_cloudstack.ready"))
74
- end
75
-
76
- @app.call(env)
77
- end
78
- end
79
- end
80
- end
81
- end
1
+ require "log4r"
2
+ require "vagrant/util/retryable"
3
+ require "vagrant-cloudstack/util/timer"
4
+
5
+ module VagrantPlugins
6
+ module Cloudstack
7
+ module Action
8
+ # This starts a stopped instance.
9
+ class StartInstance
10
+ include Vagrant::Util::Retryable
11
+
12
+ def initialize(app, env)
13
+ @app = app
14
+ @logger = Log4r::Logger.new("vagrant_cloudstack::action::start_instance")
15
+ end
16
+
17
+ def call(env)
18
+ # Initialize metrics if they haven't been
19
+ env[:metrics] ||= {}
20
+
21
+ server = env[:cloudstack_compute].servers.get(env[:machine].id)
22
+
23
+ env[:ui].info(I18n.t("vagrant_cloudstack.starting"))
24
+
25
+ begin
26
+ server.start
27
+
28
+ domain = env[:machine].provider_config.domain_id
29
+ domain_config = env[:machine].provider_config.get_domain_config(domain)
30
+
31
+ # Wait for the instance to be ready first
32
+ env[:metrics]["instance_ready_time"] = Util::Timer.time do
33
+ tries = domain_config.instance_ready_timeout / 2
34
+
35
+ env[:ui].info(I18n.t("vagrant_cloudstack.waiting_for_ready"))
36
+ begin
37
+ retryable(:on => Fog::Errors::TimeoutError, :tries => tries) do
38
+ # If we're interrupted don't worry about waiting
39
+ next if env[:interrupted]
40
+
41
+ # Wait for the server to be ready
42
+ server.wait_for(2) { ready? }
43
+ end
44
+ rescue Fog::Errors::TimeoutError
45
+ # Notify the user
46
+ raise Errors::InstanceReadyTimeout,
47
+ :timeout => domain_config.instance_ready_timeout
48
+ end
49
+ end
50
+ rescue Fog::Compute::Cloudstack::Error => e
51
+ raise Errors::FogError, :message => e.message
52
+ end
53
+
54
+ @logger.info("Time to instance ready: #{env[:metrics]["instance_ready_time"]}")
55
+
56
+ if !env[:interrupted]
57
+ env[:metrics]["instance_ssh_time"] = Util::Timer.time do
58
+ # Wait for communicator to be ready.
59
+ communicator = env[:machine].config.vm.communicator
60
+ communicator = "SSH" if communicator.nil?
61
+ env[:ui].info(I18n.t("vagrant_cloudstack.waiting_for_communicator", :communicator => communicator.to_s.upcase))
62
+ while true
63
+ # If we're interrupted then just back out
64
+ break if env[:interrupted]
65
+ break if env[:machine].communicate.ready?
66
+ sleep 2
67
+ end
68
+ end
69
+
70
+ @logger.info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}")
71
+
72
+ # Ready and booted!
73
+ env[:ui].info(I18n.t("vagrant_cloudstack.ready"))
74
+ end
75
+
76
+ @app.call(env)
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -1,28 +1,28 @@
1
- require "log4r"
2
-
3
- module VagrantPlugins
4
- module Cloudstack
5
- module Action
6
- # This stops the running instance.
7
- class StopInstance
8
- def initialize(app, env)
9
- @app = app
10
- @logger = Log4r::Logger.new("vagrant_cloudstack::action::stop_instance")
11
- end
12
-
13
- def call(env)
14
- server = env[:cloudstack_compute].servers.get(env[:machine].id)
15
-
16
- if env[:machine].state.id == :stopped
17
- env[:ui].info(I18n.t("vagrant_cloudstack.already_status", :status => env[:machine].state.id))
18
- else
19
- env[:ui].info(I18n.t("vagrant_cloudstack.stopping"))
20
- server.stop({'force' => !!env[:force_halt]})
21
- end
22
-
23
- @app.call(env)
24
- end
25
- end
26
- end
27
- end
28
- end
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module Cloudstack
5
+ module Action
6
+ # This stops the running instance.
7
+ class StopInstance
8
+ def initialize(app, env)
9
+ @app = app
10
+ @logger = Log4r::Logger.new("vagrant_cloudstack::action::stop_instance")
11
+ end
12
+
13
+ def call(env)
14
+ server = env[:cloudstack_compute].servers.get(env[:machine].id)
15
+
16
+ if env[:machine].state.id == :stopped
17
+ env[:ui].info(I18n.t("vagrant_cloudstack.already_status", :status => env[:machine].state.id))
18
+ else
19
+ env[:ui].info(I18n.t("vagrant_cloudstack.stopping"))
20
+ server.stop({'force' => !!env[:force_halt]})
21
+ end
22
+
23
+ @app.call(env)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,224 +1,269 @@
1
- require 'log4r'
2
-
3
- module VagrantPlugins
4
- module Cloudstack
5
- module Action
6
- # This terminates the running instance.
7
- class TerminateInstance
8
- def initialize(app, env)
9
- @app = app
10
- @logger = Log4r::Logger.new('vagrant_cloudstack::action::terminate_instance')
11
- end
12
-
13
- def call(env)
14
- # Delete the Firewall rule
15
- remove_firewall_rules(env)
16
-
17
- # Disable Static NAT
18
- remove_static_nat(env)
19
-
20
- # Delete the Port forwarding rule
21
- remove_portforwarding(env)
22
-
23
- # Destroy the server and remove the tracking ID
24
- if env[:machine].id.nil?
25
- env[:ui].info(I18n.t('vagrant_cloudstack.no_instance_found'))
26
- return
27
- else
28
- server = env[:cloudstack_compute].servers.get(env[:machine].id)
29
-
30
- env[:ui].info(I18n.t('vagrant_cloudstack.terminating'))
31
-
32
- domain = env[:machine].provider_config.domain_id
33
- domain_config = env[:machine].provider_config.get_domain_config(domain)
34
- expunge_on_destroy = domain_config.expunge_on_destroy
35
-
36
- options = {}
37
- options['expunge'] = expunge_on_destroy
38
-
39
- job = server.destroy(options)
40
- while true
41
- response = env[:cloudstack_compute].query_async_job_result({:jobid => job.id})
42
- if response['queryasyncjobresultresponse']['jobstatus'] != 0
43
- break
44
- else
45
- env[:ui].info('Waiting for instance to be deleted')
46
- sleep 2
47
- end
48
- end
49
- end
50
-
51
- # Delete the vmcredentials file
52
- remove_stored_credentials(env)
53
-
54
- # Remove keyname from cloudstack
55
- remove_generated_ssh_key(env)
56
-
57
- remove_security_groups(env)
58
-
59
- env[:machine].id = nil
60
-
61
- @app.call(env)
62
- end
63
-
64
- def remove_security_groups(env)
65
- security_groups_file = env[:machine].data_dir.join('security_groups')
66
- if security_groups_file.file?
67
- File.read(security_groups_file).each_line do |line|
68
- security_group_id = line.strip
69
- begin
70
- security_group = env[:cloudstack_compute].security_groups.get(security_group_id)
71
-
72
- security_group.ingress_rules.each do |ir|
73
- env[:cloudstack_compute].revoke_security_group_ingress({:id => ir['ruleid']})
74
- end
75
- env[:ui].info('Deleted ingress rules')
76
-
77
- security_group.egress_rules.each do |er|
78
- env[:cloudstack_compute].revoke_security_group_egress({:id => er['ruleid']})
79
- end
80
- env[:ui].info('Deleted egress rules')
81
-
82
- rescue Fog::Compute::Cloudstack::Error => e
83
- raise Errors::FogError, :message => e.message
84
- end
85
-
86
- begin
87
- env[:cloudstack_compute].delete_security_group({:id => security_group_id})
88
- rescue Fog::Compute::Cloudstack::Error => e
89
- env[:ui].warn("Couldn't delete group right now.")
90
- env[:ui].warn('Waiting 30 seconds to retry')
91
- sleep 30
92
- retry
93
- end
94
- end
95
- security_groups_file.delete
96
- end
97
- end
98
-
99
- def remove_generated_ssh_key(env)
100
- sshkeyname_file = env[:machine].data_dir.join('sshkeyname')
101
- if sshkeyname_file.file?
102
- env[:ui].info(I18n.t('vagrant_cloudstack.ssh_key_pair_removing'))
103
- sshkeyname = ''
104
- File.read(sshkeyname_file).each_line do |line|
105
- sshkeyname = line.strip
106
- end
107
-
108
- begin
109
- response = env[:cloudstack_compute].delete_ssh_key_pair(name: sshkeyname)
110
- env[:ui].warn(I18n.t('vagrant_cloudstack.ssh_key_pair_no_success_removing', name: sshkeyname)) unless response['deletesshkeypairresponse']['success'] == 'true'
111
- rescue Fog::Compute::Cloudstack::Error => e
112
- env[:ui].warn(I18n.t('vagrant_cloudstack.errors.fog_error', :message => e.message))
113
- end
114
- sshkeyname_file.delete
115
- end
116
- end
117
-
118
- def remove_stored_credentials(env)
119
- vmcredentials_file = env[:machine].data_dir.join('vmcredentials')
120
- vmcredentials_file.delete if vmcredentials_file.file?
121
- end
122
-
123
- def remove_portforwarding(env)
124
- env[:ui].info(I18n.t('vagrant_cloudstack.deleting_port_forwarding_rule'))
125
- port_forwarding_file = env[:machine].data_dir.join('port_forwarding')
126
- if port_forwarding_file.file?
127
- File.read(port_forwarding_file).each_line do |line|
128
- rule_id = line.strip
129
- begin
130
- resp = env[:cloudstack_compute].delete_port_forwarding_rule({:id => rule_id})
131
- job_id = resp['deleteportforwardingruleresponse']['jobid']
132
- while true
133
- response = env[:cloudstack_compute].query_async_job_result({:jobid => job_id})
134
- if response['queryasyncjobresultresponse']['jobstatus'] != 0
135
- break
136
- else
137
- sleep 2
138
- end
139
- end
140
- rescue Fog::Compute::Cloudstack::Error => e
141
- if e.message =~ /Unable to execute API command deleteportforwardingrule.*entity does not exist/
142
- env[:ui].warn(" -- Failed to delete portforwarding rule: #{e.message}")
143
- else
144
- raise Errors::FogError, :message => e.message
145
- end
146
-
147
- end
148
- end
149
- port_forwarding_file.delete
150
- end
151
-
152
- # Delete the Communicator Port forwording public port file
153
- # Delete the RDP Port forwording public port file
154
- %w(pf_public_port pf_public_rdp_port).each do |pf_filename|
155
- pf_file = env[:machine].data_dir.join(pf_filename)
156
- pf_file.delete if pf_file.file?
157
- end
158
- end
159
-
160
- def remove_static_nat(env)
161
- env[:ui].info(I18n.t('vagrant_cloudstack.disabling_static_nat'))
162
- static_nat_file = env[:machine].data_dir.join('static_nat')
163
- if static_nat_file.file?
164
- File.read(static_nat_file).each_line do |line|
165
- ip_address_id = line.strip
166
- begin
167
- options = {
168
- :command => 'disableStaticNat',
169
- :ipaddressid => ip_address_id
170
- }
171
- resp = env[:cloudstack_compute].request(options)
172
- job_id = resp['disablestaticnatresponse']['jobid']
173
- while true
174
- response = env[:cloudstack_compute].query_async_job_result({:jobid => job_id})
175
- if response['queryasyncjobresultresponse']['jobstatus'] != 0
176
- break
177
- else
178
- sleep 2
179
- end
180
- end
181
- rescue Fog::Compute::Cloudstack::Error => e
182
- raise Errors::FogError, :message => e.message
183
- end
184
- end
185
- static_nat_file.delete
186
- end
187
- end
188
-
189
- def remove_firewall_rules(env)
190
- env[:ui].info(I18n.t('vagrant_cloudstack.deleting_firewall_rule'))
191
- firewall_file = env[:machine].data_dir.join('firewall')
192
- if firewall_file.file?
193
- File.read(firewall_file).each_line do |line|
194
- rule_id = line.strip
195
- begin
196
- options = {
197
- :command => 'deleteFirewallRule',
198
- :id => rule_id
199
- }
200
- resp = env[:cloudstack_compute].request(options)
201
- job_id = resp['deletefirewallruleresponse']['jobid']
202
- while true
203
- response = env[:cloudstack_compute].query_async_job_result({:jobid => job_id})
204
- if response['queryasyncjobresultresponse']['jobstatus'] != 0
205
- break
206
- else
207
- sleep 2
208
- end
209
- end
210
- rescue Fog::Compute::Cloudstack::Error => e
211
- if e.message =~ /Unable to execute API command deletefirewallrule.*entity does not exist/
212
- env[:ui].warn(" -- Failed to delete firewall rule: #{e.message}")
213
- else
214
- raise Errors::FogError, :message => e.message
215
- end
216
- end
217
- end
218
- firewall_file.delete
219
- end
220
- end
221
- end
222
- end
223
- end
224
- end
1
+ require 'log4r'
2
+
3
+ module VagrantPlugins
4
+ module Cloudstack
5
+ module Action
6
+ # This terminates the running instance.
7
+ class TerminateInstance
8
+ def initialize(app, env)
9
+ @app = app
10
+ @logger = Log4r::Logger.new('vagrant_cloudstack::action::terminate_instance')
11
+ end
12
+
13
+ def call(env)
14
+ # Delete the Firewall rule
15
+ remove_firewall_rules(env)
16
+
17
+ # Disable Static NAT
18
+ remove_static_nat(env)
19
+
20
+ # Delete the Port forwarding rule
21
+ remove_portforwarding(env)
22
+
23
+ # Destroy the server and remove the tracking ID
24
+ if env[:machine].id.nil?
25
+ env[:ui].info(I18n.t('vagrant_cloudstack.no_instance_found'))
26
+ return
27
+ else
28
+ server = env[:cloudstack_compute].servers.get(env[:machine].id)
29
+
30
+ env[:ui].info(I18n.t('vagrant_cloudstack.terminating'))
31
+
32
+ domain = env[:machine].provider_config.domain_id
33
+ domain_config = env[:machine].provider_config.get_domain_config(domain)
34
+ expunge_on_destroy = domain_config.expunge_on_destroy
35
+
36
+ options = {}
37
+ options['expunge'] = expunge_on_destroy
38
+
39
+ job = server.destroy(options)
40
+ while true
41
+ response = env[:cloudstack_compute].query_async_job_result({:jobid => job.id})
42
+ if response['queryasyncjobresultresponse']['jobstatus'] != 0
43
+ break
44
+ else
45
+ env[:ui].info('Waiting for instance to be deleted')
46
+ sleep 2
47
+ end
48
+ end
49
+ end
50
+
51
+ remove_volumes(env)
52
+
53
+ # Delete the vmcredentials file
54
+ remove_stored_credentials(env)
55
+
56
+ # Remove keyname from cloudstack
57
+ remove_generated_ssh_key(env)
58
+
59
+ remove_security_groups(env)
60
+
61
+ env[:machine].id = nil
62
+
63
+ env[:ui].info(I18n.t('vagrant_cloudstack.terminateinstance_done'))
64
+ @app.call(env)
65
+ end
66
+
67
+ def remove_volumes(env)
68
+ volumes_file = env[:machine].data_dir.join('volumes')
69
+ if volumes_file.file?
70
+ env[:ui].info(I18n.t('vagrant_cloudstack.deleting_volumes'))
71
+ File.read(volumes_file).each_line do |line|
72
+ volume_id = line.strip
73
+ begin
74
+ resp = env[:cloudstack_compute].detach_volume({:id => volume_id})
75
+ job_id = resp['detachvolumeresponse']['jobid']
76
+ while true
77
+ response = env[:cloudstack_compute].query_async_job_result({:jobid => job_id})
78
+ if response['queryasyncjobresultresponse']['jobstatus'] != 0
79
+ break
80
+ else
81
+ sleep 2
82
+ end
83
+ end
84
+ rescue Fog::Compute::Cloudstack::Error => e
85
+ if e.message =~ /Unable to execute API command detachvolume.*entity does not exist/
86
+ env[:ui].warn(I18n.t('vagrant_cloudstack.detach_volume_failed', message: e.message))
87
+ else
88
+ raise Errors::FogError, :message => e.message
89
+ end
90
+ end
91
+ resp = env[:cloudstack_compute].delete_volume({:id => volume_id})
92
+ env[:ui].warn(I18n.t('vagrant_cloudstack.detach_volume_failed', volume_id: volume_id)) unless resp['deletevolumeresponse']['success'] == 'true'
93
+ end
94
+ volumes_file.delete
95
+ end
96
+ end
97
+
98
+ def remove_security_groups(env)
99
+ security_groups_file = env[:machine].data_dir.join('security_groups')
100
+ if security_groups_file.file?
101
+ File.read(security_groups_file).each_line do |line|
102
+ security_group_id = line.strip
103
+ begin
104
+ security_group = env[:cloudstack_compute].security_groups.get(security_group_id)
105
+
106
+ security_group.ingress_rules.each do |ir|
107
+ env[:cloudstack_compute].revoke_security_group_ingress({:id => ir['ruleid']})
108
+ end
109
+ env[:ui].info('Deleted ingress rules')
110
+
111
+ security_group.egress_rules.each do |er|
112
+ env[:cloudstack_compute].revoke_security_group_egress({:id => er['ruleid']})
113
+ end
114
+ env[:ui].info('Deleted egress rules')
115
+
116
+ rescue Fog::Compute::Cloudstack::Error => e
117
+ raise Errors::FogError, :message => e.message
118
+ end
119
+
120
+ begin
121
+ env[:cloudstack_compute].delete_security_group({:id => security_group_id})
122
+ rescue Fog::Compute::Cloudstack::Error => e
123
+ env[:ui].warn("Couldn't delete group right now.")
124
+ env[:ui].warn('Waiting 30 seconds to retry')
125
+ sleep 30
126
+ retry
127
+ end
128
+ end
129
+ security_groups_file.delete
130
+ end
131
+ end
132
+
133
+ def remove_generated_ssh_key(env)
134
+ sshkeyname_file = env[:machine].data_dir.join('sshkeyname')
135
+ if sshkeyname_file.file?
136
+ env[:ui].info(I18n.t('vagrant_cloudstack.ssh_key_pair_removing'))
137
+ sshkeyname = ''
138
+ File.read(sshkeyname_file).each_line do |line|
139
+ sshkeyname = line.strip
140
+ end
141
+
142
+ begin
143
+ response = env[:cloudstack_compute].delete_ssh_key_pair(name: sshkeyname)
144
+ env[:ui].warn(I18n.t('vagrant_cloudstack.ssh_key_pair_no_success_removing', name: sshkeyname)) unless response['deletesshkeypairresponse']['success'] == 'true'
145
+ rescue Fog::Compute::Cloudstack::Error => e
146
+ env[:ui].warn(I18n.t('vagrant_cloudstack.errors.fog_error', :message => e.message))
147
+ end
148
+ sshkeyname_file.delete
149
+ end
150
+ end
151
+
152
+ def remove_stored_credentials(env)
153
+ vmcredentials_file = env[:machine].data_dir.join('vmcredentials')
154
+ vmcredentials_file.delete if vmcredentials_file.file?
155
+ end
156
+
157
+ def remove_portforwarding(env)
158
+ env[:ui].info(I18n.t('vagrant_cloudstack.deleting_port_forwarding_rule'))
159
+ port_forwarding_file = env[:machine].data_dir.join('port_forwarding')
160
+ if port_forwarding_file.file?
161
+ File.read(port_forwarding_file).each_line do |line|
162
+ rule_id = line.strip
163
+ begin
164
+ resp = env[:cloudstack_compute].delete_port_forwarding_rule({:id => rule_id})
165
+ job_id = resp['deleteportforwardingruleresponse']['jobid']
166
+ while true
167
+ response = env[:cloudstack_compute].query_async_job_result({:jobid => job_id})
168
+ if response['queryasyncjobresultresponse']['jobstatus'] != 0
169
+ break
170
+ else
171
+ sleep 2
172
+ end
173
+ end
174
+ rescue Fog::Compute::Cloudstack::Error => e
175
+ if e.message =~ /Unable to execute API command deleteportforwardingrule.*entity does not exist/
176
+ env[:ui].warn(" -- Failed to delete portforwarding rule: #{e.message}")
177
+ else
178
+ raise Errors::FogError, :message => e.message
179
+ end
180
+
181
+ end
182
+ end
183
+ port_forwarding_file.delete
184
+ end
185
+
186
+ # Delete the Communicator Port forwording public port file
187
+ # Delete the RDP Port forwording public port file
188
+ %w(pf_public_port pf_public_rdp_port).each do |pf_filename|
189
+ pf_file = env[:machine].data_dir.join(pf_filename)
190
+ pf_file.delete if pf_file.file?
191
+ end
192
+ end
193
+
194
+ def remove_static_nat(env)
195
+ env[:ui].info(I18n.t('vagrant_cloudstack.disabling_static_nat'))
196
+ static_nat_file = env[:machine].data_dir.join('static_nat')
197
+ if static_nat_file.file?
198
+ File.read(static_nat_file).each_line do |line|
199
+ ip_address_id = line.strip
200
+ begin
201
+ options = {
202
+ :command => 'disableStaticNat',
203
+ :ipaddressid => ip_address_id
204
+ }
205
+ resp = env[:cloudstack_compute].request(options)
206
+ job_id = resp['disablestaticnatresponse']['jobid']
207
+ while true
208
+ response = env[:cloudstack_compute].query_async_job_result({:jobid => job_id})
209
+ if response['queryasyncjobresultresponse']['jobstatus'] != 0
210
+ break
211
+ else
212
+ sleep 2
213
+ end
214
+ end
215
+ rescue Fog::Compute::Cloudstack::Error => e
216
+ raise Errors::FogError, :message => e.message
217
+ end
218
+ end
219
+ static_nat_file.delete
220
+ end
221
+ end
222
+
223
+ def remove_firewall_rules(env)
224
+ env[:ui].info(I18n.t('vagrant_cloudstack.deleting_firewall_rule'))
225
+ firewall_file = env[:machine].data_dir.join('firewall')
226
+ if firewall_file.file?
227
+ File.read(firewall_file).each_line do |line|
228
+ line_items=line.split(",").collect(&:strip)
229
+ rule_id = line_items[0]
230
+ type_string = line_items[1]
231
+
232
+ if type_string == 'firewallrule'
233
+ command_string = 'deleteFirewallRule'
234
+ response_string = 'deletefirewallruleresponse'
235
+ else
236
+ command_string = 'deleteNetworkACL'
237
+ response_string = 'deletenetworkaclresponse'
238
+ end
239
+
240
+ begin
241
+ options = {
242
+ command: command_string,
243
+ id: rule_id
244
+ }
245
+ resp = env[:cloudstack_compute].request(options)
246
+ job_id = resp[response_string]['jobid']
247
+ while true
248
+ response = env[:cloudstack_compute].query_async_job_result({:jobid => job_id})
249
+ if response['queryasyncjobresultresponse']['jobstatus'] != 0
250
+ break
251
+ else
252
+ sleep 2
253
+ end
254
+ end
255
+ rescue Fog::Compute::Cloudstack::Error => e
256
+ if e.message =~ /Unable to execute API command deletefirewallrule.*entity does not exist/
257
+ env[:ui].warn(" -- Failed to delete #{type_string}: #{e.message}")
258
+ else
259
+ raise Errors::FogError, :message => e.message
260
+ end
261
+ end
262
+ end
263
+ firewall_file.delete
264
+ end
265
+ end
266
+ end
267
+ end
268
+ end
269
+ end