vagrant-vsphere 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +5 -5
  2. data/Gemfile +9 -9
  3. data/LICENSE.txt +23 -23
  4. data/README.md +175 -164
  5. data/Rakefile +16 -16
  6. data/example_box/metadata.json +2 -2
  7. data/lib/vSphere/action/clone.rb +127 -83
  8. data/lib/vSphere/action/close_vsphere.rb +23 -23
  9. data/lib/vSphere/action/connect_vsphere.rb +25 -25
  10. data/lib/vSphere/action/destroy.rb +37 -37
  11. data/lib/vSphere/action/get_ssh_info.rb +37 -37
  12. data/lib/vSphere/action/get_state.rb +45 -45
  13. data/lib/vSphere/action/is_created.rb +15 -15
  14. data/lib/vSphere/action/is_running.rb +20 -20
  15. data/lib/vSphere/action/message_already_created.rb +17 -17
  16. data/lib/vSphere/action/message_not_created.rb +17 -17
  17. data/lib/vSphere/action/message_not_running.rb +18 -18
  18. data/lib/vSphere/action/power_off.rb +27 -27
  19. data/lib/vSphere/action/power_on.rb +31 -31
  20. data/lib/vSphere/action/sync_folders.rb +97 -81
  21. data/lib/vSphere/action.rb +172 -172
  22. data/lib/vSphere/config.rb +37 -37
  23. data/lib/vSphere/errors.rb +10 -10
  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 +36 -36
  28. data/lib/vSphere/version.rb +4 -4
  29. data/lib/vagrant-vsphere.rb +17 -17
  30. data/locales/en.yml +65 -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 -97
  39. data/vSphere.gemspec +27 -27
  40. metadata +21 -5
  41. checksums.yaml +0 -15
