vagrant-vsphere 1.9.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.bumpversion.cfg +1 -1
- data/CHANGELOG.md +5 -0
- data/README.md +2 -2
- data/lib/vSphere/action.rb +82 -0
- data/lib/vSphere/action/snapshot_delete.rb +38 -0
- data/lib/vSphere/action/snapshot_list.rb +25 -0
- data/lib/vSphere/action/snapshot_restore.rb +34 -0
- data/lib/vSphere/action/snapshot_save.rb +37 -0
- data/lib/vSphere/cap/snapshot_list.rb +15 -0
- data/lib/vSphere/plugin.rb +10 -0
- data/lib/vSphere/util/vm_helpers.rb +121 -0
- data/lib/vSphere/version.rb +1 -1
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38f22b2b500db61a2424e1f889a8a06c3110d608
|
4
|
+
data.tar.gz: c046149e0f57992b4d2a6efa0e24fd92d9c98ebd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15d78428dee29093ba9891f19d4cef5fc231ac361d39c0cce28cef0f6c506c66db67a1f436c747ecb9e019beff9f89f0864e4713c5585a126994aca63f2fba41
|
7
|
+
data.tar.gz: 93d239b478335c3f5848412373ba5303806843f20831f050876ea202a3f2f0589df56a75fc95d4a8b475ab14b886377419387a907e357a0b6198e69a64a3fe18
|
data/.bumpversion.cfg
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## [1.10.0 (2016-05-17)](https://github.com/nsidc/vagrant-vsphere/releases/tag/v1.10.0)
|
2
|
+
|
3
|
+
- Add support for `vagrant snapshot` and its subcommands
|
4
|
+
([vagrant-vsphere:add-snapshot-support](https://github.com/nsidc/vagrant-vsphere/pull/198)).
|
5
|
+
|
1
6
|
## [1.9.0 (2016-05-17)](https://github.com/nsidc/vagrant-vsphere/releases/tag/v1.9.0)
|
2
7
|
|
3
8
|
- Add real_nic_ip option/logic to support VMs with multiple bridge adapters
|
data/README.md
CHANGED
@@ -19,9 +19,9 @@ This provider is built on top of the
|
|
19
19
|
* libxml2, libxml2-dev, libxslt, libxslt-dev
|
20
20
|
|
21
21
|
## Current Version
|
22
|
-
**version: 1.
|
22
|
+
**version: 1.10.0**
|
23
23
|
|
24
|
-
vagrant-vsphere (**version: 1.
|
24
|
+
vagrant-vsphere (**version: 1.10.0**) is available from
|
25
25
|
[RubyGems.org](https://rubygems.org/gems/vagrant-vsphere)
|
26
26
|
|
27
27
|
## Installation
|
data/lib/vSphere/action.rb
CHANGED
@@ -176,6 +176,78 @@ module VagrantPlugins
|
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
179
|
+
# TODO: Remove the if guard when Vagrant 1.8.0 is the minimum version.
|
180
|
+
# rubocop:disable IndentationWidth
|
181
|
+
if Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('1.8.0')
|
182
|
+
def self.action_snapshot_delete
|
183
|
+
Vagrant::Action::Builder.new.tap do |b|
|
184
|
+
b.use ConfigValidate
|
185
|
+
b.use ConnectVSphere
|
186
|
+
b.use Call, IsCreated do |env, b2|
|
187
|
+
if env[:result]
|
188
|
+
b2.use SnapshotDelete
|
189
|
+
else
|
190
|
+
b2.use MessageNotCreated
|
191
|
+
end
|
192
|
+
end
|
193
|
+
b.use CloseVSphere
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def self.action_snapshot_list
|
198
|
+
Vagrant::Action::Builder.new.tap do |b|
|
199
|
+
b.use ConfigValidate
|
200
|
+
b.use ConnectVSphere
|
201
|
+
b.use Call, IsCreated do |env, b2|
|
202
|
+
if env[:result]
|
203
|
+
b2.use SnapshotList
|
204
|
+
else
|
205
|
+
b2.use MessageNotCreated
|
206
|
+
end
|
207
|
+
end
|
208
|
+
b.use CloseVSphere
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def self.action_snapshot_restore
|
213
|
+
Vagrant::Action::Builder.new.tap do |b|
|
214
|
+
b.use ConfigValidate
|
215
|
+
b.use ConnectVSphere
|
216
|
+
b.use Call, IsCreated do |env, b2|
|
217
|
+
unless env[:result]
|
218
|
+
b2.use MessageNotCreated
|
219
|
+
next
|
220
|
+
end
|
221
|
+
|
222
|
+
b2.use SnapshotRestore
|
223
|
+
b2.use Call, IsEnvSet, :snapshot_delete do |env2, b3|
|
224
|
+
# Used by vagrant push/pop
|
225
|
+
b3.use action_snapshot_delete if env2[:result]
|
226
|
+
end
|
227
|
+
|
228
|
+
b2.use action_up
|
229
|
+
end
|
230
|
+
b.use CloseVSphere
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def self.action_snapshot_save
|
235
|
+
Vagrant::Action::Builder.new.tap do |b|
|
236
|
+
b.use ConfigValidate
|
237
|
+
b.use ConnectVSphere
|
238
|
+
b.use Call, IsCreated do |env, b2|
|
239
|
+
if env[:result]
|
240
|
+
b2.use SnapshotSave
|
241
|
+
else
|
242
|
+
b2.use MessageNotCreated
|
243
|
+
end
|
244
|
+
end
|
245
|
+
b.use CloseVSphere
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end # Vagrant > 1.8.0 guard
|
249
|
+
# rubocop:enable IndentationWidth
|
250
|
+
|
179
251
|
# autoload
|
180
252
|
action_root = Pathname.new(File.expand_path('../action', __FILE__))
|
181
253
|
autoload :Clone, action_root.join('clone')
|
@@ -191,6 +263,16 @@ module VagrantPlugins
|
|
191
263
|
autoload :MessageNotRunning, action_root.join('message_not_running')
|
192
264
|
autoload :PowerOff, action_root.join('power_off')
|
193
265
|
autoload :PowerOn, action_root.join('power_on')
|
266
|
+
|
267
|
+
# TODO: Remove the if guard when Vagrant 1.8.0 is the minimum version.
|
268
|
+
# rubocop:disable IndentationWidth
|
269
|
+
if Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('1.8.0')
|
270
|
+
autoload :SnapshotDelete, action_root.join('snapshot_delete')
|
271
|
+
autoload :SnapshotList, action_root.join('snapshot_list')
|
272
|
+
autoload :SnapshotRestore, action_root.join('snapshot_restore')
|
273
|
+
autoload :SnapshotSave, action_root.join('snapshot_save')
|
274
|
+
end
|
275
|
+
# rubocop:enable IndentationWidth
|
194
276
|
end
|
195
277
|
end
|
196
278
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'vSphere/util/vim_helpers'
|
2
|
+
require 'vSphere/util/vm_helpers'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module VSphere
|
6
|
+
module Action
|
7
|
+
class SnapshotDelete
|
8
|
+
include Util::VimHelpers
|
9
|
+
include Util::VmHelpers
|
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
|
+
env[:ui].info(I18n.t(
|
19
|
+
"vagrant.actions.vm.snapshot.deleting",
|
20
|
+
name: env[:snapshot_name]))
|
21
|
+
|
22
|
+
delete_snapshot(vm, env[:snapshot_name]) do |progress|
|
23
|
+
env[:ui].clear_line
|
24
|
+
env[:ui].report_progress(progress, 100, false)
|
25
|
+
end
|
26
|
+
|
27
|
+
env[:ui].clear_line
|
28
|
+
|
29
|
+
env[:ui].info(I18n.t(
|
30
|
+
"vagrant.actions.vm.snapshot.deleted",
|
31
|
+
name: env[:snapshot_name]))
|
32
|
+
|
33
|
+
@app.call env
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'vSphere/util/vim_helpers'
|
2
|
+
require 'vSphere/util/vm_helpers'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module VSphere
|
6
|
+
module Action
|
7
|
+
class SnapshotList
|
8
|
+
include Util::VimHelpers
|
9
|
+
include Util::VmHelpers
|
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
|
+
env[:machine_snapshot_list] = enumerate_snapshots(vm).map(&:name)
|
19
|
+
|
20
|
+
@app.call env
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'vSphere/util/vim_helpers'
|
2
|
+
require 'vSphere/util/vm_helpers'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module VSphere
|
6
|
+
module Action
|
7
|
+
class SnapshotRestore
|
8
|
+
include Util::VimHelpers
|
9
|
+
include Util::VmHelpers
|
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
|
+
env[:ui].info(I18n.t(
|
19
|
+
"vagrant.actions.vm.snapshot.restoring",
|
20
|
+
name: env[:snapshot_name]))
|
21
|
+
|
22
|
+
restore_snapshot(vm, env[:snapshot_name]) do |progress|
|
23
|
+
env[:ui].clear_line
|
24
|
+
env[:ui].report_progress(progress, 100, false)
|
25
|
+
end
|
26
|
+
|
27
|
+
env[:ui].clear_line
|
28
|
+
|
29
|
+
@app.call env
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'vSphere/util/vim_helpers'
|
2
|
+
require 'vSphere/util/vm_helpers'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module VSphere
|
6
|
+
module Action
|
7
|
+
class SnapshotSave
|
8
|
+
include Util::VimHelpers
|
9
|
+
include Util::VmHelpers
|
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
|
+
env[:ui].info(I18n.t(
|
19
|
+
"vagrant.actions.vm.snapshot.saving",
|
20
|
+
name: env[:snapshot_name]))
|
21
|
+
|
22
|
+
create_snapshot(vm, env[:snapshot_name]) do |progress|
|
23
|
+
env[:ui].clear_line
|
24
|
+
env[:ui].report_progress(progress, 100, false)
|
25
|
+
end
|
26
|
+
|
27
|
+
env[:ui].clear_line
|
28
|
+
|
29
|
+
env[:ui].success(I18n.t(
|
30
|
+
"vagrant.actions.vm.snapshot.saved",
|
31
|
+
name: env[:snapshot_name]))
|
32
|
+
@app.call env
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module VSphere
|
3
|
+
module Cap
|
4
|
+
module SnapshotList
|
5
|
+
# Returns a list of the snapshots that are taken on this machine.
|
6
|
+
#
|
7
|
+
# @return [Array<String>] Snapshot Name
|
8
|
+
def self.snapshot_list(machine)
|
9
|
+
env = machine.action(:snapshot_list, lock: false)
|
10
|
+
env[:machine_snapshot_list]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/vSphere/plugin.rb
CHANGED
@@ -35,6 +35,16 @@ module VagrantPlugins
|
|
35
35
|
Cap::PublicAddress
|
36
36
|
end
|
37
37
|
|
38
|
+
# TODO: Remove the if guard when Vagrant 1.8.0 is the minimum version.
|
39
|
+
# rubocop:disable IndentationWidth
|
40
|
+
if Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('1.8.0')
|
41
|
+
provider_capability('vsphere', 'snapshot_list') do
|
42
|
+
require_relative 'cap/snapshot_list'
|
43
|
+
Cap::SnapshotList
|
44
|
+
end
|
45
|
+
end
|
46
|
+
# rubocop:enable IndentationWidth
|
47
|
+
|
38
48
|
def self.setup_i18n
|
39
49
|
I18n.load_path << File.expand_path('locales/en.yml', VSphere.source_root)
|
40
50
|
I18n.reload!
|
@@ -33,6 +33,127 @@ module VagrantPlugins
|
|
33
33
|
def suspended?(vm)
|
34
34
|
get_vm_state(vm).eql?(VmState::SUSPENDED)
|
35
35
|
end
|
36
|
+
|
37
|
+
# Enumerate VM snapshot tree
|
38
|
+
#
|
39
|
+
# This method returns an enumerator that performs a depth-first walk
|
40
|
+
# of the VM snapshot grap and yields each VirtualMachineSnapshotTree
|
41
|
+
# node.
|
42
|
+
#
|
43
|
+
# @param vm [RbVmomi::VIM::VirtualMachine]
|
44
|
+
#
|
45
|
+
# @return [Enumerator<RbVmomi::VIM::VirtualMachineSnapshotTree>]
|
46
|
+
def enumerate_snapshots(vm)
|
47
|
+
snapshot_info = vm.snapshot
|
48
|
+
|
49
|
+
if snapshot_info.nil?
|
50
|
+
snapshot_root = []
|
51
|
+
else
|
52
|
+
snapshot_root = snapshot_info.rootSnapshotList
|
53
|
+
end
|
54
|
+
|
55
|
+
recursor = lambda do |snapshot_list|
|
56
|
+
Enumerator.new do |yielder|
|
57
|
+
snapshot_list.each do |s|
|
58
|
+
# Yield the current VirtualMachineSnapshotTree object
|
59
|
+
yielder.yield s
|
60
|
+
|
61
|
+
# Recurse into child VirtualMachineSnapshotTree objects
|
62
|
+
children = recursor.call(s.childSnapshotList)
|
63
|
+
loop do
|
64
|
+
yielder.yield children.next
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
recursor.call(snapshot_root)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Create a named snapshot on a given VM
|
74
|
+
#
|
75
|
+
# This method creates a named snapshot on the given VM. This method
|
76
|
+
# blocks until the snapshot creation task is complete. An optional
|
77
|
+
# block can be passed which is used to report progress.
|
78
|
+
#
|
79
|
+
# @param vm [RbVmomi::VIM::VirtualMachine]
|
80
|
+
# @param name [String]
|
81
|
+
# @yield [Integer] Percentage complete as an integer. Called multiple
|
82
|
+
# times.
|
83
|
+
#
|
84
|
+
# @return [void]
|
85
|
+
def create_snapshot(vm, name)
|
86
|
+
task = vm.CreateSnapshot_Task(
|
87
|
+
name: name,
|
88
|
+
memory: false,
|
89
|
+
quiesce: false)
|
90
|
+
|
91
|
+
if block_given?
|
92
|
+
task.wait_for_progress do |progress|
|
93
|
+
yield progress unless progress.nil?
|
94
|
+
end
|
95
|
+
else
|
96
|
+
task.wait_for_completion
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Delete a named snapshot on a given VM
|
101
|
+
#
|
102
|
+
# This method deletes a named snapshot on the given VM. This method
|
103
|
+
# blocks until the snapshot deletion task is complete. An optional
|
104
|
+
# block can be passed which is used to report progress.
|
105
|
+
#
|
106
|
+
# @param vm [RbVmomi::VIM::VirtualMachine]
|
107
|
+
# @param name [String]
|
108
|
+
# @yield [Integer] Percentage complete as an integer. Called multiple
|
109
|
+
# times.
|
110
|
+
#
|
111
|
+
# @return [void]
|
112
|
+
def delete_snapshot(vm, name)
|
113
|
+
snapshot = enumerate_snapshots(vm).find { |s| s.name == name }
|
114
|
+
|
115
|
+
# No snapshot matching "name"
|
116
|
+
return nil if snapshot.nil?
|
117
|
+
|
118
|
+
task = snapshot.snapshot.RemoveSnapshot_Task(removeChildren: false)
|
119
|
+
|
120
|
+
if block_given?
|
121
|
+
task.wait_for_progress do |progress|
|
122
|
+
yield progress unless progress.nil?
|
123
|
+
end
|
124
|
+
else
|
125
|
+
task.wait_for_completion
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# Restore a VM to a named snapshot
|
130
|
+
#
|
131
|
+
# This method restores a VM to the named snapshot state. This method
|
132
|
+
# blocks until the restoration task is complete. An optional block can
|
133
|
+
# be passed which is used to report progress.
|
134
|
+
#
|
135
|
+
# @param vm [RbVmomi::VIM::VirtualMachine]
|
136
|
+
# @param name [String]
|
137
|
+
# @yield [Integer] Percentage complete as an integer. Called multiple
|
138
|
+
# times.
|
139
|
+
#
|
140
|
+
# @return [void]
|
141
|
+
def restore_snapshot(vm, name)
|
142
|
+
snapshot = enumerate_snapshots(vm).find { |s| s.name == name }
|
143
|
+
|
144
|
+
# No snapshot matching "name"
|
145
|
+
return nil if snapshot.nil?
|
146
|
+
|
147
|
+
task = snapshot.snapshot.RevertToSnapshot_Task(suppressPowerOn: true)
|
148
|
+
|
149
|
+
if block_given?
|
150
|
+
task.wait_for_progress do |progress|
|
151
|
+
yield progress unless progress.nil?
|
152
|
+
end
|
153
|
+
else
|
154
|
+
task.wait_for_completion
|
155
|
+
end
|
156
|
+
end
|
36
157
|
end
|
37
158
|
end
|
38
159
|
end
|
data/lib/vSphere/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-vsphere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Grauch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -161,7 +161,12 @@ files:
|
|
161
161
|
- lib/vSphere/action/message_not_running.rb
|
162
162
|
- lib/vSphere/action/power_off.rb
|
163
163
|
- lib/vSphere/action/power_on.rb
|
164
|
+
- lib/vSphere/action/snapshot_delete.rb
|
165
|
+
- lib/vSphere/action/snapshot_list.rb
|
166
|
+
- lib/vSphere/action/snapshot_restore.rb
|
167
|
+
- lib/vSphere/action/snapshot_save.rb
|
164
168
|
- lib/vSphere/cap/public_address.rb
|
169
|
+
- lib/vSphere/cap/snapshot_list.rb
|
165
170
|
- lib/vSphere/config.rb
|
166
171
|
- lib/vSphere/errors.rb
|
167
172
|
- lib/vSphere/plugin.rb
|
@@ -202,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
207
|
version: '0'
|
203
208
|
requirements: []
|
204
209
|
rubyforge_project:
|
205
|
-
rubygems_version: 2.
|
210
|
+
rubygems_version: 2.4.8
|
206
211
|
signing_key:
|
207
212
|
specification_version: 4
|
208
213
|
summary: VMWare vSphere provider
|