djo-vagrant-vsphere 1.6.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.
Files changed (49) 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 +250 -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 +195 -0
  15. data/lib/vSphere/action/clone.rb +239 -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 +16 -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 +28 -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/vim_helpers.rb +91 -0
  34. data/lib/vSphere/util/vm_helpers.rb +39 -0
  35. data/lib/vSphere/version.rb +5 -0
  36. data/lib/vagrant-vsphere.rb +18 -0
  37. data/locales/en.yml +64 -0
  38. data/spec/action_spec.rb +162 -0
  39. data/spec/clone_spec.rb +102 -0
  40. data/spec/connect_vsphere_spec.rb +26 -0
  41. data/spec/destroy_spec.rb +31 -0
  42. data/spec/get_ssh_info_spec.rb +31 -0
  43. data/spec/get_state_spec.rb +55 -0
  44. data/spec/is_created_spec.rb +29 -0
  45. data/spec/power_off_spec.rb +35 -0
  46. data/spec/spec_helper.rb +147 -0
  47. data/vSphere.gemspec +30 -0
  48. data/vsphere_screenshot.png +0 -0
  49. metadata +212 -0
@@ -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,147 @@
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
+ boot_timeout: 1,
72
+ graceful_halt_timeout: 0.1),
73
+ validate: []
74
+ )
75
+ @app = double 'app', call: true
76
+ @machine = double 'machine',
77
+ :provider_config => provider_config,
78
+ :config => vm_config,
79
+ :state => double('state', id: nil),
80
+ :communicate => double('communicator', :wait_for_ready => true, :ready? => true),
81
+ :ssh_info => {},
82
+ :data_dir => Pathname.new(''),
83
+ :id => nil,
84
+ :id= => nil,
85
+ :guest => double('guest', capability: nil)
86
+
87
+ @env = {
88
+ machine: @machine,
89
+ ui: double('ui', info: nil, output: nil)
90
+ }
91
+
92
+ @vm = double('vm',
93
+ runtime: double('runtime', powerState: nil),
94
+ guest: double('guest', ipAddress: IP_ADDRESS),
95
+ Destroy_Task: double('result', wait_for_completion: nil),
96
+ PowerOffVM_Task: double('result', wait_for_completion: nil),
97
+ PowerOnVM_Task: double('result', wait_for_completion: nil))
98
+
99
+ vm_folder = double('vm_folder')
100
+ vm_folder.stub(:findByUuid).with(EXISTING_UUID).and_return(@vm)
101
+ vm_folder.stub(:findByUuid).with(MISSING_UUID).and_return(nil)
102
+ vm_folder.stub(:findByUuid).with(nil).and_return(nil)
103
+
104
+ @child_resource_pool = double('testresourcepool')
105
+ @root_resource_pool = double('pools', find: @child_resource_pool)
106
+
107
+ @compute_resource = RbVmomi::VIM::ComputeResource.new(nil, nil)
108
+ @compute_resource.stub(:resourcePool).and_return(@root_resource_pool)
109
+
110
+ @host_folder = double('hostFolder', childEntity: double('childEntity', find: @compute_resource))
111
+
112
+ @data_center = double('data_center',
113
+ vmFolder: vm_folder,
114
+ pretty_path: "data_center/#{vm_folder}",
115
+ find_compute_resource: @compute_resource,
116
+ hostFolder: @host_folder)
117
+
118
+ @device = RbVmomi::VIM::VirtualEthernetCard.new
119
+ @device.stub(:backing).and_return(RbVmomi::VIM::VirtualEthernetCardNetworkBackingInfo.new)
120
+
121
+ @virtual_hardware = double('virtual_hardware',
122
+ device: [@device])
123
+ @template_config = double('template_config',
124
+ hardware: @virtual_hardware)
125
+
126
+ @template = double('template_vm',
127
+ parent: @data_center,
128
+ pretty_path: "#{@data_center.pretty_path}/template_vm",
129
+ CloneVM_Task: double('result',
130
+ wait_for_completion: double('new_vm', config: double('config', uuid: NEW_UUID))),
131
+ config: @template_config)
132
+
133
+ @data_center.stub(:find_vm).with(TEMPLATE).and_return(@template)
134
+
135
+ service_instance = double 'service_instance', find_datacenter: @data_center
136
+ @ip = double 'ip', :ipAddress= => nil
137
+ @customization_spec = double 'customization spec', nicSettingMap: [double('nic setting', adapter: double('adapter', ip: @ip))]
138
+ @customization_spec.stub(:clone).and_return(@customization_spec)
139
+ customization_spec_manager = double 'customization spec manager', GetCustomizationSpec: double('spec info', spec: @customization_spec)
140
+ service_content = double 'service content', customizationSpecManager: customization_spec_manager
141
+ @vim = double 'vim', serviceInstance: service_instance, close: true, serviceContent: service_content
142
+
143
+ VIM.stub(:connect).and_return(@vim)
144
+ VIM.stub(:VirtualMachineRelocateSpec).and_return({})
145
+ VIM.stub(:VirtualMachineCloneSpec) { |location, _powerOn, _template| { location: location[:location] } }
146
+ end
147
+ 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 = 'djo-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.2'
18
+ s.add_dependency 'i18n', '~> 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.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,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: djo-vagrant-vsphere
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.6.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Grauch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-26 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.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: i18n
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.6.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.6.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-core
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-expectations
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-mocks
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.32.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: 0.32.1
125
+ description: Enables Vagrant to manage machines with VMWare vSphere.
126
+ email:
127
+ - andrew.grauch@nsidc.org
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .bumpversion.cfg
133
+ - .gitignore
134
+ - .rubocop.yml
135
+ - .rubocop_todo.yml
136
+ - .travis.yml
137
+ - CHANGELOG.md
138
+ - DEVELOPMENT.md
139
+ - Gemfile
140
+ - LICENSE.txt
141
+ - README.md
142
+ - Rakefile
143
+ - example_box/metadata.json
144
+ - lib/vSphere/action.rb
145
+ - lib/vSphere/action/clone.rb
146
+ - lib/vSphere/action/close_vsphere.rb
147
+ - lib/vSphere/action/connect_vsphere.rb
148
+ - lib/vSphere/action/destroy.rb
149
+ - lib/vSphere/action/get_ssh_info.rb
150
+ - lib/vSphere/action/get_state.rb
151
+ - lib/vSphere/action/is_created.rb
152
+ - lib/vSphere/action/is_running.rb
153
+ - lib/vSphere/action/message_already_created.rb
154
+ - lib/vSphere/action/message_not_created.rb
155
+ - lib/vSphere/action/message_not_running.rb
156
+ - lib/vSphere/action/power_off.rb
157
+ - lib/vSphere/action/power_on.rb
158
+ - lib/vSphere/cap/public_address.rb
159
+ - lib/vSphere/config.rb
160
+ - lib/vSphere/errors.rb
161
+ - lib/vSphere/plugin.rb
162
+ - lib/vSphere/provider.rb
163
+ - lib/vSphere/util/vim_helpers.rb
164
+ - lib/vSphere/util/vm_helpers.rb
165
+ - lib/vSphere/version.rb
166
+ - lib/vagrant-vsphere.rb
167
+ - locales/en.yml
168
+ - spec/action_spec.rb
169
+ - spec/clone_spec.rb
170
+ - spec/connect_vsphere_spec.rb
171
+ - spec/destroy_spec.rb
172
+ - spec/get_ssh_info_spec.rb
173
+ - spec/get_state_spec.rb
174
+ - spec/is_created_spec.rb
175
+ - spec/power_off_spec.rb
176
+ - spec/spec_helper.rb
177
+ - vSphere.gemspec
178
+ - vsphere_screenshot.png
179
+ homepage: ''
180
+ licenses:
181
+ - MIT
182
+ metadata: {}
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 2.0.14.1
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: VMWare vSphere provider
203
+ test_files:
204
+ - spec/action_spec.rb
205
+ - spec/clone_spec.rb
206
+ - spec/connect_vsphere_spec.rb
207
+ - spec/destroy_spec.rb
208
+ - spec/get_ssh_info_spec.rb
209
+ - spec/get_state_spec.rb
210
+ - spec/is_created_spec.rb
211
+ - spec/power_off_spec.rb
212
+ - spec/spec_helper.rb