Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds flag to config to expunge vm immediately on destroy #75

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ to update UUIDs in your Vagrantfile. If both are specified, the id parameter tak
* `ssh_key` - Path to a private key to be used with ssh
* `ssh_user` - User name to be used with ssh
* `private_ip_address` - private (static)ip address to be used by the virtual machine
* `expunge_on_destroy` - Flag to enable/disable expunge vm on destroy

These can be set like typical provider-specific configuration:

Expand Down
9 changes: 8 additions & 1 deletion lib/vagrant-cloudstack/action/terminate_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ def initialize(app, env)
end

def call(env)
# Get the configs
domain = env[:machine].provider_config.domain_id
domain_config = env[:machine].provider_config.get_domain_config(domain)
expunge_on_destroy = domain_config.expunge_on_destroy

# Disable Static NAT
env[:ui].info(I18n.t("vagrant_cloudstack.disabling_static_nat"))
static_nat_file = env[:machine].data_dir.join("static_nat")
Expand Down Expand Up @@ -96,8 +101,10 @@ def call(env)
server = env[:cloudstack_compute].servers.get(env[:machine].id)

env[:ui].info(I18n.t("vagrant_cloudstack.terminating"))
options = {}
options['expunge'] = expunge_on_destroy

job = server.destroy
job = server.destroy(options)
while true
response = env[:cloudstack_compute].query_async_job_result({:jobid => job.id})
if response["queryasyncjobresultresponse"]["jobstatus"] != 0
Expand Down
8 changes: 8 additions & 0 deletions lib/vagrant-cloudstack/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ class Config < Vagrant.plugin("2", :config)
# @return [String]
attr_accessor :private_ip_address

# flag to enable/disable expunge vm on destroy
#
# @return [Boolean]
attr_accessor :expunge_on_destroy

def initialize(domain_specific=false)
@host = UNSET_VALUE
Expand Down Expand Up @@ -236,6 +240,7 @@ def initialize(domain_specific=false)
@ssh_key = UNSET_VALUE
@ssh_user = UNSET_VALUE
@private_ip_address = UNSET_VALUE
@expunge_on_destroy = UNSET_VALUE

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

# expunge on destroy is nil by default
@expunge_on_destroy = false if @expunge_on_destroy == UNSET_VALUE

# Compile our domain specific configurations only within
# NON-DOMAIN-SPECIFIC configurations.
if !@__domain_specific
Expand Down
5 changes: 5 additions & 0 deletions spec/vagrant-cloudstack/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
its("ssh_key") { should be_nil }
its("ssh_user") { should be_nil }
its("private_ip_address") { should be_nil }
its("expunge_on_destroy") { should == false }
end

describe "getting credentials from environment" do
Expand Down Expand Up @@ -148,6 +149,7 @@
let(:config_ssh_key) { "./foo.pem" }
let(:config_ssh_user) { "foo" }
let(:config_private_ip_address) { "foo" }
let(:config_expunge_on_destroy) { "foo" }

def set_test_values(instance)
instance.host = config_host
Expand Down Expand Up @@ -180,6 +182,7 @@ def set_test_values(instance)
instance.ssh_key = config_ssh_key
instance.ssh_user = config_ssh_user
instance.private_ip_address = config_private_ip_address
instance.expunge_on_destroy = config_expunge_on_destroy
end

it "should raise an exception if not finalized" do
Expand Down Expand Up @@ -229,6 +232,7 @@ def set_test_values(instance)
its("ssh_key") { should == config_ssh_key }
its("ssh_user") { should == config_ssh_user }
its("private_ip_address") { should == config_private_ip_address }
its("expunge_on_destroy") { should == config_expunge_on_destroy }
end

context "with a specific config set" do
Expand Down Expand Up @@ -277,6 +281,7 @@ def set_test_values(instance)
its("ssh_key") { should == config_ssh_key }
its("ssh_user") { should == config_ssh_user }
its("private_ip_address") { should == config_private_ip_address }
its("expunge_on_destroy") { should == config_expunge_on_destroy }
end

describe "inheritance of parent config" do
Expand Down