vagrant-vsphere 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +10 -0
  3. data/LICENSE.txt +24 -0
  4. data/README.md +151 -0
  5. data/Rakefile +17 -0
  6. data/example_box/metadata.json +3 -0
  7. data/lib/vSphere/action/clone.rb +83 -0
  8. data/lib/vSphere/action/close_vsphere.rb +24 -0
  9. data/lib/vSphere/action/connect_vsphere.rb +25 -0
  10. data/lib/vSphere/action/destroy.rb +38 -0
  11. data/lib/vSphere/action/get_ssh_info.rb +38 -0
  12. data/lib/vSphere/action/get_state.rb +46 -0
  13. data/lib/vSphere/action/is_created.rb +16 -0
  14. data/lib/vSphere/action/is_running.rb +20 -0
  15. data/lib/vSphere/action/message_already_created.rb +18 -0
  16. data/lib/vSphere/action/message_not_created.rb +18 -0
  17. data/lib/vSphere/action/message_not_running.rb +18 -0
  18. data/lib/vSphere/action/power_off.rb +28 -0
  19. data/lib/vSphere/action/power_on.rb +31 -0
  20. data/lib/vSphere/action/sync_folders.rb +65 -0
  21. data/lib/vSphere/action.rb +151 -0
  22. data/lib/vSphere/config.rb +37 -0
  23. data/lib/vSphere/errors.rb +11 -0
  24. data/lib/vSphere/plugin.rb +30 -0
  25. data/lib/vSphere/provider.rb +39 -0
  26. data/lib/vSphere/util/machine_helpers.rb +15 -0
  27. data/lib/vSphere/util/vim_helpers.rb +37 -0
  28. data/lib/vSphere/version.rb +5 -0
  29. data/lib/vagrant-vsphere.rb +18 -0
  30. data/locales/en.yml +61 -0
  31. data/spec/action_spec.rb +116 -0
  32. data/spec/clone_spec.rb +32 -0
  33. data/spec/connect_vsphere_spec.rb +24 -0
  34. data/spec/destroy_spec.rb +31 -0
  35. data/spec/get_ssh_info_spec.rb +31 -0
  36. data/spec/get_state_spec.rb +54 -0
  37. data/spec/is_created_spec.rb +29 -0
  38. data/spec/spec_helper.rb +97 -0
  39. data/vSphere.gemspec +28 -0
  40. metadata +205 -0
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe VagrantPlugins::VSphere::Action::GetSshInfo do
4
+ before :each do
5
+ @env[:vSphere_connection] = @vim
6
+ end
7
+
8
+ it 'should set the ssh info to nil if machine ID is not set' do
9
+ call
10
+
11
+ @env.has_key?(:machine_ssh_info).should be true
12
+ @env[:machine_ssh_info].should be nil
13
+ end
14
+
15
+ it 'should set the ssh info to nil for a VM that does not exist' do
16
+ @env[:machine].stub(:id).and_return(MISSING_UUID)
17
+
18
+ call
19
+
20
+ @env.has_key?(:machine_ssh_info).should be true
21
+ @env[:machine_ssh_info].should be nil
22
+ end
23
+
24
+ it 'should set the ssh info host to the IP an existing VM' do
25
+ @env[:machine].stub(:id).and_return(EXISTING_UUID)
26
+
27
+ call
28
+
29
+ @env[:machine_ssh_info][:host].should be IP_ADDRESS
30
+ end
31
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe VagrantPlugins::VSphere::Action::GetState do
4
+ before :each do
5
+ @env[:vSphere_connection] = @vim
6
+ end
7
+
8
+ it 'should set state id to not created if machine ID is not set' do
9
+ call
10
+
11
+ @env[:machine_state_id].should be :not_created
12
+ end
13
+
14
+ it 'should set state id to not created if VM is not found' do
15
+ @env[:machine].stub(:id).and_return(MISSING_UUID)
16
+
17
+ call
18
+
19
+ @env[:machine_state_id].should be :not_created
20
+ end
21
+
22
+ it 'should set state id to running if machine is powered on' do
23
+ @env[:machine].stub(:id).and_return(EXISTING_UUID)
24
+ @vm.runtime.stub(:powerState).and_return(described_class::POWERED_ON)
25
+
26
+ call
27
+
28
+ @env[:machine_state_id].should be :running
29
+ end
30
+
31
+ it 'should set state id to powered off if machine is powered off' do
32
+ @env[:machine].stub(:id).and_return(EXISTING_UUID)
33
+ @vm.runtime.stub(:powerState).and_return(described_class::POWERED_OFF)
34
+
35
+ call
36
+
37
+ @env[:machine_state_id].should be :poweroff
38
+ end
39
+
40
+ it 'should set state id to powered off if machine is suspended' do
41
+ @env[:machine].stub(:id).and_return(EXISTING_UUID)
42
+ @vm.runtime.stub(:powerState).and_return(described_class::SUSPENDED)
43
+
44
+ call
45
+
46
+ @env[:machine_state_id].should be :poweroff
47
+ end
48
+
49
+ it 'should call the next item in the middleware stack' do
50
+ call
51
+
52
+ @app.should have_received :call
53
+ end
54
+ 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
+ @env[:result].should 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
+ @env[:result].should be false
23
+ end
24
+
25
+ it 'should call the next item in the middleware stack' do
26
+ call
27
+ @app.should have_received :call
28
+ end
29
+ end
@@ -0,0 +1,97 @@
1
+ require 'rbvmomi'
2
+ require 'vSphere/errors'
3
+ require 'vSphere/action'
4
+ require 'vSphere/action/connect_vsphere'
5
+ require 'vSphere/action/close_vsphere'
6
+ require 'vSphere/action/is_created'
7
+ require 'vSphere/action/get_state'
8
+ require 'vSphere/action/get_ssh_info'
9
+ require 'vSphere/action/clone'
10
+ require 'vSphere/action/message_already_created'
11
+ require 'vSphere/action/message_not_created'
12
+ require 'vSphere/action/destroy'
13
+ require 'vSphere/action/power_off'
14
+
15
+ VIM = RbVmomi::VIM
16
+
17
+ EXISTING_UUID = 'existing_uuid'
18
+ MISSING_UUID = 'missing_uuid'
19
+ NEW_UUID = 'new_uuid'
20
+ TEMPLATE = 'template'
21
+ NAME = 'vm'
22
+ IP_ADDRESS = '127.0.0.1'
23
+
24
+ RSpec.configure do |config|
25
+ config.before(:each) do
26
+ def call
27
+ described_class.new(@app, @env).call(@env)
28
+ end
29
+
30
+ provider_config = double(
31
+ :host => 'testhost.com',
32
+ :user => 'testuser',
33
+ :password => 'testpassword',
34
+ :data_center_name => nil,
35
+ :compute_resource_name => 'testcomputeresource',
36
+ :resource_pool_name => 'testresourcepool',
37
+ :template_name => TEMPLATE,
38
+ :name => NAME,
39
+ :insecure => true,
40
+ :validate => [],
41
+ :customization_spec_name => nil,
42
+ :data_store_name => nil,
43
+ :clone_from_vm => nil)
44
+ vm_config = double(
45
+ :vm => double('config_vm', :synced_folders => [], :provisioners => [], :networks => [[:private_network, {:ip => '0.0.0.0'}]]),
46
+ :validate => []
47
+ )
48
+ @app = double 'app', :call => true
49
+ @machine = double 'machine',
50
+ :provider_config => provider_config,
51
+ :config => vm_config,
52
+ :state => double('state', :id => nil),
53
+ :communicate => double('communicator', :ready? => true),
54
+ :ssh_info => {},
55
+ :id => nil,
56
+ :id= => nil
57
+ @env = {
58
+ :machine => @machine,
59
+ :ui => double('ui', :info => nil)
60
+ }
61
+
62
+ @vm = double('vm',
63
+ :runtime => double('runtime', :powerState => nil),
64
+ :guest => double('guest', :ipAddress => IP_ADDRESS),
65
+ :Destroy_Task => double('result', :wait_for_completion => nil),
66
+ :PowerOffVM_Task => double('result', :wait_for_completion => nil),
67
+ :PowerOnVM_Task => double('result', :wait_for_completion => nil))
68
+
69
+ vm_folder = double('vm_folder')
70
+ vm_folder.stub(:findByUuid).with(EXISTING_UUID).and_return(@vm)
71
+ vm_folder.stub(:findByUuid).with(MISSING_UUID).and_return(nil)
72
+ vm_folder.stub(:findByUuid).with(nil).and_return(nil)
73
+
74
+ @data_center = double('data_center',
75
+ :vmFolder => vm_folder,
76
+ :find_compute_resource => double('compute resource', :resourcePool => double('pools', :find => {})))
77
+
78
+ @template = double('template_vm',
79
+ :parent => @data_center,
80
+ :CloneVM_Task => double('result',
81
+ :wait_for_completion => double('new_vm', :config => double('config', :uuid => NEW_UUID))))
82
+
83
+ @data_center.stub(:find_vm).with(TEMPLATE).and_return(@template)
84
+
85
+ service_instance = double 'service_instance', :find_datacenter => @data_center
86
+ @ip = double 'ip', :ipAddress= => nil
87
+ customization_spec = double 'customization spec', :nicSettingMap => [double('nic setting', :adapter => double('adapter', :ip => @ip))]
88
+ customization_spec.stub(:clone).and_return(customization_spec)
89
+ customization_spec_manager = double 'customization spec manager', :GetCustomizationSpec => double('spec info', :spec => customization_spec)
90
+ service_content = double 'service content', :customizationSpecManager => customization_spec_manager
91
+ @vim = double 'vim', :serviceInstance => service_instance, :close => true, :serviceContent => service_content
92
+
93
+ VIM.stub(:connect).and_return(@vim)
94
+ VIM.stub(:VirtualMachineRelocateSpec).and_return({})
95
+ VIM.stub(:VirtualMachineCloneSpec).and_return({})
96
+ end
97
+ end
data/vSphere.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+ require 'vSphere/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = '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.10 to prevent conflicts with older versions of zlib
15
+ s.add_dependency 'nokogiri', '1.5.10'
16
+ s.add_dependency 'rbvmomi'
17
+ s.add_dependency 'i18n', '~> 0.6.4'
18
+
19
+ s.add_development_dependency 'rake'
20
+ s.add_development_dependency 'rspec-core'
21
+ s.add_development_dependency 'rspec-expectations'
22
+ s.add_development_dependency 'rspec-mocks'
23
+
24
+ s.files = `git ls-files`.split($/)
25
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
27
+ s.require_path = 'lib'
28
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-vsphere
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Grauch
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.5.10
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.5.10
30
+ - !ruby/object:Gem::Dependency
31
+ name: rbvmomi
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: i18n
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.6.4
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.6.4
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec-core
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec-expectations
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
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
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rspec-mocks
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Enables Vagrant to manage machines with VMWare vSphere.
127
+ email:
128
+ - andrew.grauch@nsidc.org
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - Gemfile
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - example_box/metadata.json
139
+ - lib/vSphere/action.rb
140
+ - lib/vSphere/action/clone.rb
141
+ - lib/vSphere/action/close_vsphere.rb
142
+ - lib/vSphere/action/connect_vsphere.rb
143
+ - lib/vSphere/action/destroy.rb
144
+ - lib/vSphere/action/get_ssh_info.rb
145
+ - lib/vSphere/action/get_state.rb
146
+ - lib/vSphere/action/is_created.rb
147
+ - lib/vSphere/action/is_running.rb
148
+ - lib/vSphere/action/message_already_created.rb
149
+ - lib/vSphere/action/message_not_created.rb
150
+ - lib/vSphere/action/message_not_running.rb
151
+ - lib/vSphere/action/power_off.rb
152
+ - lib/vSphere/action/power_on.rb
153
+ - lib/vSphere/action/sync_folders.rb
154
+ - lib/vSphere/config.rb
155
+ - lib/vSphere/errors.rb
156
+ - lib/vSphere/plugin.rb
157
+ - lib/vSphere/provider.rb
158
+ - lib/vSphere/util/machine_helpers.rb
159
+ - lib/vSphere/util/vim_helpers.rb
160
+ - lib/vSphere/version.rb
161
+ - lib/vagrant-vsphere.rb
162
+ - locales/en.yml
163
+ - spec/action_spec.rb
164
+ - spec/clone_spec.rb
165
+ - spec/connect_vsphere_spec.rb
166
+ - spec/destroy_spec.rb
167
+ - spec/get_ssh_info_spec.rb
168
+ - spec/get_state_spec.rb
169
+ - spec/is_created_spec.rb
170
+ - spec/spec_helper.rb
171
+ - vSphere.gemspec
172
+ homepage: ''
173
+ licenses:
174
+ - MIT
175
+ post_install_message:
176
+ rdoc_options: []
177
+ require_paths:
178
+ - lib
179
+ required_ruby_version: !ruby/object:Gem::Requirement
180
+ none: false
181
+ requirements:
182
+ - - ! '>='
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ! '>='
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ requirements: []
192
+ rubyforge_project:
193
+ rubygems_version: 1.8.23
194
+ signing_key:
195
+ specification_version: 3
196
+ summary: VMWare vSphere provider
197
+ test_files:
198
+ - spec/action_spec.rb
199
+ - spec/clone_spec.rb
200
+ - spec/connect_vsphere_spec.rb
201
+ - spec/destroy_spec.rb
202
+ - spec/get_ssh_info_spec.rb
203
+ - spec/get_state_spec.rb
204
+ - spec/is_created_spec.rb
205
+ - spec/spec_helper.rb