vagrant-vsphere 0.19.0 → 0.19.1

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.
@@ -9,7 +9,7 @@ module VagrantPlugins
9
9
  include Util::VimHelpers
10
10
  include Util::VmHelpers
11
11
 
12
- def initialize(app, env)
12
+ def initialize(app, _env)
13
13
  @app = app
14
14
  end
15
15
 
@@ -26,9 +26,7 @@ module VagrantPlugins
26
26
 
27
27
  vm = get_vm_by_uuid connection, machine
28
28
 
29
- if vm.nil?
30
- return :not_created
31
- end
29
+ return :not_created if vm.nil?
32
30
 
33
31
  if powered_on?(vm)
34
32
  :running
@@ -40,4 +38,4 @@ module VagrantPlugins
40
38
  end
41
39
  end
42
40
  end
43
- end
41
+ end
@@ -2,7 +2,7 @@ module VagrantPlugins
2
2
  module VSphere
3
3
  module Action
4
4
  class IsCreated
5
- def initialize(app, env)
5
+ def initialize(app, _env)
6
6
  @app = app
7
7
  end
8
8
 
@@ -13,4 +13,4 @@ module VagrantPlugins
13
13
  end
14
14
  end
15
15
  end
16
- end
16
+ end
@@ -5,8 +5,8 @@ module VagrantPlugins
5
5
  module Action
6
6
  class IsRunning
7
7
  include Util::MachineHelpers
8
-
9
- def initialize(app, env)
8
+
9
+ def initialize(app, _env)
10
10
  @app = app
11
11
  end
12
12
 
@@ -4,7 +4,7 @@ module VagrantPlugins
4
4
  module VSphere
5
5
  module Action
6
6
  class MessageAlreadyCreated
7
- def initialize(app, env)
7
+ def initialize(app, _env)
8
8
  @app = app
9
9
  end
10
10
 
@@ -15,4 +15,4 @@ module VagrantPlugins
15
15
  end
16
16
  end
17
17
  end
18
- end
18
+ end
@@ -4,7 +4,7 @@ module VagrantPlugins
4
4
  module VSphere
5
5
  module Action
6
6
  class MessageNotCreated
7
- def initialize(app, env)
7
+ def initialize(app, _env)
8
8
  @app = app
9
9
  end
10
10
 
@@ -4,7 +4,7 @@ module VagrantPlugins
4
4
  module VSphere
5
5
  module Action
6
6
  class MessageNotRunning
7
- def initialize(app, env)
7
+ def initialize(app, _env)
8
8
  @app = app
9
9
  end
10
10
 
@@ -10,7 +10,7 @@ module VagrantPlugins
10
10
  include Util::VimHelpers
11
11
  include Util::VmHelpers
12
12
 
13
- def initialize(app, env)
13
+ def initialize(app, _env)
14
14
  @app = app
15
15
  end
16
16
 
@@ -37,4 +37,4 @@ module VagrantPlugins
37
37
  end
38
38
  end
39
39
  end
40
- end
40
+ end
@@ -12,7 +12,7 @@ module VagrantPlugins
12
12
  include Util::VmHelpers
13
13
  include Util::MachineHelpers
14
14
 
15
- def initialize(app, env)
15
+ def initialize(app, _env)
16
16
  @app = app
17
17
  end
18
18
 
@@ -21,10 +21,10 @@ module VagrantPlugins
21
21
 
22
22
  env[:ui].info I18n.t('vsphere.power_on_vm')
23
23
  power_on_vm(vm)
24
-
25
- # wait for SSH to be available
24
+
25
+ # wait for SSH to be available
26
26
  wait_for_ssh env
27
-
27
+
28
28
  @app.call env
29
29
  end
30
30
  end
@@ -28,7 +28,7 @@ module VagrantPlugins
28
28
  errors = _detected_errors
29
29
 
30
30
  if password == :ask || password.nil?
31
- self.password = machine.ui.ask("vSphere Password (will be hidden): ", echo: false)
31
+ self.password = machine.ui.ask('vSphere Password (will be hidden): ', echo: false)
32
32
  end
