Skip to content

Commit 3320126

Browse files
Merge pull request #75 from j00p34/master
Fixes #74
2 parents 4fe8c5b + 939044b commit 3320126

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ to update UUIDs in your Vagrantfile. If both are specified, the id parameter tak
161161
* `ssh_key` - Path to a private key to be used with ssh
162162
* `ssh_user` - User name to be used with ssh
163163
* `private_ip_address` - private (static)ip address to be used by the virtual machine
164+
* `expunge_on_destroy` - Flag to enable/disable expunge vm on destroy
164165

165166
These can be set like typical provider-specific configuration:
166167

lib/vagrant-cloudstack/action/terminate_instance.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,14 @@ def call(env)
9797

9898
env[:ui].info(I18n.t("vagrant_cloudstack.terminating"))
9999

100-
job = server.destroy
100+
domain = env[:machine].provider_config.domain_id
101+
domain_config = env[:machine].provider_config.get_domain_config(domain)
102+
expunge_on_destroy = domain_config.expunge_on_destroy
103+
104+
options = {}
105+
options['expunge'] = expunge_on_destroy
106+
107+
job = server.destroy(options)
101108
while true
102109
response = env[:cloudstack_compute].query_async_job_result({:jobid => job.id})
103110
if response["queryasyncjobresultresponse"]["jobstatus"] != 0

lib/vagrant-cloudstack/config.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ class Config < Vagrant.plugin("2", :config)
197197
# @return [String]
198198
attr_accessor :private_ip_address
199199

200+
# flag to enable/disable expunge vm on destroy
201+
#
202+
# @return [Boolean]
203+
attr_accessor :expunge_on_destroy
200204

201205
def initialize(domain_specific=false)
202206
@host = UNSET_VALUE
@@ -236,6 +240,7 @@ def initialize(domain_specific=false)
236240
@ssh_key = UNSET_VALUE
237241
@ssh_user = UNSET_VALUE
238242
@private_ip_address = UNSET_VALUE
243+
@expunge_on_destroy = UNSET_VALUE
239244

240245
# Internal state (prefix with __ so they aren't automatically
241246
# merged)
@@ -417,6 +422,9 @@ def finalize!
417422
# private ip is nil by default
418423
@private_ip_address = nil if @private_ip_address == UNSET_VALUE
419424

425+
# expunge on destroy is nil by default
426+
@expunge_on_destroy = false if @expunge_on_destroy == UNSET_VALUE
427+
420428
# Compile our domain specific configurations only within
421429
# NON-DOMAIN-SPECIFIC configurations.
422430
if !@__domain_specific

spec/vagrant-cloudstack/config_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
its("ssh_key") { should be_nil }
4848
its("ssh_user") { should be_nil }
4949
its("private_ip_address") { should be_nil }
50+
its("expunge_on_destroy") { should == false }
5051
end
5152

5253
describe "getting credentials from environment" do
@@ -148,6 +149,7 @@
148149
let(:config_ssh_key) { "./foo.pem" }
149150
let(:config_ssh_user) { "foo" }
150151
let(:config_private_ip_address) { "foo" }
152+
let(:config_expunge_on_destroy) { "foo" }
151153

152154
def set_test_values(instance)
153155
instance.host = config_host
@@ -180,6 +182,7 @@ def set_test_values(instance)
180182
instance.ssh_key = config_ssh_key
181183
instance.ssh_user = config_ssh_user
182184
instance.private_ip_address = config_private_ip_address
185+
instance.expunge_on_destroy = config_expunge_on_destroy
183186
end
184187

185188
it "should raise an exception if not finalized" do
@@ -229,6 +232,7 @@ def set_test_values(instance)
229232
its("ssh_key") { should == config_ssh_key }
230233
its("ssh_user") { should == config_ssh_user }
231234
its("private_ip_address") { should == config_private_ip_address }
235+
its("expunge_on_destroy") { should == config_expunge_on_destroy }
232236
end
233237

234238
context "with a specific config set" do
@@ -277,6 +281,7 @@ def set_test_values(instance)
277281
its("ssh_key") { should == config_ssh_key }
278282
its("ssh_user") { should == config_ssh_user }
279283
its("private_ip_address") { should == config_private_ip_address }
284+
its("expunge_on_destroy") { should == config_expunge_on_destroy }
280285
end
281286

282287
describe "inheritance of parent config" do

0 commit comments

Comments
 (0)