@@ -1,172 +1,172 @@
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_ssh_run
68
- Vagrant::Action::Builder.new.tap do |b|
69
- b.use ConfigValidate
70
- b.use Call, IsCreated do |env, b2|
71
- if !env[:result]
72
- b2.use MessageNotCreated
73
- next
74
- end
75
-
76
- b2.use Call, IsRunning do |env, b3|
77
- if !env[:result]
78
- b3.use MessageNotRunning
79
- next
80
- end
81
-
82
- b3.use SSHRun
83
- end
84
- end
85
- end
86
- end
87
-
88
- def self.action_up
89
- Vagrant::Action::Builder.new.tap do |b|
90
- b.use ConfigValidate
91
- b.use ConnectVSphere
92
- b.use Call, IsCreated do |env, b2|
93
- if env[:result]
94
- b2.use MessageAlreadyCreated
95
- next
96
- end
97
-
98
- b2.use Clone
99
- end
100
- b.use Call, IsRunning do |env, b2|
101
- if !env[:result]
102
- b2.use PowerOn
103
- end
104
- end
105
- b.use CloseVSphere
106
- b.use Provision
107
- b.use SyncFolders
108
- end
109
- end
110
-
111
- def self.action_halt
112
- Vagrant::Action::Builder.new.tap do |b|
113
- b.use ConfigValidate
114
- b.use ConnectVSphere
115
- b.use Call, IsCreated do |env, b2|
116
- if !env[:result]
117
- b2.use MessageNotCreated
118
- next
119
- end
120
-
121
- b2.use Call, IsRunning do |env, b3|
122
- if !env[:result]
123
- b3.use MessageNotRunning
124
- next
125
- end
126
-
127
- b3.use PowerOff
128
- end
129
- end
130
- b.use CloseVSphere
131
- end
132
- end
133
-
134
- #vSphere specific actions
135
- def self.action_get_state
136
- Vagrant::Action::Builder.new.tap do |b|
137
- b.use ConfigValidate
138
- b.use ConnectVSphere
139
- b.use GetState
140
- b.use CloseVSphere
141
- end
142
- end
143
-
144
- def self.action_get_ssh_info
145
- Vagrant::Action::Builder.new.tap do |b|
146
- b.use ConfigValidate
147
- b.use ConnectVSphere
148
- b.use GetSshInfo
149
- b.use CloseVSphere
150
- end
151
- end
152
-
153
- #autoload
154
- action_root = Pathname.new(File.expand_path('../action', __FILE__))
155
- autoload :Clone, action_root.join('clone')
156
- autoload :CloseVSphere, action_root.join('close_vsphere')
157
- autoload :ConnectVSphere, action_root.join('connect_vsphere')
158
- autoload :Destroy, action_root.join('destroy')
159
- autoload :GetSshInfo, action_root.join('get_ssh_info')
160
- autoload :GetState, action_root.join('get_state')
161
- autoload :IsCreated, action_root.join('is_created')
162
- autoload :IsRunning, action_root.join('is_running')
163
- autoload :MessageAlreadyCreated, action_root.join('message_already_created')
164
- autoload :MessageNotCreated, action_root.join('message_not_created')
165
- autoload :MessageNotRunning, action_root.join('message_not_running')
166
- autoload :PowerOff, action_root.join('power_off')
167
- autoload :PowerOn, action_root.join('power_on')
168
- autoload :SyncFolders, action_root.join('sync_folders')
169
- end
170
- end
171
- end
172
-
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_ssh_run
68
+ Vagrant::Action::Builder.new.tap do |b|
69
+ b.use ConfigValidate
70
+ b.use Call, IsCreated do |env, b2|
71
+ if !env[:result]
72
+ b2.use MessageNotCreated
73
+ next
74
+ end
75
+
76
+ b2.use Call, IsRunning do |env, b3|
77
+ if !env[:result]
78
+ b3.use MessageNotRunning
79
+ next
80
+ end
81
+
82
+ b3.use SSHRun
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ def self.action_up
89
+ Vagrant::Action::Builder.new.tap do |b|
90
+ b.use ConfigValidate
91
+ b.use ConnectVSphere
92
+ b.use Call, IsCreated do |env, b2|
93
+ if env[:result]
94
+ b2.use MessageAlreadyCreated
95
+ next
96
+ end
97
+
98
+ b2.use Clone
99
+ end
100
+ b.use Call, IsRunning do |env, b2|
101
+ if !env[:result]
102
+ b2.use PowerOn
103
+ end
104
+ end
105
+ b.use CloseVSphere
106
+ b.use Provision
107
+ b.use SyncFolders
108
+ end
109
+ end
110
+
111
+ def self.action_halt
112
+ Vagrant::Action::Builder.new.tap do |b|
113
+ b.use ConfigValidate
114
+ b.use ConnectVSphere
115
+ b.use Call, IsCreated do |env, b2|
116
+ if !env[:result]
117
+ b2.use MessageNotCreated
118
+ next
119
+ end
120
+
121
+ b2.use Call, IsRunning do |env, b3|
122
+ if !env[:result]
123
+ b3.use MessageNotRunning
124
+ next
125
+ end
126
+
127
+ b3.use PowerOff
128
+ end
129
+ end
130
+ b.use CloseVSphere
131
+ end
132
+ end
133
+
134
+ #vSphere specific actions
135
+ def self.action_get_state
136
+ Vagrant::Action::Builder.new.tap do |b|
137
+ b.use ConfigValidate
138
+ b.use ConnectVSphere
139
+ b.use GetState
140
+ b.use CloseVSphere
141
+ end
142
+ end
143
+
144
+ def self.action_get_ssh_info
145
+ Vagrant::Action::Builder.new.tap do |b|
146
+ b.use ConfigValidate
147
+ b.use ConnectVSphere
148
+ b.use GetSshInfo
149
+ b.use CloseVSphere
150
+ end
151
+ end
152
+
153
+ #autoload
154
+ action_root = Pathname.new(File.expand_path('../action', __FILE__))
155
+ autoload :Clone, action_root.join('clone')
156
+ autoload :CloseVSphere, action_root.join('close_vsphere')
157
+ autoload :ConnectVSphere, action_root.join('connect_vsphere')
158
+ autoload :Destroy, action_root.join('destroy')
159
+ autoload :GetSshInfo, action_root.join('get_ssh_info')
160
+ autoload :GetState, action_root.join('get_state')
161
+ autoload :IsCreated, action_root.join('is_created')
162
+ autoload :IsRunning, action_root.join('is_running')
163
+ autoload :MessageAlreadyCreated, action_root.join('message_already_created')
164
+ autoload :MessageNotCreated, action_root.join('message_not_created')
165
+ autoload :MessageNotRunning, action_root.join('message_not_running')
166
+ autoload :PowerOff, action_root.join('power_off')
167
+ autoload :PowerOn, action_root.join('power_on')
168
+ autoload :SyncFolders, action_root.join('sync_folders')
169
+ end
170
+ end
171
+ end
172
+
@@ -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
-
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
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,11 +1,11 @@
1
- require 'vagrant'
2
-
3
- module VagrantPlugins
4
- module VSphere
5
- module Errors
6
- class VSphereError < Vagrant::Errors::VagrantError
7
- error_namespace('vsphere.errors')
8
- end
9
- end
10
- end
1
+ require 'vagrant'
2
+
3
+ module VagrantPlugins
4
+ module VSphere
5
+ module Errors
6
+ class VSphereError < Vagrant::Errors::VagrantError
7
+ error_namespace('vsphere.errors')
8
+ end
9
+ end
10
+ end
11
11
  end
@@ -1,30 +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
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
30
  end
@@ -1,39 +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
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
39
  end
@@ -1,15 +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
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