33
33
 
34
34
  # TODO: add blank?
@@ -38,7 +38,7 @@ module VagrantPlugins
38
38
  errors << I18n.t('vsphere.config.template') if template_name.nil?
39
39
 
40
40
  # Only required if we're cloning from an actual template
41
- errors << I18n.t('vsphere.config.compute_resource') if compute_resource_name.nil? and not clone_from_vm
41
+ errors << I18n.t('vsphere.config.compute_resource') if compute_resource_name.nil? && !clone_from_vm
42
42
 
43
43
  { 'vSphere Provider' => errors }
44
44
  end
@@ -1,13 +1,13 @@
1
1
  begin
2
- require "vagrant"
2
+ require 'vagrant'
3
3
  rescue LoadError
4
- raise "The Vagrant vSphere plugin must be run within Vagrant."
4
+ raise 'The Vagrant vSphere plugin must be run within Vagrant.'
5
5
  end
6
6
 
7
7
  # This is a sanity check to make sure no one is attempting to install
8
8
  # this into an early Vagrant version.
9
- if Vagrant::VERSION < "1.5"
10
- raise "The Vagrant vSphere plugin is only compatible with Vagrant 1.5+"
9
+ if Vagrant::VERSION < '1.5'
10
+ fail 'The Vagrant vSphere plugin is only compatible with Vagrant 1.5+'
11
11
  end
12
12
 
13
13
  module VagrantPlugins
@@ -30,11 +30,10 @@ module VagrantPlugins
30
30
  Provider
31
31
  end
32
32
 
33
-
34
33
  def self.setup_i18n
35
34
  I18n.load_path << File.expand_path('locales/en.yml', VSphere.source_root)
36
35
  I18n.reload!
37
36
  end
38
37
  end
39
38
  end
40
- end
39
+ end
@@ -36,4 +36,4 @@ module VagrantPlugins
36
36
  end
37
37
  end
38
38
  end
39
- end
39
+ end
@@ -3,16 +3,16 @@ module VagrantPlugins
3
3
  module Util
4
4
  module MachineHelpers
5
5
  def wait_for_ssh(env)
6
- if not env[:machine].config.vm.communicator.nil? and env[:machine].config.vm.communicator == :winrm
7
- env[:ui].info(I18n.t("vsphere.waiting_for_winrm"))
6
+ if !env[:machine].config.vm.communicator.nil? && env[:machine].config.vm.communicator == :winrm
7
+ env[:ui].info(I18n.t('vsphere.waiting_for_winrm'))
8
8
  else
9
- env[:ui].info(I18n.t("vsphere.waiting_for_ssh"))
9
+ env[:ui].info(I18n.t('vsphere.waiting_for_ssh'))
10
10
  end
11
-
12
- while true
11
+
12
+ loop do
13
13
  break if env[:machine].communicate.ready?
14
14
  sleep 5
15
- end
15
+ end
16
16
  end
17
17
  end
18
18
  end
@@ -5,7 +5,7 @@ module VagrantPlugins
5
5
  module Util
6
6
  module VimHelpers
7
7
  def get_datacenter(connection, machine)
8
- connection.serviceInstance.find_datacenter(machine.provider_config.data_center_name) or fail Errors::VSphereError, :missing_datacenter
8
+ connection.serviceInstance.find_datacenter(machine.provider_config.data_center_name) || fail(Errors::VSphereError, :missing_datacenter)
9
9
  end
10
10
 
11
11
  def get_vm_by_uuid(connection, machine)
@@ -13,16 +13,18 @@ module VagrantPlugins
13
13
  end
14
14
 
15
15
  def get_resource_pool(datacenter, machine)
16
- computeResource = get_compute_resource(datacenter, machine)
17
- rp = computeResource.resourcePool
18
- if !(machine.provider_config.resource_pool_name.nil?)
19
- rp = computeResource.resourcePool.find(machine.provider_config.resource_pool_name) or fail Errors::VSphereError, :missing_resource_pool
16
+ compute_resource = get_compute_resource(datacenter, machine)
17
+ rp = compute_resource.resourcePool
18
+ unless machine.provider_config.resource_pool_name.nil?
19
+ rp = compute_resource.resourcePool.find(machine.provider_config.resource_pool_name)
20
+ fail Errors::VSphereError, :missing_resource_pool if rp.nil?
20
21
  end
