wh-vagrant-vsphere 1.5.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.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.bumpversion.cfg +11 -0
  3. data/.gitignore +8 -0
  4. data/.rubocop.yml +13 -0
  5. data/.rubocop_todo.yml +80 -0
  6. data/.travis.yml +11 -0
  7. data/CHANGELOG.md +244 -0
  8. data/DEVELOPMENT.md +67 -0
  9. data/Gemfile +16 -0
  10. data/LICENSE.txt +24 -0
  11. data/README.md +310 -0
  12. data/Rakefile +20 -0
  13. data/example_box/metadata.json +3 -0
  14. data/lib/vSphere/action.rb +194 -0
  15. data/lib/vSphere/action/clone.rb +244 -0
  16. data/lib/vSphere/action/close_vsphere.rb +22 -0
  17. data/lib/vSphere/action/connect_vsphere.rb +29 -0
  18. data/lib/vSphere/action/destroy.rb +41 -0
  19. data/lib/vSphere/action/get_ssh_info.rb +37 -0
  20. data/lib/vSphere/action/get_state.rb +41 -0
  21. data/lib/vSphere/action/is_created.rb +16 -0
  22. data/lib/vSphere/action/is_running.rb +20 -0
  23. data/lib/vSphere/action/message_already_created.rb +18 -0
  24. data/lib/vSphere/action/message_not_created.rb +18 -0
  25. data/lib/vSphere/action/message_not_running.rb +18 -0
  26. data/lib/vSphere/action/power_off.rb +40 -0
  27. data/lib/vSphere/action/power_on.rb +33 -0
  28. data/lib/vSphere/cap/public_address.rb +15 -0
  29. data/lib/vSphere/config.rb +60 -0
  30. data/lib/vSphere/errors.rb +11 -0
  31. data/lib/vSphere/plugin.rb +44 -0
  32. data/lib/vSphere/provider.rb +39 -0
  33. data/lib/vSphere/util/machine_helpers.rb +20 -0
  34. data/lib/vSphere/util/vim_helpers.rb +91 -0
  35. data/lib/vSphere/util/vm_helpers.rb +39 -0
  36. data/lib/vSphere/version.rb +5 -0
  37. data/lib/vagrant-vsphere.rb +18 -0
  38. data/locales/en.yml +68 -0
  39. data/spec/action_spec.rb +162 -0
  40. data/spec/clone_spec.rb +102 -0
  41. data/spec/connect_vsphere_spec.rb +26 -0
  42. data/spec/destroy_spec.rb +31 -0
  43. data/spec/get_ssh_info_spec.rb +31 -0
  44. data/spec/get_state_spec.rb +55 -0
  45. data/spec/is_created_spec.rb +29 -0
  46. data/spec/power_off_spec.rb +35 -0
  47. data/spec/spec_helper.rb +146 -0
  48. data/vSphere.gemspec +30 -0
  49. data/vsphere_screenshot.png +0 -0
  50. metadata +231 -0
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'vSphere/util/vim_helpers'
3
+
4
+ describe VagrantPlugins::VSphere::Action::GetState do
5
+ before :each do
6
+ @env[:vSphere_connection] = @vim
7
+ end
8
+
9
+ it 'should set state id to not created if machine ID is not set' do
10
+ call
11
+
12
+ expect(@env[:machine_state_id]).to be :not_created
13
+ end
14
+
15
+ it 'should set state id to not created if VM is not found' do
16
+ @env[:machine].stub(:id).and_return(MISSING_UUID)
17
+
18
+ call
19
+
20
+ expect(@env[:machine_state_id]).to be :not_created
21
+ end
22
+
23
+ it 'should set state id to running if machine is powered on' do
24
+ @env[:machine].stub(:id).and_return(EXISTING_UUID)
25
+ @vm.runtime.stub(:powerState).and_return(VagrantPlugins::VSphere::Util::VmState::POWERED_ON)
26
+
27
+ call
28
+
29
+ expect(@env[:machine_state_id]).to be :running
30
+ end
31
+
32
+ it 'should set state id to powered off if machine is powered off' do
33
+ @env[:machine].stub(:id).and_return(EXISTING_UUID)
34
+ @vm.runtime.stub(:powerState).and_return(VagrantPlugins::VSphere::Util::VmState::POWERED_OFF)
35
+
36
+ call
37
+
38
+ expect(@env[:machine_state_id]).to be :poweroff
39
+ end
40
+
41
+ it 'should set state id to powered off if machine is suspended' do
42
+ @env[:machine].stub(:id).and_return(EXISTING_UUID)
43
+ @vm.runtime.stub(:powerState).and_return(VagrantPlugins::VSphere::Util::VmState::SUSPENDED)
44
+
45
+ call
46
+
47
+ expect(@env[:machine_state_id]).to be :poweroff
48
+ end
49
+
50
+ it 'should call the next item in the middleware stack' do
51
+ call
52
+
53
+ expect(@app).to have_received :call
54
+ end
55
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'vSphere/action/is_created'
3
+
4
+ describe VagrantPlugins::VSphere::Action::IsCreated do
5
+ before :each do
6
+ @env[:vSphere_connection] = @vim
7
+ end
8
+
9
+ it 'should set result to false if the VM does not exist' do
10
+ @env[:machine].state.stub(:id).and_return(:running)
11
+
12
+ call
13
+
14
+ expect(@env[:result]).to be true
15
+ end
16
+
17
+ it 'should set result to false if the VM does not exist' do
18
+ @env[:machine].state.stub(:id).and_return(:not_created)
19
+
20
+ call
21
+
22
+ expect(@env[:result]).to be false
23
+ end
24
+
25
+ it 'should call the next item in the middleware stack' do
26
+ call
27
+ expect(@app).to have_received :call
28
+ end
29
+ end
@@ -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
@@ -0,0 +1,146 @@
1
+ require 'rbvmomi'
2
+ require 'pathname'
3
+ require 'vSphere/errors'
4
+ require 'vSphere/action'
5
+ require 'vSphere/action/connect_vsphere'
6
+ require 'vSphere/action/close_vsphere'
7
+ require 'vSphere/action/is_created'
8
+ require 'vSphere/action/get_state'
9
+ require 'vSphere/action/get_ssh_info'
10
+ require 'vSphere/action/clone'
11
+ require 'vSphere/action/message_already_created'
12
+ require 'vSphere/action/message_not_created'
13
+ require 'vSphere/action/destroy'
14
+ require 'vSphere/action/power_off'
15
+
16
+ VIM = RbVmomi::VIM
17
+
18
+ EXISTING_UUID = 'existing_uuid'
19
+ MISSING_UUID = 'missing_uuid'
20
+ NEW_UUID = 'new_uuid'
21
+ TEMPLATE = 'template'
22
+ NAME = 'vm'
23
+ IP_ADDRESS = '127.0.0.1'
24
+
25
+ RSpec.configure do |config|
26
+ # removes deprecation warnings.
27
+ # http://stackoverflow.com/questions/20275510/how-to-avoid-deprecation-warning-for-stub-chain-in-rspec-3-0/20296359#20296359
28
+ config.mock_with :rspec do |c|
29
+ c.syntax = [:should, :expect]
30
+ end
31
+
32
+ config.before(:each) do
33
+ def call
34
+ described_class.new(@app, @env).call(@env)
35
+ end
36
+
37
+ provider_config = double(
38
+ host: 'testhost.com',
39
+ user: 'testuser',
40
+ password: 'testpassword',
41
+ data_center_name: nil,
42
+ compute_resource_name: 'testcomputeresource',
43
+ resource_pool_name: 'testresourcepool',
44
+ vm_base_path: nil,
45
+ template_name: TEMPLATE,
46
+ name: NAME,
47
+ insecure: true,
48
+ validate: [],
49
+ customization_spec_name: nil,
50
+ data_store_name: nil,
51
+ clone_from_vm: nil,
52
+ linked_clone: nil,
53
+ proxy_host: nil,
54
+ proxy_port: nil,
55
+ vlan: nil,
56
+ memory_mb: nil,
57
+ cpu_count: nil,
58
+ mac: nil,
59
+ addressType: nil,
60
+ cpu_reservation: nil,
61
+ mem_reservation: nil,
62
+ custom_attributes: {})
63
+ vm_config = double(
64
+ vm: double('config_vm',
65
+ box: nil,
66
+ synced_folders: [],
67
+ provisioners: [],
68
+ hostname: nil,
69
+ communicator: nil,
70
+ networks: [[:private_network, { ip: '0.0.0.0' }]],
71
+ graceful_halt_timeout: 0.1),
72
+ validate: []
73
+ )
74
+ @app = double 'app', call: true
75
+ @machine = double 'machine',
76
+ :provider_config => provider_config,
77
+ :config => vm_config,
78
+ :state => double('state', id: nil),
79
+ :communicate => double('communicator', :ready? => true),
80
+ :ssh_info => {},
81
+ :data_dir => Pathname.new(''),
82
+ :id => nil,
83
+ :id= => nil,
84
+ :guest => double('guest', capability: nil)
85
+
86
+ @env = {
87
+ machine: @machine,
88
+ ui: double('ui', info: nil, output: nil)
89
+ }
90
+
91
+ @vm = double('vm',
92
+ runtime: double('runtime', powerState: nil),
93
+ guest: double('guest', ipAddress: IP_ADDRESS),
94
+ Destroy_Task: double('result', wait_for_completion: nil),
95
+ PowerOffVM_Task: double('result', wait_for_completion: nil),
96
+ PowerOnVM_Task: double('result', wait_for_completion: nil))
97
+
98
+ vm_folder = double('vm_folder')
99
+ vm_folder.stub(:findByUuid).with(EXISTING_UUID).and_return(@vm)
100
+ vm_folder.stub(:findByUuid).with(MISSING_UUID).and_return(nil)
101
+ vm_folder.stub(:findByUuid).with(nil).and_return(nil)
102
+
103
+ @child_resource_pool = double('testresourcepool')
104
+ @root_resource_pool = double('pools', find: @child_resource_pool)
105
+
106
+ @compute_resource = RbVmomi::VIM::ComputeResource.new(nil, nil)
107
+ @compute_resource.stub(:resourcePool).and_return(@root_resource_pool)
108
+
109
+ @host_folder = double('hostFolder', childEntity: double('childEntity', find: @compute_resource))
110
+
111
+ @data_center = double('data_center',
112
+ vmFolder: vm_folder,
113
+ pretty_path: "data_center/#{vm_folder}",
114
+ find_compute_resource: @compute_resource,
115
+ hostFolder: @host_folder)
116
+
117
+ @device = RbVmomi::VIM::VirtualEthernetCard.new
118
+ @device.stub(:backing).and_return(RbVmomi::VIM::VirtualEthernetCardNetworkBackingInfo.new)
119
+
120
+ @virtual_hardware = double('virtual_hardware',
121
+ device: [@device])
122
+ @template_config = double('template_config',
123
+ hardware: @virtual_hardware)
124
+
125
+ @template = double('template_vm',
126
+ parent: @data_center,
127
+ pretty_path: "#{@data_center.pretty_path}/template_vm",
128
+ CloneVM_Task: double('result',
129
+ wait_for_completion: double('new_vm', config: double('config', uuid: NEW_UUID))),
130
+ config: @template_config)
131
+
132
+ @data_center.stub(:find_vm).with(TEMPLATE).and_return(@template)
133
+
134
+ service_instance = double 'service_instance', find_datacenter: @data_center
135
+ @ip = double 'ip', :ipAddress= => nil
136
+ @customization_spec = double 'customization spec', nicSettingMap: [double('nic setting', adapter: double('adapter', ip: @ip))]
137
+ @customization_spec.stub(:clone).and_return(@customization_spec)
138
+ customization_spec_manager = double 'customization spec manager', GetCustomizationSpec: double('spec info', spec: @customization_spec)
139
+ service_content = double 'service content', customizationSpecManager: customization_spec_manager
140
+ @vim = double 'vim', serviceInstance: service_instance, close: true, serviceContent: service_content
141
+
142
+ VIM.stub(:connect).and_return(@vim)
143
+ VIM.stub(:VirtualMachineRelocateSpec).and_return({})
144
+ VIM.stub(:VirtualMachineCloneSpec) { |location, _powerOn, _template| { location: location[:location] } }
145
+ end
146
+ end
data/vSphere.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+ require 'vSphere/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'wh-vagrant-vsphere'
6
+ s.version = VagrantPlugins::VSphere::VERSION
7
+ s.authors = ['Andrew Grauch']
8
+ s.email = ['andrew.grauch@nsidc.org']
9
+ s.homepage = ''
10
+ s.license = 'MIT'
11
+ s.summary = 'VMWare vSphere provider'
12
+ s.description = 'Enables Vagrant to manage machines with VMWare vSphere.'
13
+
14
+ # force the use of Nokogiri 1.5.x to prevent conflicts with older versions of zlib
15
+ s.add_dependency 'nokogiri', '~>1.5'
16
+ # force the use of rbvmomi 1.8.2 to work around concurrency errors: https://github.com/nsidc/vagrant-vsphere/issues/139
17
+ s.add_dependency 'rbvmomi', '~> 1.8', '>= 1.8.2'
18
+ s.add_dependency 'i18n', '~> 0.6', '>= 0.6.4'
19
+
20
+ s.add_development_dependency 'rake'
21
+ s.add_development_dependency 'rspec-core'
22
+ s.add_development_dependency 'rspec-expectations'
23
+ s.add_development_dependency 'rspec-mocks'
24
+ s.add_development_dependency 'rubocop', '~> 0.32', '>= 0.32.1'
25
+
26
+ s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
27
+ s.executables = s.files.grep(/^bin\//) { |f| File.basename(f) }
28
+ s.test_files = s.files.grep(/^(test|spec|features)\//)
29
+ s.require_path = 'lib'
30
+ end
Binary file
metadata ADDED
@@ -0,0 +1,231 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wh-vagrant-vsphere
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Grauch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rbvmomi
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.8.2
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.8'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.8.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: i18n
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.6'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.6.4
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '0.6'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 0.6.4
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec-core
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rspec-expectations
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: rspec-mocks
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: rubocop
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '0.32'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 0.32.1
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '0.32'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 0.32.1
143
+ description: Enables Vagrant to manage machines with VMWare vSphere.
144
+ email:
145
+ - andrew.grauch@nsidc.org
146
+ executables: []
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - ".bumpversion.cfg"
151
+ - ".gitignore"
152
+ - ".rubocop.yml"
153
+ - ".rubocop_todo.yml"
154
+ - ".travis.yml"
155
+ - CHANGELOG.md
156
+ - DEVELOPMENT.md
157
+ - Gemfile
158
+ - LICENSE.txt
159
+ - README.md
160
+ - Rakefile
161
+ - example_box/metadata.json
162
+ - lib/vSphere/action.rb
163
+ - lib/vSphere/action/clone.rb
164
+ - lib/vSphere/action/close_vsphere.rb
165
+ - lib/vSphere/action/connect_vsphere.rb
166
+ - lib/vSphere/action/destroy.rb
167
+ - lib/vSphere/action/get_ssh_info.rb
168
+ - lib/vSphere/action/get_state.rb
169
+ - lib/vSphere/action/is_created.rb
170
+ - lib/vSphere/action/is_running.rb
171
+ - lib/vSphere/action/message_already_created.rb
172
+ - lib/vSphere/action/message_not_created.rb
173
+ - lib/vSphere/action/message_not_running.rb
174
+ - lib/vSphere/action/power_off.rb
175
+ - lib/vSphere/action/power_on.rb
176
+ - lib/vSphere/cap/public_address.rb
177
+ - lib/vSphere/config.rb
178
+ - lib/vSphere/errors.rb
179
+ - lib/vSphere/plugin.rb
180
+ - lib/vSphere/provider.rb
181
+ - lib/vSphere/util/machine_helpers.rb
182
+ - lib/vSphere/util/vim_helpers.rb
183
+ - lib/vSphere/util/vm_helpers.rb
184
+ - lib/vSphere/version.rb
185
+ - lib/vagrant-vsphere.rb
186
+ - locales/en.yml
187
+ - spec/action_spec.rb
188
+ - spec/clone_spec.rb
189
+ - spec/connect_vsphere_spec.rb
190
+ - spec/destroy_spec.rb
191
+ - spec/get_ssh_info_spec.rb
192
+ - spec/get_state_spec.rb
193
+ - spec/is_created_spec.rb
194
+ - spec/power_off_spec.rb
195
+ - spec/spec_helper.rb
196
+ - vSphere.gemspec
197
+ - vsphere_screenshot.png
198
+ homepage: ''
199
+ licenses:
200
+ - MIT
201
+ metadata: {}
202
+ post_install_message:
203
+ rdoc_options: []
204
+ require_paths:
205
+ - lib
206
+ required_ruby_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ requirements: []
217
+ rubyforge_project:
218
+ rubygems_version: 2.4.8
219
+ signing_key:
220
+ specification_version: 4
221
+ summary: VMWare vSphere provider
222
+ test_files:
223
+ - spec/action_spec.rb
224
+ - spec/clone_spec.rb
225
+ - spec/connect_vsphere_spec.rb
226
+ - spec/destroy_spec.rb
227
+ - spec/get_ssh_info_spec.rb
228
+ - spec/get_state_spec.rb
229
+ - spec/is_created_spec.rb
230
+ - spec/power_off_spec.rb
231
+ - spec/spec_helper.rb