vagrant-vsphere 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +24 -0
- data/README.md +151 -0
- data/Rakefile +17 -0
- data/example_box/metadata.json +3 -0
- data/lib/vSphere/action/clone.rb +83 -0
- data/lib/vSphere/action/close_vsphere.rb +24 -0
- data/lib/vSphere/action/connect_vsphere.rb +25 -0
- data/lib/vSphere/action/destroy.rb +38 -0
- data/lib/vSphere/action/get_ssh_info.rb +38 -0
- data/lib/vSphere/action/get_state.rb +46 -0
- data/lib/vSphere/action/is_created.rb +16 -0
- data/lib/vSphere/action/is_running.rb +20 -0
- data/lib/vSphere/action/message_already_created.rb +18 -0
- data/lib/vSphere/action/message_not_created.rb +18 -0
- data/lib/vSphere/action/message_not_running.rb +18 -0
- data/lib/vSphere/action/power_off.rb +28 -0
- data/lib/vSphere/action/power_on.rb +31 -0
- data/lib/vSphere/action/sync_folders.rb +65 -0
- data/lib/vSphere/action.rb +151 -0
- data/lib/vSphere/config.rb +37 -0
- data/lib/vSphere/errors.rb +11 -0
- data/lib/vSphere/plugin.rb +30 -0
- data/lib/vSphere/provider.rb +39 -0
- data/lib/vSphere/util/machine_helpers.rb +15 -0
- data/lib/vSphere/util/vim_helpers.rb +37 -0
- data/lib/vSphere/version.rb +5 -0
- data/lib/vagrant-vsphere.rb +18 -0
- data/locales/en.yml +61 -0
- data/spec/action_spec.rb +116 -0
- data/spec/clone_spec.rb +32 -0
- data/spec/connect_vsphere_spec.rb +24 -0
- data/spec/destroy_spec.rb +31 -0
- data/spec/get_ssh_info_spec.rb +31 -0
- data/spec/get_state_spec.rb +54 -0
- data/spec/is_created_spec.rb +29 -0
- data/spec/spec_helper.rb +97 -0
- data/vSphere.gemspec +28 -0
- metadata +205 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
require "vagrant/util/subprocess"
|
3
|
+
require "vagrant/util/scoped_hash_override"
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module VSphere
|
7
|
+
module Action
|
8
|
+
# This middleware uses `rsync` to sync the folders over to the vSphere instance
|
9
|
+
# Borrowed from the Vagrant AWS gem, see https://github.com/mitchellh/vagrant-aws/blob/master/lib/vagrant-aws/action/sync_folders.rb
|
10
|
+
class SyncFolders
|
11
|
+
include Vagrant::Util::ScopedHashOverride
|
12
|
+
|
13
|
+
def initialize(app, env)
|
14
|
+
@app = app
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
@app.call(env)
|
19
|
+
|
20
|
+
ssh_info = env[:machine].ssh_info
|
21
|
+
|
22
|
+
env[:machine].config.vm.synced_folders.each do |id, data|
|
23
|
+
data = scoped_hash_override(data, :vsphere)
|
24
|
+
|
25
|
+
# Ignore disabled shared folders
|
26
|
+
next if data[:disabled]
|
27
|
+
|
28
|
+
hostpath = File.expand_path(data[:hostpath], env[:root_path])
|
29
|
+
guestpath = data[:guestpath]
|
30
|
+
|
31
|
+
# Make sure there is a trailing slash on the host path to
|
32
|
+
# avoid creating an additional directory with rsync
|
33
|
+
hostpath = "#{hostpath}/" if hostpath !~ /\/$/
|
34
|
+
|
35
|
+
env[:ui].info(I18n.t("vsphere.rsync_folder",
|
36
|
+
:hostpath => hostpath,
|
37
|
+
:guestpath => guestpath))
|
38
|
+
|
39
|
+
# Create the guest path
|
40
|
+
env[:machine].communicate.sudo("mkdir -p '#{guestpath}'")
|
41
|
+
env[:machine].communicate.sudo(
|
42
|
+
"chown #{ssh_info[:username]} '#{guestpath}'")
|
43
|
+
|
44
|
+
# Rsync over to the guest path using the SSH info
|
45
|
+
command = [
|
46
|
+
"rsync", "--verbose", "--archive", "-z",
|
47
|
+
"--exclude", ".vagrant/",
|
48
|
+
"-e", "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no -i '#{ssh_info[:private_key_path]}'",
|
49
|
+
hostpath,
|
50
|
+
"#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
|
51
|
+
|
52
|
+
|
53
|
+
r = Vagrant::Util::Subprocess.execute(*command)
|
54
|
+
if r.exit_code != 0
|
55
|
+
raise Errors::RsyncError,
|
56
|
+
:guestpath => guestpath,
|
57
|
+
:hostpath => hostpath,
|
58
|
+
:stderr => r.stderr
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
require 'vagrant/action/builder'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module VSphere
|
6
|
+
module Action
|
7
|
+
include Vagrant::Action::Builtin
|
8
|
+
|
9
|
+
#Vagrant commands
|
10
|
+
def self.action_destroy
|
11
|
+
Vagrant::Action::Builder.new.tap do |b|
|
12
|
+
b.use ConfigValidate
|
13
|
+
b.use ConnectVSphere
|
14
|
+
b.use Call, IsRunning do |env, b2|
|
15
|
+
if [:result]
|
16
|
+
b2.use PowerOff
|
17
|
+
next
|
18
|
+
end
|
19
|
+
end
|
20
|
+
b.use Destroy
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.action_provision
|
25
|
+
Vagrant::Action::Builder.new.tap do |b|
|
26
|
+
b.use ConfigValidate
|
27
|
+
b.use Call, IsCreated do |env, b2|
|
28
|
+
if !env[:result]
|
29
|
+
b2.use MessageNotCreated
|
30
|
+
next
|
31
|
+
end
|
32
|
+
|
33
|
+
b2.use Call, IsRunning do |env, b3|
|
34
|
+
if !env[:result]
|
35
|
+
b3.use MessageNotRunning
|
36
|
+
next
|
37
|
+
end
|
38
|
+
|
39
|
+
b3.use Provision
|
40
|
+
b3.use SyncFolders
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.action_ssh
|
47
|
+
Vagrant::Action::Builder.new.tap do |b|
|
48
|
+
b.use ConfigValidate
|
49
|
+
b.use Call, IsCreated do |env, b2|
|
50
|
+
if !env[:result]
|
51
|
+
b2.use MessageNotCreated
|
52
|
+
next
|
53
|
+
end
|
54
|
+
|
55
|
+
b2.use Call, IsRunning do |env, b3|
|
56
|
+
if !env[:result]
|
57
|
+
b3.use MessageNotRunning
|
58
|
+
next
|
59
|
+
end
|
60
|
+
|
61
|
+
b3.use SSHExec
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.action_up
|
68
|
+
Vagrant::Action::Builder.new.tap do |b|
|
69
|
+
b.use ConfigValidate
|
70
|
+
b.use ConnectVSphere
|
71
|
+
b.use Call, IsCreated do |env, b2|
|
72
|
+
if env[:result]
|
73
|
+
b2.use MessageAlreadyCreated
|
74
|
+
next
|
75
|
+
end
|
76
|
+
|
77
|
+
b2.use Clone
|
78
|
+
end
|
79
|
+
b.use Call, IsRunning do |env, b2|
|
80
|
+
if !env[:result]
|
81
|
+
b2.use PowerOn
|
82
|
+
end
|
83
|
+
end
|
84
|
+
b.use CloseVSphere
|
85
|
+
b.use Provision
|
86
|
+
b.use SyncFolders
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.action_halt
|
91
|
+
Vagrant::Action::Builder.new.tap do |b|
|
92
|
+
b.use ConfigValidate
|
93
|
+
b.use ConnectVSphere
|
94
|
+
b.use Call, IsCreated do |env, b2|
|
95
|
+
if !env[:result]
|
96
|
+
b2.use MessageNotCreated
|
97
|
+
next
|
98
|
+
end
|
99
|
+
|
100
|
+
b2.use Call, IsRunning do |env, b3|
|
101
|
+
if !env[:result]
|
102
|
+
b3.use MessageNotRunning
|
103
|
+
next
|
104
|
+
end
|
105
|
+
|
106
|
+
b3.use PowerOff
|
107
|
+
end
|
108
|
+
end
|
109
|
+
b.use CloseVSphere
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
#vSphere specific actions
|
114
|
+
def self.action_get_state
|
115
|
+
Vagrant::Action::Builder.new.tap do |b|
|
116
|
+
b.use ConfigValidate
|
117
|
+
b.use ConnectVSphere
|
118
|
+
b.use GetState
|
119
|
+
b.use CloseVSphere
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.action_get_ssh_info
|
124
|
+
Vagrant::Action::Builder.new.tap do |b|
|
125
|
+
b.use ConfigValidate
|
126
|
+
b.use ConnectVSphere
|
127
|
+
b.use GetSshInfo
|
128
|
+
b.use CloseVSphere
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
#autoload
|
133
|
+
action_root = Pathname.new(File.expand_path('../action', __FILE__))
|
134
|
+
autoload :Clone, action_root.join('clone')
|
135
|
+
autoload :CloseVSphere, action_root.join('close_vsphere')
|
136
|
+
autoload :ConnectVSphere, action_root.join('connect_vsphere')
|
137
|
+
autoload :Destroy, action_root.join('destroy')
|
138
|
+
autoload :GetSshInfo, action_root.join('get_ssh_info')
|
139
|
+
autoload :GetState, action_root.join('get_state')
|
140
|
+
autoload :IsCreated, action_root.join('is_created')
|
141
|
+
autoload :IsRunning, action_root.join('is_running')
|
142
|
+
autoload :MessageAlreadyCreated, action_root.join('message_already_created')
|
143
|
+
autoload :MessageNotCreated, action_root.join('message_not_created')
|
144
|
+
autoload :MessageNotRunning, action_root.join('message_not_running')
|
145
|
+
autoload :PowerOff, action_root.join('power_off')
|
146
|
+
autoload :PowerOn, action_root.join('power_on')
|
147
|
+
autoload :SyncFolders, action_root.join('sync_folders')
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module VSphere
|
5
|
+
class Config < Vagrant.plugin('2', :config)
|
6
|
+
attr_accessor :host
|
7
|
+
attr_accessor :insecure
|
8
|
+
attr_accessor :user
|
9
|
+
attr_accessor :password
|
10
|
+
attr_accessor :data_center_name
|
11
|
+
attr_accessor :compute_resource_name
|
12
|
+
attr_accessor :resource_pool_name
|
13
|
+
attr_accessor :clone_from_vm
|
14
|
+
attr_accessor :template_name
|
15
|
+
attr_accessor :name
|
16
|
+
attr_accessor :customization_spec_name
|
17
|
+
attr_accessor :data_store_name
|
18
|
+
|
19
|
+
def validate(machine)
|
20
|
+
errors = _detected_errors
|
21
|
+
|
22
|
+
#TODO: add blank?
|
23
|
+
errors << I18n.t('config.host') if host.nil?
|
24
|
+
errors << I18n.t('config.user') if user.nil?
|
25
|
+
errors << I18n.t('config.password') if password.nil?
|
26
|
+
errors << I18n.t('config.name') if name.nil?
|
27
|
+
errors << I18n.t('config.template') if template_name.nil?
|
28
|
+
|
29
|
+
#These are only required if we're cloning from an actual template
|
30
|
+
errors << I18n.t('config.compute_resource') if compute_resource_name.nil? and not clone_from_vm
|
31
|
+
errors << I18n.t('config.resource_pool') if resource_pool_name.nil? and not clone_from_vm
|
32
|
+
|
33
|
+
{ 'vSphere Provider' => errors }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module VSphere
|
5
|
+
class Plugin < Vagrant.plugin('2')
|
6
|
+
name 'vsphere'
|
7
|
+
description 'Allows Vagrant to manage machines with VMWare vSphere'
|
8
|
+
|
9
|
+
config(:vsphere, :provider) do
|
10
|
+
require_relative 'config'
|
11
|
+
Config
|
12
|
+
end
|
13
|
+
|
14
|
+
provider(:vsphere) do
|
15
|
+
# TODO: add logging
|
16
|
+
setup_i18n
|
17
|
+
|
18
|
+
# Return the provider
|
19
|
+
require_relative 'provider'
|
20
|
+
Provider
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def self.setup_i18n
|
25
|
+
I18n.load_path << File.expand_path('locales/en.yml', VSphere.source_root)
|
26
|
+
I18n.reload!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module VSphere
|
5
|
+
class Provider < Vagrant.plugin('2', :provider)
|
6
|
+
def initialize(machine)
|
7
|
+
@machine = machine
|
8
|
+
end
|
9
|
+
|
10
|
+
def action(name)
|
11
|
+
action_method = "action_#{name}"
|
12
|
+
return Action.send(action_method) if Action.respond_to?(action_method)
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def ssh_info
|
17
|
+
env = @machine.action('get_ssh_info')
|
18
|
+
env[:machine_ssh_info]
|
19
|
+
end
|
20
|
+
|
21
|
+
def state
|
22
|
+
env = @machine.action('get_state')
|
23
|
+
|
24
|
+
state_id = env[:machine_state_id]
|
25
|
+
|
26
|
+
short = "vagrant_vsphere.states.short_#{state_id}"
|
27
|
+
long = "vagrant_vsphere.states.long_#{state_id}"
|
28
|
+
|
29
|
+
# Return the MachineState object
|
30
|
+
Vagrant::MachineState.new(state_id, short, long)
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
id = @machine.id.nil? ? 'new' : @machine.id
|
35
|
+
"vSphere (#{id})"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module VSphere
|
3
|
+
module Util
|
4
|
+
module MachineHelpers
|
5
|
+
def wait_for_ssh(env)
|
6
|
+
env[:ui].info(I18n.t("vsphere.waiting_for_ssh"))
|
7
|
+
while true
|
8
|
+
break if env[:machine].communicate.ready?
|
9
|
+
sleep 5
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rbvmomi'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module VSphere
|
5
|
+
module Util
|
6
|
+
module VimHelpers
|
7
|
+
def get_datacenter(connection, machine)
|
8
|
+
connection.serviceInstance.find_datacenter(machine.provider_config.data_center_name) or fail Errors::VSphereError, :message => I18n.t('errors.missing_datacenter')
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_vm_by_uuid(connection, machine)
|
12
|
+
get_datacenter(connection, machine).vmFolder.findByUuid machine.id
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_resource_pool(connection, machine)
|
16
|
+
cr = get_datacenter(connection, machine).find_compute_resource(machine.provider_config.compute_resource_name) or fail Errors::VSphereError, :message => I18n.t('errors.missing_compute_resource')
|
17
|
+
cr.resourcePool.find(machine.provider_config.resource_pool_name) or fail Errors::VSphereError, :message => I18n.t('errors.missing_resource_pool')
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_customization_spec_info_by_name(connection, machine)
|
21
|
+
name = machine.provider_config.customization_spec_name
|
22
|
+
return if name.nil? || name.empty?
|
23
|
+
|
24
|
+
manager = connection.serviceContent.customizationSpecManager or fail Errors::VSphereError, :message => I18n.t('errors.null_configuration_spec_manager') if manager.nil?
|
25
|
+
spec = manager.GetCustomizationSpec(:name => name) or fail Errors::VSphereError, :message => I18n.t('errors.missing_configuration_spec') if spec.nil?
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_datastore(connection, machine)
|
29
|
+
name = machine.provider_config.data_store_name
|
30
|
+
return if name.nil? || name.empty?
|
31
|
+
|
32
|
+
get_datacenter(connection, machine).find_datastore name or fail Errors::VSphereError, :message => I18n.t('errors.missing_datastore')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
require 'vSphere/plugin'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module VSphere
|
7
|
+
lib_path = Pathname.new(File.expand_path('../vSphere', __FILE__))
|
8
|
+
autoload :Action, lib_path.join('action')
|
9
|
+
autoload :Errors, lib_path.join('errors')
|
10
|
+
|
11
|
+
# This returns the path to the source of this plugin.
|
12
|
+
#
|
13
|
+
# @return [Pathname]
|
14
|
+
def self.source_root
|
15
|
+
@source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
en:
|
2
|
+
vsphere:
|
3
|
+
creating_cloned_vm: |-
|
4
|
+
Calling vSphere CloneVM with the following settings:
|
5
|
+
vm_clone_success: |-
|
6
|
+
New virtual machine successfully cloned and started
|
7
|
+
destroy_vm: |-
|
8
|
+
Calling vShpere Destroy
|
9
|
+
power_off_vm: |-
|
10
|
+
Calling vSphere PowerOff
|
11
|
+
power_on_vm: |-
|
12
|
+
Calling vSphere PowerOn
|
13
|
+
vm_already_created: |-
|
14
|
+
The VM is already created
|
15
|
+
vm_not_created: |-
|
16
|
+
The VM has not been created
|
17
|
+
vm_not_running: |-
|
18
|
+
The VM is not running
|
19
|
+
waiting_for_ssh: |-
|
20
|
+
Waiting for SSH to become available...
|
21
|
+
rsync_folder: |-
|
22
|
+
Rsyncing folder: %{hostpath} => %{guestpath}
|
23
|
+
errors:
|
24
|
+
missing_template: |-
|
25
|
+
Configured template/source VM could not be found
|
26
|
+
missing_datacenter: |-
|
27
|
+
Configured data center not found
|
28
|
+
missing_compute_resource: |-
|
29
|
+
Configured compute resource not found
|
30
|
+
missing_resource_pool: |-
|
31
|
+
Configured resource pool not found
|
32
|
+
null_configuration_spec_manager: |-
|
33
|
+
Configuration spec manager not configured in the ServiceInstance
|
34
|
+
missing_configuration_spec: |-
|
35
|
+
Configured configuration spec not found
|
36
|
+
missing_datastore: |-
|
37
|
+
Configured data store not found
|
38
|
+
rsync_error: |-
|
39
|
+
There was an error when attemping to rsync a share folder.
|
40
|
+
Please inspect the error message below for more info.
|
41
|
+
|
42
|
+
Host path: %{hostpath}
|
43
|
+
Guest path: %{guestpath}
|
44
|
+
Error: %{stderr}
|
45
|
+
too_many_private_networks: |-
|
46
|
+
There a more private networks configured than can be assigned to the customization spec
|
47
|
+
config:
|
48
|
+
host: |-
|
49
|
+
Configuration must specify a vSphere host
|
50
|
+
user: |-
|
51
|
+
Configuration must specify a vSphere user
|
52
|
+
password: |-
|
53
|
+
Configuration must specify a vSphere password
|
54
|
+
name: |-
|
55
|
+
Configuration must specify a VM name
|
56
|
+
template: |-
|
57
|
+
Configuration must specify a template name
|
58
|
+
compute_resource: |-
|
59
|
+
Configuration must specify a compute resource name
|
60
|
+
resource_pool: |-
|
61
|
+
Configuration must specify a resource pool name
|
data/spec/action_spec.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'vagrant'
|
3
|
+
|
4
|
+
describe VagrantPlugins::VSphere::Action do
|
5
|
+
def run(action)
|
6
|
+
Vagrant::Action::Runner.new.run described_class.send("action_#{action}"), @env
|
7
|
+
end
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
@machine.stub(:id).and_return(EXISTING_UUID)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'up' do
|
14
|
+
def run_up
|
15
|
+
run :up
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should connect to vSphere' do
|
19
|
+
VagrantPlugins::VSphere::Action::ConnectVSphere.any_instance.should_receive(:call)
|
20
|
+
|
21
|
+
run_up
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should check if the VM exits' do
|
25
|
+
VagrantPlugins::VSphere::Action::IsCreated.any_instance.should_receive(:call)
|
26
|
+
|
27
|
+
run_up
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should create the VM when the VM does already not exist' do
|
31
|
+
@machine.state.stub(:id).and_return(:not_created)
|
32
|
+
|
33
|
+
VagrantPlugins::VSphere::Action::Clone.any_instance.should_receive(:call)
|
34
|
+
|
35
|
+
run_up
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should not create the VM when the VM already exists' do
|
39
|
+
@machine.state.stub(:id).and_return(:running)
|
40
|
+
|
41
|
+
VagrantPlugins::VSphere::Action::Clone.any_instance.should_not_receive(:call)
|
42
|
+
|
43
|
+
run_up
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'destroy' do
|
48
|
+
def run_destroy
|
49
|
+
run :destroy
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should connect to vSphere' do
|
53
|
+
VagrantPlugins::VSphere::Action::ConnectVSphere.any_instance.should_receive(:call)
|
54
|
+
|
55
|
+
run_destroy
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should power off the VM' do
|
59
|
+
VagrantPlugins::VSphere::Action::PowerOff.any_instance.should_receive(:call)
|
60
|
+
|
61
|
+
run_destroy
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should destroy the VM' do
|
65
|
+
VagrantPlugins::VSphere::Action::Destroy.any_instance.should_receive(:call)
|
66
|
+
|
67
|
+
run_destroy
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'halt' do
|
72
|
+
it 'should power off the VM' do
|
73
|
+
@machine.state.stub(:id).and_return(:running)
|
74
|
+
|
75
|
+
VagrantPlugins::VSphere::Action::PowerOff.any_instance.should_receive(:call)
|
76
|
+
|
77
|
+
run :halt
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'get state' do
|
82
|
+
def run_get_state
|
83
|
+
run :get_state
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should connect to vSphere' do
|
87
|
+
VagrantPlugins::VSphere::Action::ConnectVSphere.any_instance.should_receive(:call)
|
88
|
+
|
89
|
+
run_get_state
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should get the power state' do
|
93
|
+
VagrantPlugins::VSphere::Action::GetState.any_instance.should_receive(:call)
|
94
|
+
|
95
|
+
run_get_state
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'get ssh info' do
|
100
|
+
def run_get_ssh_info
|
101
|
+
run :get_ssh_info
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should connect to vSphere' do
|
105
|
+
VagrantPlugins::VSphere::Action::ConnectVSphere.any_instance.should_receive(:call)
|
106
|
+
|
107
|
+
run_get_ssh_info
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should get the power state' do
|
111
|
+
VagrantPlugins::VSphere::Action::GetSshInfo.any_instance.should_receive(:call)
|
112
|
+
|
113
|
+
run_get_ssh_info
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
data/spec/clone_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VagrantPlugins::VSphere::Action::Clone do
|
4
|
+
before :each do
|
5
|
+
@env[:vSphere_connection] = @vim
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should create a CloneVM task' do
|
9
|
+
call
|
10
|
+
@template.should have_received(:CloneVM_Task).with({
|
11
|
+
:folder => @data_center,
|
12
|
+
:name => NAME,
|
13
|
+
:spec => {}
|
14
|
+
})
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should set the machine id to be the new UUID' do
|
18
|
+
call
|
19
|
+
@machine.should have_received(:id=).with(NEW_UUID)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should call the next item in the middleware stack' do
|
23
|
+
call
|
24
|
+
@app.should have_received :call
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should set static IP when given config spec' do
|
28
|
+
@machine.provider_config.stub(:customization_spec_name).and_return('spec')
|
29
|
+
call
|
30
|
+
@ip.should have_received(:ipAddress=).with('0.0.0.0')
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VagrantPlugins::VSphere::Action::ConnectVSphere do
|
4
|
+
before :each do
|
5
|
+
described_class.new(@app, @env).call(@env)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should connect to vSphere' do
|
9
|
+
VIM.should have_received(:connect).with({
|
10
|
+
:host => @env[:machine].provider_config.host,
|
11
|
+
:user => @env[:machine].provider_config.user,
|
12
|
+
:password => @env[:machine].provider_config.password,
|
13
|
+
:insecure => @env[:machine].provider_config.insecure,
|
14
|
+
})
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should add the vSphere connection to the environment' do
|
18
|
+
@env[:vSphere_connection].should be @vim
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should call the next item in the middleware stack' do
|
22
|
+
@app.should have_received :call
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VagrantPlugins::VSphere::Action::Destroy do
|
4
|
+
before :each do
|
5
|
+
@env[:vSphere_connection] = @vim
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should set the machine id to nil' do
|
9
|
+
@env[:machine].stub(:id).and_return(MISSING_UUID)
|
10
|
+
|
11
|
+
call
|
12
|
+
|
13
|
+
@env[:machine].should have_received(:id=).with(nil)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should not create a Destroy task if VM is not found' do
|
17
|
+
@env[:machine].stub(:id).and_return(MISSING_UUID)
|
18
|
+
|
19
|
+
call
|
20
|
+
|
21
|
+
@vm.should_not have_received :Destroy_Task
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should create a VM Destroy task if the VM exists' do
|
25
|
+
@env[:machine].stub(:id).and_return(EXISTING_UUID)
|
26
|
+
|
27
|
+
call
|
28
|
+
|
29
|
+
@vm.should have_received :Destroy_Task
|
30
|
+
end
|
31
|
+
end
|