21
22
  rp
22
23
  end
23
24
 
24
25
  def get_compute_resource(datacenter, machine)
25
- cr = find_clustercompute_or_compute_resource(datacenter, machine.provider_config.compute_resource_name) or fail Errors::VSphereError, :missing_compute_resource
26
+ cr = find_clustercompute_or_compute_resource(datacenter, machine.provider_config.compute_resource_name)
27
+ fail Errors::VSphereError, :missing_compute_resource if cr.nil?
26
28
  cr
27
29
  end
28
30
 
@@ -36,50 +38,52 @@ module VagrantPlugins
36
38
  end
37
39
  return datacenter.hostFolder if es.empty?
38
40
  final = es.pop
39
-
40
- p = es.inject(datacenter.hostFolder) do |f,e|
41
+
42
+ p = es.inject(datacenter.hostFolder) do |f, e|
41
43
  f.find(e, RbVmomi::VIM::Folder) || return
42
44
  end
43
45
 
44
46
  begin
45
- if x = p.find(final, RbVmomi::VIM::ComputeResource)
47
+ if (x = p.find(final, RbVmomi::VIM::ComputeResource))
46
48
  x
47
- elsif x = p.find(final, RbVmomi::VIM::ClusterComputeResource)
49
+ elsif (x = p.find(final, RbVmomi::VIM::ClusterComputeResource))
48
50
  x
49
- else
50
- nil
51
51
  end
52
- rescue Exception => e
53
- # When looking for the ClusterComputeResource there seems to be some parser error in RbVmomi Folder.find, try this instead
54
- x = p.childEntity.find { |x| x.name == final }
55
- if x.is_a? RbVmomi::VIM::ClusterComputeResource or x.is_a? RbVmomi::VIM::ComputeResource
52
+ rescue Exception
53
+ # When looking for the ClusterComputeResource there seems to be some parser error in RbVmomi Folder.find, try this instead
54
+ x = p.childEntity.find { |x2| x2.name == final }
55
+ if x.is_a?(RbVmomi::VIM::ClusterComputeResource) || x.is_a?(RbVmomi::VIM::ComputeResource)
56
56
  x
57
57
  else
58
- puts "ex unknown type " + x.to_json
58
+ puts 'ex unknown type ' + x.to_json
59
59
  nil
60
60
  end
61
61
  end
62
-
63
62
  end
64
63
 
65
64
  def get_customization_spec_info_by_name(connection, machine)
66
65
  name = machine.provider_config.customization_spec_name
67
66
  return if name.nil? || name.empty?
68
67
 
69
- manager = connection.serviceContent.customizationSpecManager or fail Errors::VSphereError, :null_configuration_spec_manager if manager.nil?
70
- spec = manager.GetCustomizationSpec(:name => name) or fail Errors::VSphereError, :missing_configuration_spec if spec.nil?
68
+ manager = connection.serviceContent.customizationSpecManager
69
+ fail Errors::VSphereError, :null_configuration_spec_manager if manager.nil?
70
+
71
+ spec = manager.GetCustomizationSpec(name: name)
72
+ fail Errors::VSphereError, :missing_configuration_spec if spec.nil?
73
+
74
+ spec
71
75
  end
72
76
 
73
77
  def get_datastore(datacenter, machine)
74
78
  name = machine.provider_config.data_store_name
75
79
  return if name.nil? || name.empty?
76
80
 
77
- # find_datastore uses folder datastore that only lists Datastore and not StoragePod, if not found also try datastoreFolder which contains StoragePod(s)
78
- datacenter.find_datastore name or datacenter.datastoreFolder.traverse name or fail Errors::VSphereError, :missing_datastore
81
+ # find_datastore uses folder datastore that only lists Datastore and not StoragePod, if not found also try datastoreFolder which contains StoragePod(s)
82
+ datacenter.find_datastore(name) || datacenter.datastoreFolder.traverse(name) || fail(Errors::VSphereError, :missing_datastore)
79
83
  end
