vagrant-vsphere 0.14.0 → 0.15.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
2
  SHA1:
3
- metadata.gz: 18ea9f258ae0478f7b099bd5f90ab8cee9e5de79
4
- data.tar.gz: 39813243c2ded6a1e451f504533cea4b4c230745
3
+ metadata.gz: c011d25a3f928fd80cd7fc8c9df74e647de432a8
4
+ data.tar.gz: c4f6350c4ac9090a4fa87a167f9ae73e18069768
5
5
  SHA512:
6
- metadata.gz: 6be072277703883e5e6876dc16c456656ca90073ea5c4d7b0fdb7ba8fab42792075abf3c598c0f6c69f273b9d349703ad08a18104af227c894eda3a8ccb68b40
7
- data.tar.gz: 2281f71c3ad514d185aecda5962291ae1114019ad0b37d0089f4cfb186fea556d9df8a80169b8f8a57359582c0c2787295952f1805f883271bb8319c9980dbcd
6
+ metadata.gz: 51261468c611ba92faf5803e6883b7fa5219efe4c4be61a18cd54c42122a9bc6a8afd8261b9dcd26f7508d6dbec569916bf505021a34921c97ce550410830325
7
+ data.tar.gz: 45038a038b302e6c82a06d8e9bf459f35daa25f329b937ca1795d32795217383e2a17a57dcec9195b3978e58f876d98442dc5680cc43566a9841362c256aac0f
data/.bumpversion.cfg CHANGED
@@ -1,5 +1,5 @@
1
1
  [bumpversion]
2
- current_version = 0.14.0
2
+ current_version = 0.15.0
3
3
  tag = true
4
4
  commit = true
5
5
 
