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.
- checksums.yaml +4 -4
- data/.gitignore +18 -19
- data/.ruby-version +1 -1
- data/.travis.yml +19 -19
- data/CHANGELOG.md +179 -171
- data/Docker/.dockerignore +2 -0
- data/Docker/Dockerfile +51 -0
- data/Docker/Dockerfile.chefdk_0_17 +49 -0
- data/Docker/Dockerfile.latest_dependencies +49 -0
- data/Docker/README.md +67 -0
- data/Docker/vac.ps1 +29 -0
- data/Docker/vac.sh +30 -0
- data/Gemfile +20 -20
- data/LICENSE +8 -8
- data/README.md +416 -416
- data/Rakefile +106 -99
- data/bootstrap.key +27 -0
- data/build_rpm.sh +7 -7
- data/functional-tests/basic/Vagrantfile.basic_networking +45 -45
- data/functional-tests/basic/basic_spec.rb +21 -21
- data/functional-tests/networking/Vagrantfile.advanced_networking +119 -102
- data/functional-tests/networking/networking_spec.rb +14 -0
- data/functional-tests/rsync/Vagrantfile.advanced_networking +39 -56
- data/functional-tests/rsync/rsync_spec.rb +9 -9
- data/functional-tests/vmlifecycle/Vagrantfile.advanced_networking +66 -82
- data/functional-tests/vmlifecycle/vmlifecycle_spec.rb +13 -13
- data/lib/vagrant-cloudstack/action/connect_cloudstack.rb +47 -47
- data/lib/vagrant-cloudstack/action/is_created.rb +18 -18
- data/lib/vagrant-cloudstack/action/is_stopped.rb +18 -18
- data/lib/vagrant-cloudstack/action/message_already_created.rb +16 -16
- data/lib/vagrant-cloudstack/action/message_not_created.rb +16 -16
- data/lib/vagrant-cloudstack/action/message_will_not_destroy.rb +16 -16
- data/lib/vagrant-cloudstack/action/read_rdp_info.rb +76 -76
- data/lib/vagrant-cloudstack/action/read_ssh_info.rb +104 -87
- data/lib/vagrant-cloudstack/action/read_state.rb +38 -38
- data/lib/vagrant-cloudstack/action/read_winrm_info.rb +103 -103
- data/lib/vagrant-cloudstack/action/run_instance.rb +798 -703
- data/lib/vagrant-cloudstack/action/start_instance.rb +81 -81
- data/lib/vagrant-cloudstack/action/stop_instance.rb +28 -28
- data/lib/vagrant-cloudstack/action/terminate_instance.rb +269 -224
- data/lib/vagrant-cloudstack/action/timed_provision.rb +21 -21
- data/lib/vagrant-cloudstack/action/wait_for_state.rb +41 -41
- data/lib/vagrant-cloudstack/action/warn_networks.rb +19 -19
- data/lib/vagrant-cloudstack/action.rb +210 -210
- data/lib/vagrant-cloudstack/capabilities/rdp.rb +12 -12
- data/lib/vagrant-cloudstack/capabilities/winrm.rb +12 -12
- data/lib/vagrant-cloudstack/config.rb +566 -548
- data/lib/vagrant-cloudstack/errors.rb +27 -27
- data/lib/vagrant-cloudstack/exceptions/exceptions.rb +10 -10
- data/lib/vagrant-cloudstack/model/cloudstack_resource.rb +51 -33
- data/lib/vagrant-cloudstack/plugin.rb +82 -82
- data/lib/vagrant-cloudstack/provider.rb +58 -58
- data/lib/vagrant-cloudstack/service/cloudstack_resource_service.rb +64 -58
- data/lib/vagrant-cloudstack/util/timer.rb +17 -17
- data/lib/vagrant-cloudstack/version.rb +5 -5
- data/lib/vagrant-cloudstack.rb +17 -17
- data/locales/en.yml +131 -123
- data/spec/spec_helper.rb +8 -6
- data/spec/vagrant-cloudstack/action/read_ssh_info_spec.rb +80 -0
- data/spec/vagrant-cloudstack/config_spec.rb +355 -355
- data/spec/vagrant-cloudstack/model/cloudstack_resource_spec.rb +95 -73
- data/spec/vagrant-cloudstack/service/cloudstack_resource_service_spec.rb +43 -43
- data/spec/vagrant-cloudstack/support/be_a_resource.rb +6 -0
- data/vagrant-cloudstack.gemspec +59 -59
- data/vagrant-cloudstack.spec +42 -42
- metadata +14 -7
- data/dummy.box +0 -0
- data/example_box/README.md +0 -13
- data/example_box/metadata.json +0 -3
- 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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
env
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
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
|