80
84
 
81
85
  def get_network_by_name(dc, name)
82
- dc.network.find { |f| f.name == name } or fail Errors::VSphereError, :missing_vlan
86
+ dc.network.find { |f| f.name == name } || fail(Errors::VSphereError, :missing_vlan)
83
87
  end
84
88
  end
85
89
  end
@@ -3,7 +3,6 @@ require 'rbvmomi'
3
3
  module VagrantPlugins
4
4
  module VSphere
5
5
  module Util
6
-
7
6
  module VmState
8
7
  POWERED_ON = 'poweredOn'
9
8
  POWERED_OFF = 'poweredOff'
@@ -37,4 +36,4 @@ module VagrantPlugins
37
36
  end
38
37
  end
39
38
  end
40
- end
39
+ end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module VSphere
3
- VERSION = '0.19.0'
3
+ VERSION = '0.19.1'
4
4
  end
5
5
  end
@@ -15,4 +15,4 @@ module VagrantPlugins
15
15
  @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
16
16
  end
17
17
  end
18
- end
18
+ end
data/spec/action_spec.rb CHANGED
@@ -56,6 +56,7 @@ describe VagrantPlugins::VSphere::Action do
56
56
  end
57
57
 
58
58
  it 'should power off the VM' do
59
+ @machine.state.stub(:id).and_return(:running)
59
60
  VagrantPlugins::VSphere::Action::PowerOff.any_instance.should_receive(:call)
60
61
 
61
62
  run_destroy
data/spec/clone_spec.rb CHANGED
@@ -9,26 +9,26 @@ describe VagrantPlugins::VSphere::Action::Clone do
9
9
 
10
10
  it "should create a CloneVM task with template's parent" do
11
11
  call
12
- expect(@template).to have_received(:CloneVM_Task).with({
13
- :folder => @data_center,
14
- :name => NAME,
15
- :spec => {:location => {:pool => @child_resource_pool},
16
- :config => RbVmomi::VIM.VirtualMachineConfigSpec }
17
- })
12
+ expect(@template).to have_received(:CloneVM_Task).with(
13
+ folder: @data_center,
14
+ name: NAME,
15
+ spec: { location: { pool: @child_resource_pool },
16
+ config: RbVmomi::VIM.VirtualMachineConfigSpec }
17
+ )
18
18
  end
19
19
 
20
20
  it 'should create a CloneVM task with custom folder when given vm base path' do
21
21
  custom_base_folder = double(CUSTOM_VM_FOLDER,
22
- :pretty_path => "#{@data_center.pretty_path}/#{CUSTOM_VM_FOLDER}")
22
+ pretty_path: "#{@data_center.pretty_path}/#{CUSTOM_VM_FOLDER}")
23
23
  @machine.provider_config.stub(:vm_base_path).and_return(CUSTOM_VM_FOLDER)
24
24
  @data_center.vmFolder.stub(:traverse).with(CUSTOM_VM_FOLDER, RbVmomi::VIM::Folder, true).and_return(custom_base_folder)
25
25
  call
26
- expect(@template).to have_received(:CloneVM_Task).with({
27
- :folder => custom_base_folder,
28
- :name => NAME,
29
- :spec => {:location => {:pool => @child_resource_pool},
30
- :config => RbVmomi::VIM.VirtualMachineConfigSpec }
31
- })
26
+ expect(@template).to have_received(:CloneVM_Task).with(
27
+ folder: custom_base_folder,
28
+ name: NAME,
29
+ spec: { location: { pool: @child_resource_pool },
30
+ config: RbVmomi::VIM.VirtualMachineConfigSpec }
31
+ )
32
32
  end
33
33
 
34
34
  it 'should set the machine id to be the new UUID' do
@@ -43,46 +43,44 @@ describe VagrantPlugins::VSphere::Action::Clone do
43
43
 
44
44
  it 'should create a CloneVM spec with configured vlan' do
