vagrant-vsphere 0.6.0 → 0.7.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.
- data/.gitignore +5 -5
- data/Gemfile +9 -9
- data/LICENSE.txt +23 -23
- data/README.md +175 -164
- data/Rakefile +16 -16
- data/example_box/metadata.json +2 -2
- data/lib/vSphere/action/clone.rb +127 -83
- data/lib/vSphere/action/close_vsphere.rb +23 -23
- data/lib/vSphere/action/connect_vsphere.rb +25 -25
- data/lib/vSphere/action/destroy.rb +37 -37
- data/lib/vSphere/action/get_ssh_info.rb +37 -37
- data/lib/vSphere/action/get_state.rb +45 -45
- data/lib/vSphere/action/is_created.rb +15 -15
- data/lib/vSphere/action/is_running.rb +20 -20
- data/lib/vSphere/action/message_already_created.rb +17 -17
- data/lib/vSphere/action/message_not_created.rb +17 -17
- data/lib/vSphere/action/message_not_running.rb +18 -18
- data/lib/vSphere/action/power_off.rb +27 -27
- data/lib/vSphere/action/power_on.rb +31 -31
- data/lib/vSphere/action/sync_folders.rb +97 -81
- data/lib/vSphere/action.rb +172 -172
- data/lib/vSphere/config.rb +37 -37
- data/lib/vSphere/errors.rb +10 -10
- data/lib/vSphere/plugin.rb +29 -29
- data/lib/vSphere/provider.rb +38 -38
- data/lib/vSphere/util/machine_helpers.rb +15 -15
- data/lib/vSphere/util/vim_helpers.rb +36 -36
- data/lib/vSphere/version.rb +4 -4
- data/lib/vagrant-vsphere.rb +17 -17
- data/locales/en.yml +65 -65
- data/spec/action_spec.rb +116 -116
- data/spec/clone_spec.rb +31 -31
- data/spec/connect_vsphere_spec.rb +23 -23
- data/spec/destroy_spec.rb +30 -30
- data/spec/get_ssh_info_spec.rb +30 -30
- data/spec/get_state_spec.rb +54 -54
- data/spec/is_created_spec.rb +28 -28
- data/spec/spec_helper.rb +98 -97
- data/vSphere.gemspec +27 -27
- metadata +21 -5
- checksums.yaml +0 -15
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'i18n'
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module VSphere
|
5
|
-
module Action
|
6
|
-
class MessageAlreadyCreated
|
7
|
-
def initialize(app, env)
|
8
|
-
@app = app
|
9
|
-
end
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
env[:ui].info I18n.t('vsphere.vm_not_created')
|
13
|
-
@app.call(env)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
require 'i18n'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module VSphere
|
5
|
+
module Action
|
6
|
+
class MessageAlreadyCreated
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
env[:ui].info I18n.t('vsphere.vm_not_created')
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
18
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'i18n'
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module VSphere
|
5
|
-
module Action
|
6
|
-
class MessageNotRunning
|
7
|
-
def initialize(app, env)
|
8
|
-
@app = app
|
9
|
-
end
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
env[:ui].info I18n.t('vsphere.vm_not_running')
|
13
|
-
@app.call(env)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
1
|
+
require 'i18n'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module VSphere
|
5
|
+
module Action
|
6
|
+
class MessageNotRunning
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
env[:ui].info I18n.t('vsphere.vm_not_running')
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,28 +1,28 @@
|
|
1
|
-
require 'rbvmomi'
|
2
|
-
require 'i18n'
|
3
|
-
require 'vSphere/util/vim_helpers'
|
4
|
-
|
5
|
-
module VagrantPlugins
|
6
|
-
module VSphere
|
7
|
-
module Action
|
8
|
-
class PowerOff
|
9
|
-
include Util::VimHelpers
|
10
|
-
|
11
|
-
def initialize(app, env)
|
12
|
-
@app = app
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(env)
|
16
|
-
vm = get_vm_by_uuid env[:vSphere_connection], env[:machine]
|
17
|
-
|
18
|
-
unless vm.nil?
|
19
|
-
env[:ui].info I18n.t('vsphere.power_off_vm')
|
20
|
-
vm.PowerOffVM_Task.wait_for_completion
|
21
|
-
end
|
22
|
-
|
23
|
-
@app.call env
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
1
|
+
require 'rbvmomi'
|
2
|
+
require 'i18n'
|
3
|
+
require 'vSphere/util/vim_helpers'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module VSphere
|
7
|
+
module Action
|
8
|
+
class PowerOff
|
9
|
+
include Util::VimHelpers
|
10
|
+
|
11
|
+
def initialize(app, env)
|
12
|
+
@app = app
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
vm = get_vm_by_uuid env[:vSphere_connection], env[:machine]
|
17
|
+
|
18
|
+
unless vm.nil?
|
19
|
+
env[:ui].info I18n.t('vsphere.power_off_vm')
|
20
|
+
vm.PowerOffVM_Task.wait_for_completion
|
21
|
+
end
|
22
|
+
|
23
|
+
@app.call env
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
28
|
end
|
@@ -1,31 +1,31 @@
|
|
1
|
-
require 'rbvmomi'
|
2
|
-
require 'i18n'
|
3
|
-
require 'vSphere/util/vim_helpers'
|
4
|
-
require 'vSphere/util/machine_helpers'
|
5
|
-
|
6
|
-
module VagrantPlugins
|
7
|
-
module VSphere
|
8
|
-
module Action
|
9
|
-
class PowerOn
|
10
|
-
include Util::VimHelpers
|
11
|
-
include Util::MachineHelpers
|
12
|
-
|
13
|
-
def initialize(app, env)
|
14
|
-
@app = app
|
15
|
-
end
|
16
|
-
|
17
|
-
def call(env)
|
18
|
-
vm = get_vm_by_uuid env[:vSphere_connection], env[:machine]
|
19
|
-
|
20
|
-
env[:ui].info I18n.t('vsphere.power_on_vm')
|
21
|
-
vm.PowerOnVM_Task.wait_for_completion
|
22
|
-
|
23
|
-
# wait for SSH to be available
|
24
|
-
wait_for_ssh env
|
25
|
-
|
26
|
-
@app.call env
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
1
|
+
require 'rbvmomi'
|
2
|
+
require 'i18n'
|
3
|
+
require 'vSphere/util/vim_helpers'
|
4
|
+
require 'vSphere/util/machine_helpers'
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module VSphere
|
8
|
+
module Action
|
9
|
+
class PowerOn
|
10
|
+
include Util::VimHelpers
|
11
|
+
include Util::MachineHelpers
|
12
|
+
|
13
|
+
def initialize(app, env)
|
14
|
+
@app = app
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
vm = get_vm_by_uuid env[:vSphere_connection], env[:machine]
|
19
|
+
|
20
|
+
env[:ui].info I18n.t('vsphere.power_on_vm')
|
21
|
+
vm.PowerOnVM_Task.wait_for_completion
|
22
|
+
|
23
|
+
# wait for SSH to be available
|
24
|
+
wait_for_ssh env
|
25
|
+
|
26
|
+
@app.call env
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,81 +1,97 @@
|
|
1
|
-
require 'i18n'
|
2
|
-
require "vagrant/util/subprocess"
|
3
|
-
require "vagrant/util/scoped_hash_override"
|
4
|
-
require "vagrant/util/which"
|
5
|
-
|
6
|
-
module VagrantPlugins
|
7
|
-
module VSphere
|
8
|
-
module Action
|
9
|
-
# This middleware uses `rsync` to sync the folders over to the vSphere instance
|
10
|
-
# Borrowed from the Vagrant AWS gem, see https://github.com/mitchellh/vagrant-aws/blob/master/lib/vagrant-aws/action/sync_folders.rb
|
11
|
-
class SyncFolders
|
12
|
-
include Vagrant::Util::ScopedHashOverride
|
13
|
-
|
14
|
-
def initialize(app, env)
|
15
|
-
@app = app
|
16
|
-
end
|
17
|
-
|
18
|
-
def call(env)
|
19
|
-
@app.call(env)
|
20
|
-
|
21
|
-
ssh_info = env[:machine].ssh_info
|
22
|
-
|
23
|
-
env[:machine].config.vm.synced_folders.each do |id, data|
|
24
|
-
data = scoped_hash_override(data, :vsphere)
|
25
|
-
|
26
|
-
# Ignore disabled shared folders
|
27
|
-
next if data[:disabled]
|
28
|
-
|
29
|
-
unless Vagrant::Util::Which.which('rsync')
|
30
|
-
env[:ui].warn(I18n.t('errors.rsync_not_found'))
|
31
|
-
break
|
32
|
-
end
|
33
|
-
hostpath = File.expand_path(data[:hostpath], env[:root_path])
|
34
|
-
guestpath = data[:guestpath]
|
35
|
-
|
36
|
-
# Make sure there is a trailing slash on the host path to
|
37
|
-
# avoid creating an additional directory with rsync
|
38
|
-
hostpath = "#{hostpath}/" if hostpath !~ /\/$/
|
39
|
-
|
40
|
-
# on windows rsync.exe requires cygdrive-style paths
|
41
|
-
if Vagrant::Util::Platform.windows?
|
42
|
-
hostpath = hostpath.gsub(/^(\w):/) { "/cygdrive/#{$1}" }
|
43
|
-
end
|
44
|
-
|
45
|
-
env[:ui].info(I18n.t("vsphere.rsync_folder",
|
46
|
-
:hostpath => hostpath,
|
47
|
-
:guestpath => guestpath))
|
48
|
-
|
49
|
-
# Create the guest path
|
50
|
-
env[:machine].communicate.sudo("mkdir -p '#{guestpath}'")
|
51
|
-
env[:machine].communicate.sudo(
|
52
|
-
"chown #{ssh_info[:username]} '#{guestpath}'")
|
53
|
-
|
54
|
-
#
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
#
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
1
|
+
require 'i18n'
|
2
|
+
require "vagrant/util/subprocess"
|
3
|
+
require "vagrant/util/scoped_hash_override"
|
4
|
+
require "vagrant/util/which"
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module VSphere
|
8
|
+
module Action
|
9
|
+
# This middleware uses `rsync` to sync the folders over to the vSphere instance
|
10
|
+
# Borrowed from the Vagrant AWS gem, see https://github.com/mitchellh/vagrant-aws/blob/master/lib/vagrant-aws/action/sync_folders.rb
|
11
|
+
class SyncFolders
|
12
|
+
include Vagrant::Util::ScopedHashOverride
|
13
|
+
|
14
|
+
def initialize(app, env)
|
15
|
+
@app = app
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
@app.call(env)
|
20
|
+
|
21
|
+
ssh_info = env[:machine].ssh_info
|
22
|
+
|
23
|
+
env[:machine].config.vm.synced_folders.each do |id, data|
|
24
|
+
data = scoped_hash_override(data, :vsphere)
|
25
|
+
|
26
|
+
# Ignore disabled shared folders
|
27
|
+
next if data[:disabled]
|
28
|
+
|
29
|
+
unless Vagrant::Util::Which.which('rsync')
|
30
|
+
env[:ui].warn(I18n.t('errors.rsync_not_found'))
|
31
|
+
break
|
32
|
+
end
|
33
|
+
hostpath = File.expand_path(data[:hostpath], env[:root_path])
|
34
|
+
guestpath = data[:guestpath]
|
35
|
+
|
36
|
+
# Make sure there is a trailing slash on the host path to
|
37
|
+
# avoid creating an additional directory with rsync
|
38
|
+
hostpath = "#{hostpath}/" if hostpath !~ /\/$/
|
39
|
+
|
40
|
+
# on windows rsync.exe requires cygdrive-style paths
|
41
|
+
if Vagrant::Util::Platform.windows?
|
42
|
+
hostpath = hostpath.gsub(/^(\w):/) { "/cygdrive/#{$1}" }
|
43
|
+
end
|
44
|
+
|
45
|
+
env[:ui].info(I18n.t("vsphere.rsync_folder",
|
46
|
+
:hostpath => hostpath,
|
47
|
+
:guestpath => guestpath))
|
48
|
+
|
49
|
+
# Create the guest path
|
50
|
+
env[:machine].communicate.sudo("mkdir -p '#{guestpath}'")
|
51
|
+
env[:machine].communicate.sudo(
|
52
|
+
"chown #{ssh_info[:username]} '#{guestpath}'")
|
53
|
+
|
54
|
+
# Prepare private_key path
|
55
|
+
private_key_options = ""
|
56
|
+
if ssh_info[:private_key_path].is_a? String
|
57
|
+
private_key_options = build_key_option ssh_info[:private_key_path]
|
58
|
+
elsif ssh_info[:private_key_path].is_a? Array
|
59
|
+
ssh_info[:private_key_path].each do |path|
|
60
|
+
private_key_options += build_key_option path
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Rsync over to the guest path using the SSH info
|
65
|
+
command = [
|
66
|
+
"rsync", "--verbose", "--archive", "-z",
|
67
|
+
"--exclude", ".vagrant/",
|
68
|
+
"-e", "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no #{private_key_options}",
|
69
|
+
hostpath,
|
70
|
+
"#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
|
71
|
+
|
72
|
+
|
73
|
+
# we need to fix permissions when using rsync.exe on windows, see
|
74
|
+
# http://stackoverflow.com/questions/5798807/rsync-permission-denied-created-directories-have-no-permissions
|
75
|
+
if Vagrant::Util::Platform.windows?
|
76
|
+
command.insert(1, "--chmod", "ugo=rwX")
|
77
|
+
end
|
78
|
+
|
79
|
+
r = Vagrant::Util::Subprocess.execute(*command)
|
80
|
+
if r.exit_code != 0
|
81
|
+
raise Errors::RsyncError,
|
82
|
+
:guestpath => guestpath,
|
83
|
+
:hostpath => hostpath,
|
84
|
+
:stderr => r.stderr
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def build_key_option(key)
|
92
|
+
" -i '#{key}'"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|