data/README.md CHANGED
@@ -12,9 +12,9 @@ This provider is built on top of the [RbVmomi](https://github.com/vmware/rbvmomi
12
12
  * libxml2, libxml2-dev, libxslt, libxslt-dev
13
13
 
14
14
  ## Current Version
15
- **version: 0.14.0**
15
+ **version: 0.15.0**
16
16
 
17
- vagrant-vsphere (**version: 0.14.0**) is available from [RubyGems.org](https://rubygems.org/gems/vagrant-vsphere)
17
+ vagrant-vsphere (**version: 0.15.0**) is available from [RubyGems.org](https://rubygems.org/gems/vagrant-vsphere)
18
18
 
19
19
  ## Installation
20
20
 
@@ -100,6 +100,7 @@ This provider has the following settings, all are required unless noted:
100
100
  * `linked_clone` - _Optional_ link the cloned VM to the parent to share virtual disks
101
101
  * `proxy_host` - _Optional_ proxy host name for connecting to vSphere via proxy
102
102
  * `proxy_port` - _Optional_ proxy port number for connecting to vSphere via proxy
103
+ * `vlan` - _Optional_ vlan to connect the first NIC to
103
104
 
104
105
  ### Cloning from a VM rather than a template
105
106
 
@@ -187,6 +188,10 @@ This is useful if running Vagrant from multiple directories or if multiple machi
187
188
  * 0.14.0 Add vlan configuration [#91 rylarson:add-vlan-configuration](https://github.com/nsidc/vagrant-vsphere/pull/91)
188
189
  * Added a new configuration option 'vlan' that lets you specify the vlan string
189
190
  * If vlan is set, the clone spec is modified with an edit action to connect the first NIC on the VM to the configured VLAN.
191
+ * 0.15.0 Make destroy work in all vm states [#93 rylarson:make-destroy-work-in-all-vm-states](https://github.com/nsidc/vagrant-vsphere/pull/93) (fixes #77)
192
+ * If the VM is powered on, then it is powered off, and destroyed.
193
+ * If the VM is powered off, it is just destroyed.
194
+ * If the VM is suspended, it is powered on, then powered off, then destroyed.
190
195
 
191
196
 
192
197
  ## Versioning
@@ -1,16 +1,13 @@
1
1
  require 'rbvmomi'
2
2
  require 'vSphere/util/vim_helpers'
3
+ require 'vSphere/util/vm_helpers'
3
4
 
4
5
  module VagrantPlugins
5
6
  module VSphere
6
7
  module Action
7
8
  class GetState
8
9
  include Util::VimHelpers
9
-
10
- # the three possible values of a vSphere VM's power state
11
- POWERED_ON = 'poweredOn'
12
- POWERED_OFF = 'poweredOff'
13
- SUSPENDED = 'suspended'
10
+ include Util::VmHelpers
14
11
 
15
12
  def initialize(app, env)
16
13
  @app = app
@@ -33,7 +30,7 @@ module VagrantPlugins
33
30
  return :not_created
34
31
  end
35
32
 
36
- if vm.runtime.powerState.eql?(POWERED_ON)
33
+ if powered_on?(vm)
37
34
  :running
38
35
  else
39
36
  # If the VM is powered off or suspended, we consider it to be powered off. A power on command will either turn on or resume the VM
@@ -1,12 +1,14 @@
1
1
  require 'rbvmomi'
2
2
  require 'i18n'
3
3
  require 'vSphere/util/vim_helpers'
4
+ require 'vSphere/util/vm_helpers'
4
5
 
5
6
  module VagrantPlugins
6
7
  module VSphere
7
8
  module Action
8
9
  class PowerOff
9
10
  include Util::VimHelpers
11
+ include Util::VmHelpers
10
12
 
11
13
  def initialize(app, env)
12
14
  @app = app
@@ -15,9 +17,19 @@ module VagrantPlugins
15
17
  def call(env)
16
18
  vm = get_vm_by_uuid env[:vSphere_connection], env[:machine]
17
19
 
18
- unless vm.nil?
20
+ # If the vm is suspended, we need to turn it on so that we can turn it off.
21
+ # This may seem counterintuitive, but the vsphere API documentation states
22
+ # that the Power Off task for a VM will fail if the state is not poweredOn
23
+ # see: https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.VirtualMachine.html#powerOff
24
+ if suspended?(vm)
25
+ env[:ui].info I18n.t('vsphere.power_on_vm')
26
+ power_on_vm(vm)
27
+ end
28
+
29
+ # Powering off is a no-op if we can't find the VM or if it is already off
30
+ unless vm.nil? || powered_off?(vm)
19
31
  env[:ui].info I18n.t('vsphere.power_off_vm')
20
- vm.PowerOffVM_Task.wait_for_completion
32
+ power_off_vm(vm)
21
33
  end
22
34
 
23
35
  @app.call env
@@ -2,12 +2,14 @@ require 'rbvmomi'
2
2
  require 'i18n'
3
3
  require 'vSphere/util/vim_helpers'
4
4
  require 'vSphere/util/machine_helpers'
5
+ require 'vSphere/util/vm_helpers'
5
6
 
6
7
  module VagrantPlugins
7
8
  module VSphere
8
9
  module Action
9
10
  class PowerOn
10
11
  include Util::VimHelpers
12
+ include Util::VmHelpers
11
13
  include Util::MachineHelpers
12
14
 
13
15
  def initialize(app, env)
@@ -18,7 +20,7 @@ module VagrantPlugins
18
20
  vm = get_vm_by_uuid env[:vSphere_connection], env[:machine]
19
21
 
20
22
  env[:ui].info I18n.t('vsphere.power_on_vm')
21
- vm.PowerOnVM_Task.wait_for_completion
23
+ power_on_vm(vm)
22
24
 
23
25
  # wait for SSH to be available
24
26
  wait_for_ssh env
@@ -0,0 +1,40 @@
1
+ require 'rbvmomi'
2
+
3
+ module VagrantPlugins
4
+ module VSphere
5
+ module Util
6
+
7
+ module VmState
8
+ POWERED_ON = 'poweredOn'
9
+ POWERED_OFF = 'poweredOff'
10
+ SUSPENDED = 'suspended'
11
+ end
12
+
13
+ module VmHelpers
14
+ def power_on_vm(vm)
15
+ vm.PowerOnVM_Task.wait_for_completion
16
+ end
17
+
18
+ def power_off_vm(vm)
19
+ vm.PowerOffVM_Task.wait_for_completion
20
+ end
21
+
22
+ def get_vm_state(vm)
23
+ vm.runtime.powerState
24
+ end
25
+
26
+ def powered_on?(vm)
27
+ get_vm_state(vm).eql?(VmState::POWERED_ON)
28
+ end
29
+
30
+ def powered_off?(vm)
31
+ get_vm_state(vm).eql?(VmState::POWERED_OFF)
32
+ end
33
+
34
+ def suspended?(vm)
35
+ get_vm_state(vm).eql?(VmState::SUSPENDED)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module VSphere
3
- VERSION = '0.14.0'
3
+ VERSION = '0.15.0'
4
4
  end
5
5
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'vSphere/util/vim_helpers'
2
3
 
3
4
  describe VagrantPlugins::VSphere::Action::GetState do
4
5
  before :each do
@@ -21,7 +22,7 @@ describe VagrantPlugins::VSphere::Action::GetState do
21
22
 
22
23
  it 'should set state id to running if machine is powered on' do
23
24
  @env[:machine].stub(:id).and_return(EXISTING_UUID)
24
- @vm.runtime.stub(:powerState).and_return(described_class::POWERED_ON)
25
+ @vm.runtime.stub(:powerState).and_return(VagrantPlugins::VSphere::Util::VmState::POWERED_ON)
25
26
 
26
27
  call
27
28
 
@@ -30,7 +31,7 @@ describe VagrantPlugins::VSphere::Action::GetState do
30
31
 
31
32
  it 'should set state id to powered off if machine is powered off' do
32
33
  @env[:machine].stub(:id).and_return(EXISTING_UUID)
33
- @vm.runtime.stub(:powerState).and_return(described_class::POWERED_OFF)
34
+ @vm.runtime.stub(:powerState).and_return(VagrantPlugins::VSphere::Util::VmState::POWERED_OFF)
34
35
 
35
36
  call
36
37
 
@@ -39,7 +40,7 @@ describe VagrantPlugins::VSphere::Action::GetState do
39
40
 
40
41
  it 'should set state id to powered off if machine is suspended' do
41
42
  @env[:machine].stub(:id).and_return(EXISTING_UUID)
42
- @vm.runtime.stub(:powerState).and_return(described_class::SUSPENDED)
43
+ @vm.runtime.stub(:powerState).and_return(VagrantPlugins::VSphere::Util::VmState::SUSPENDED)
43
44
 
44
45
  call
45
46
 
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe VagrantPlugins::VSphere::Action::PowerOff do
4
+ before :each do
5
+ @env[:vSphere_connection] = @vim
6
+ end
7
+
8
+ it 'should power off the VM if it is powered on' do
9
+ @machine.stub(:id).and_return(EXISTING_UUID)
10
+ @machine.state.stub(:id).and_return(VagrantPlugins::VSphere::Util::VmState::POWERED_ON)
11
+
12
+ call
13
+
14
+ expect(@vm).to have_received :PowerOffVM_Task
15
+ end
16
+
17
+ it 'should not power off the VM if is powered off' do
18
+ @machine.stub(:id).and_return(EXISTING_UUID)
19
+ @vm.runtime.stub(:powerState).and_return(VagrantPlugins::VSphere::Util::VmState::POWERED_OFF)
20
+
21
+ call
22
+
23
+ expect(@vm).not_to have_received :PowerOffVM_Task
24
+ end
25
+
26
+ it 'should power on and off the VM if is suspended' do
27
+ @machine.stub(:id).and_return(EXISTING_UUID)
28
+ @vm.runtime.stub(:powerState).and_return(VagrantPlugins::VSphere::Util::VmState::SUSPENDED)
29
+
30
+ call
31
+
32
+ expect(@vm).to have_received :PowerOnVM_Task
33
+ expect(@vm).to have_received :PowerOffVM_Task
34
+ end
35
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-vsphere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Grauch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-19 00:00:00.000000000 Z
11
+ date: 2014-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -142,6 +142,7 @@ files:
142
142
  - lib/vSphere/provider.rb
143
143
  - lib/vSphere/util/machine_helpers.rb
144
144
  - lib/vSphere/util/vim_helpers.rb
145
+ - lib/vSphere/util/vm_helpers.rb
145
146
  - lib/vSphere/version.rb
146
147
  - lib/vagrant-vsphere.rb
147
148
  - locales/en.yml
@@ -152,6 +153,7 @@ files:
152
153
  - spec/get_ssh_info_spec.rb
153
154
  - spec/get_state_spec.rb
154
155
  - spec/is_created_spec.rb
156
+ - spec/power_off_spec.rb
155
157
  - spec/spec_helper.rb
156
158
  - vSphere.gemspec
157
159
  homepage: ''
@@ -174,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
176
  version: '0'
175
177
  requirements: []
176
178
  rubyforge_project:
177
- rubygems_version: 2.0.14
179
+ rubygems_version: 2.2.2
178
180
  signing_key:
179
181
  specification_version: 4
180
182
  summary: VMWare vSphere provider
@@ -186,4 +188,5 @@ test_files:
186
188
  - spec/get_ssh_info_spec.rb
187
189
  - spec/get_state_spec.rb
188
190
  - spec/is_created_spec.rb
191
+ - spec/power_off_spec.rb
189
192
  - spec/spec_helper.rb