vagrant-vsphere 0.7.0 → 0.7.1

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 +8 -6
  2. data/Gemfile +10 -10
  3. data/LICENSE.txt +23 -23
  4. data/README.md +180 -175
  5. data/Rakefile +16 -16
  6. data/example_box/metadata.json +2 -2
  7. data/lib/vSphere/action.rb +172 -172
  8. data/lib/vSphere/action/clone.rb +131 -127
  9. data/lib/vSphere/action/close_vsphere.rb +23 -23
  10. data/lib/vSphere/action/connect_vsphere.rb +25 -25
  11. data/lib/vSphere/action/destroy.rb +37 -37
  12. data/lib/vSphere/action/get_ssh_info.rb +37 -37
  13. data/lib/vSphere/action/get_state.rb +45 -45
  14. data/lib/vSphere/action/is_created.rb +15 -15
  15. data/lib/vSphere/action/is_running.rb +20 -20
  16. data/lib/vSphere/action/message_already_created.rb +17 -17
  17. data/lib/vSphere/action/message_not_created.rb +17 -17
  18. data/lib/vSphere/action/message_not_running.rb +18 -18
  19. data/lib/vSphere/action/power_off.rb +27 -27
  20. data/lib/vSphere/action/power_on.rb +31 -31
  21. data/lib/vSphere/action/sync_folders.rb +94 -97
  22. data/lib/vSphere/config.rb +37 -37
  23. data/lib/vSphere/errors.rb +14 -11
  24. data/lib/vSphere/plugin.rb +29 -29
  25. data/lib/vSphere/provider.rb +38 -38
  26. data/lib/vSphere/util/machine_helpers.rb +15 -15
  27. data/lib/vSphere/util/vim_helpers.rb +37 -37
  28. data/lib/vSphere/version.rb +5 -5
  29. data/lib/vagrant-vsphere.rb +17 -17
  30. data/locales/en.yml +66 -65
  31. data/spec/action_spec.rb +116 -116
  32. data/spec/clone_spec.rb +31 -31
  33. data/spec/connect_vsphere_spec.rb +23 -23
  34. data/spec/destroy_spec.rb +30 -30
  35. data/spec/get_ssh_info_spec.rb +30 -30
  36. data/spec/get_state_spec.rb +54 -54
  37. data/spec/is_created_spec.rb +28 -28
  38. data/spec/spec_helper.rb +98 -98
  39. data/vSphere.gemspec +29 -28
  40. metadata +14 -8
@@ -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,97 +1,94 @@
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
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('vsphere.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("chown #{ssh_info[:username]} '#{guestpath}'")
52
+
53
+ # Rsync over to the guest path using the SSH info
54
+ command = [
55
+ "rsync", "--verbose", "--archive", "-z",
56
+ "--exclude", ".vagrant/",
57
+ "-e", "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no #{get_private_key_options ssh_info}",
58
+ hostpath,
59
+ "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
60
+
61
+
62
+ # we need to fix permissions when using rsync.exe on windows, see
63
+ # http://stackoverflow.com/questions/5798807/rsync-permission-denied-created-directories-have-no-permissions
64
+ if Vagrant::Util::Platform.windows?
65
+ command.insert(1, "--chmod", "ugo=rwX")
66
+ end
67
+
68
+ r = Vagrant::Util::Subprocess.execute(*command)
69
+ if r.exit_code != 0
70
+ raise Errors::RsyncError,
71
+ :guestpath => guestpath,
72
+ :hostpath => hostpath,
73
+ :stderr => r.stderr
74
+ end
75
+ end
76
+ end
77
+
78
+ private
79
+
80
+ def get_private_key_options(ssh_info)
81
+ if ssh_info[:private_key_path].is_a? String
82
+ build_key_option ssh_info[:private_key_path]
83
+ elsif ssh_info[:private_key_path].is_a? Array
84
+ ssh_info[:private_key_path].map { |path| build_key_option path }.join(' ')
85
+ end
86
+ end
87
+
88
+ def build_key_option(key)
89
+ "-i '#{key}'"
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -1,37 +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
- attr_accessor :linked_clone
19
-
20
- def validate(machine)
21
- errors = _detected_errors
22
-
23
- # TODO: add blank?
24
- errors << I18n.t('config.host') if host.nil?
25
- errors << I18n.t('config.user') if user.nil?
26
- errors << I18n.t('config.password') if password.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
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
+ attr_accessor :linked_clone
19
+
20
+ def validate(machine)
21
+ errors = _detected_errors
22
+
23
+ # TODO: add blank?
24
+ errors << I18n.t('vsphere.config.host') if host.nil?
25
+ errors << I18n.t('vsphere.config.user') if user.nil?
26
+ errors << I18n.t('vsphere.config.password') if password.nil?
27
+ errors << I18n.t('vsphere.config.template') if template_name.nil?
28
+
29
+ # These are only required if we're cloning from an actual template
30
+ errors << I18n.t('vsphere.config.compute_resource') if compute_resource_name.nil? and not clone_from_vm
31
+ errors << I18n.t('vsphere.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