45
45
  @machine.provider_config.stub(:vlan).and_return('vlan')
46
- network = double('network', :name => 'vlan')
46
+ network = double('network', name: 'vlan')
47
47
  network.stub(:config).and_raise(StandardError)
48
48
  @data_center.stub(:network).and_return([network])
49
49
  call
50
50
 
51
- expected_config = RbVmomi::VIM.VirtualMachineConfigSpec(:deviceChange => Array.new)
52
- expected_dev_spec = RbVmomi::VIM.VirtualDeviceConfigSpec(:device => @device, :operation => "edit")
51
+ expected_config = RbVmomi::VIM.VirtualMachineConfigSpec(deviceChange: Array.new)
52
+ expected_dev_spec = RbVmomi::VIM.VirtualDeviceConfigSpec(device: @device, operation: 'edit')
53
53
  expected_config[:deviceChange].push expected_dev_spec
54
54
 
55
- expect(@template).to have_received(:CloneVM_Task).with({
56
- :folder => @data_center,
57
- :name => NAME,
58
- :spec => {:location =>
59
- {:pool => @child_resource_pool},
60
- :config => expected_config
55
+ expect(@template).to have_received(:CloneVM_Task).with(
56
+ folder: @data_center,
57
+ name: NAME,
58
+ spec: { location: { pool: @child_resource_pool },
59
+ config: expected_config
61
60
  }
62
- })
61
+ )
63
62
  end
64
63
 
65
64
  it 'should create a CloneVM spec with configured memory_mb' do
66
65
  @machine.provider_config.stub(:memory_mb).and_return(2048)
67
66
  call
68
- expect(@template).to have_received(:CloneVM_Task).with({
69
- :folder => @data_center,
70
- :name => NAME,
71
- :spec => {:location => {:pool => @child_resource_pool},
72
- :config => RbVmomi::VIM.VirtualMachineConfigSpec(:memoryMB => 2048) },
73
- })
67
+ expect(@template).to have_received(:CloneVM_Task).with(
68
+ folder: @data_center,
69
+ name: NAME,
70
+ spec: { location: { pool: @child_resource_pool },
71
+ config: RbVmomi::VIM.VirtualMachineConfigSpec(memoryMB: 2048) }
72
+ )
74
73
  end
75
74
 
76
-
77
75
  it 'should create a CloneVM spec with configured number of cpus' do
78
76
  @machine.provider_config.stub(:cpu_count).and_return(4)
79
77
  call
80
- expect(@template).to have_received(:CloneVM_Task).with({
81
- :folder => @data_center,
82
- :name => NAME,
83
- :spec => {:location => {:pool => @child_resource_pool},
84
- :config => RbVmomi::VIM.VirtualMachineConfigSpec(:numCPUs => 4) },
85
- })
78
+ expect(@template).to have_received(:CloneVM_Task).with(
79
+ folder: @data_center,
80
+ name: NAME,
81
+ spec: { location: { pool: @child_resource_pool },
82
+ config: RbVmomi::VIM.VirtualMachineConfigSpec(numCPUs: 4) }
83
+ )
86
84
  end
87
85
 
88
86
  it 'should set static IP when given config spec' do
@@ -94,11 +92,11 @@ describe VagrantPlugins::VSphere::Action::Clone do
94
92
  it 'should use root resource pool when cloning from template and no resource pool specified' do
95
93
  @machine.provider_config.stub(:resource_pool_name).and_return(nil)
96
94
  call
97
- expect(@template).to have_received(:CloneVM_Task).with({
98
- :folder => @data_center,
99
- :name => NAME,
100
- :spec => {:location => {:pool => @root_resource_pool },
101
- :config => RbVmomi::VIM.VirtualMachineConfigSpec }
102
- })
95
+ expect(@template).to have_received(:CloneVM_Task).with(
96
+ folder: @data_center,
97
+ name: NAME,
98
+ spec: { location: { pool: @root_resource_pool },
99
+ config: RbVmomi::VIM.VirtualMachineConfigSpec }
100
+ )
103
101
  end
104
102
  end