vagrant-snap 0.09 → 0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/vagrant_snap.rb +145 -87
- data/vagrant-snap.gemspec +4 -4
- metadata +6 -6
data/CHANGELOG
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'echoe'
|
|
5
5
|
Echoe.new "vagrant-snap", File.read("./VERSION").chomp do |p|
|
6
6
|
p.author = "t9md"
|
7
7
|
p.email = "taqumd@gmail.com"
|
8
|
-
p.summary = %Q{vagrant snapshot
|
8
|
+
p.summary = %Q{vagrant snapshot management plugin}
|
9
9
|
p.project = nil
|
10
10
|
p.url = "http://github.com/t9md/vagrant-snap"
|
11
11
|
p.ignore_pattern = ["misc/*"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.10
|
data/lib/vagrant_snap.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
require "virtualbox"
|
1
2
|
require "colored"
|
3
|
+
require "pp"
|
2
4
|
|
3
5
|
module Snap
|
4
6
|
module VBox
|
@@ -17,7 +19,7 @@ module Snap
|
|
17
19
|
|
18
20
|
def parse_tree(vmname)
|
19
21
|
init
|
20
|
-
vm = VirtualBox::VM.find( vmname )
|
22
|
+
vm = ::VirtualBox::VM.find( vmname )
|
21
23
|
@@current = vm.current_snapshot
|
22
24
|
return unless @@current
|
23
25
|
@@tree = _parse(vm.root_snapshot)
|
@@ -68,6 +70,16 @@ module Snap
|
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
73
|
+
def next_available_snapname
|
74
|
+
if lastname.nil?
|
75
|
+
"0"
|
76
|
+
else
|
77
|
+
n = lastname.succ
|
78
|
+
n = n.succ while VBox::SnapShot.include? n
|
79
|
+
n
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
71
83
|
def include?(name)
|
72
84
|
return false unless tree
|
73
85
|
tree.flatten.map(&:name).include? name
|
@@ -91,110 +103,156 @@ module Snap
|
|
91
103
|
end #}}}
|
92
104
|
end
|
93
105
|
|
94
|
-
class
|
95
|
-
|
106
|
+
class Snap < Vagrant::Command::Base
|
107
|
+
def help
|
108
|
+
puts <<-EOS
|
109
|
+
Usage: vagrant snap <subcommand> [options...]
|
96
110
|
|
97
|
-
|
98
|
-
|
99
|
-
|
111
|
+
subcommands are..
|
112
|
+
vagrant snap list
|
113
|
+
vagrant snap back
|
114
|
+
vagrant snap go <snapshot> [boxname]
|
115
|
+
vagrant snap take [TARGET] [-n SNAP_NAME] [-d DESC]"
|
116
|
+
vagrant snap delete <snapshot> [boxname]"
|
117
|
+
|
118
|
+
EOS
|
119
|
+
end
|
120
|
+
def execute# {{{
|
121
|
+
@main_args, @sub_command, @sub_args = split_main_and_subcommand(@argv)
|
122
|
+
# p [@main_args, @sub_command, @sub_args]
|
123
|
+
|
124
|
+
# sub_list = %w(list go back take delete test)
|
125
|
+
sub_list = %w(list go back take delete)
|
126
|
+
unless @sub_command
|
127
|
+
help
|
128
|
+
exit
|
129
|
+
end
|
130
|
+
if sub_list.include? @sub_command
|
131
|
+
send(@sub_command)
|
132
|
+
else
|
133
|
+
ui.warn "unkown command '#{@sub_command}'"
|
134
|
+
help
|
135
|
+
exit
|
100
136
|
end
|
137
|
+
end# }}}
|
101
138
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
vagvmname = vm.name
|
107
|
-
vmname = vm.vm.name
|
139
|
+
private
|
140
|
+
# def env
|
141
|
+
# @_env ||= Vagrant::Environment.new
|
142
|
+
# end
|
108
143
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
desc "list", "list snapshot"
|
119
|
-
def list(target=nil)
|
120
|
-
with_target(target) do |vmname, vagvmname|
|
121
|
-
puts "[#{vagvmname}]"
|
122
|
-
VBox::SnapShot.parse_tree( vmname )
|
123
|
-
if VBox::SnapShot.tree
|
124
|
-
result = VBox::SnapShot.show
|
125
|
-
else
|
126
|
-
result = "no snapshot"
|
144
|
+
def ui# {{{
|
145
|
+
@ui ||= ::Vagrant::UI::Colored.new("vagrant")
|
146
|
+
end# }}}
|
147
|
+
def safe_with_target_vms(target, &blk)# {{{
|
148
|
+
with_target_vms(target) do |vm|
|
149
|
+
unless vm.created?
|
150
|
+
@logger.info("not created yet: #{vm.name}")
|
151
|
+
next
|
127
152
|
end
|
128
|
-
puts
|
153
|
+
puts "[#{vm.name}]"
|
154
|
+
blk.call(vm)
|
129
155
|
end
|
130
|
-
end
|
156
|
+
end# }}}
|
157
|
+
def target_vmname# {{{
|
158
|
+
target = @sub_args.empty? ? nil : @sub_args.last.to_s
|
159
|
+
end# }}}
|
160
|
+
def exe(cmd)# {{{
|
161
|
+
puts "# exe: #{cmd}" if @exe_verbose
|
162
|
+
system cmd
|
163
|
+
end# }}}
|
131
164
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
165
|
+
def list# {{{
|
166
|
+
# options = {}
|
167
|
+
# opts = OptionParser.new { |opts| opts.banner = "vagrant snap list" }
|
168
|
+
# argv = parse_options(opts)
|
169
|
+
# # p argv
|
170
|
+
safe_with_target_vms(target_vmname) do |vm|
|
171
|
+
VBox::SnapShot.parse_tree( vm.uuid )
|
172
|
+
puts VBox::SnapShot.tree ? VBox::SnapShot.show : "no snapshot"
|
173
|
+
end
|
174
|
+
end# }}}
|
175
|
+
def go # {{{
|
176
|
+
options = {}
|
177
|
+
opts = OptionParser.new do |opts|
|
178
|
+
opts.banner = "Usage: vagrant snapt go <snapshot> [boxname]"
|
179
|
+
end
|
180
|
+
snapshot, target = *@sub_args
|
181
|
+
unless snapshot
|
182
|
+
puts opts.help
|
183
|
+
return
|
184
|
+
end
|
185
|
+
safe_with_target_vms(target) do |vm|
|
186
|
+
VBox::SnapShot.parse_tree( vm.uuid )
|
187
|
+
if VBox::SnapShot.include?( snapshot )
|
188
|
+
exe "VBoxManage controlvm '#{vm.uuid}' poweroff"
|
189
|
+
exe "VBoxManage snapshot '#{vm.uuid}' restore '#{snapshot}'"
|
190
|
+
exe "VBoxManage startvm '#{vm.uuid}' --type headless"
|
141
191
|
else
|
142
|
-
warn "#{
|
192
|
+
ui.warn "'#{snapshot}' is not exist"
|
143
193
|
end
|
144
194
|
end
|
145
|
-
end
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
195
|
+
end# }}}
|
196
|
+
def back# {{{
|
197
|
+
safe_with_target_vms(target_vmname) do |vm|
|
198
|
+
exe "VBoxManage controlvm '#{vm.uuid}' poweroff"
|
199
|
+
exe "VBoxManage snapshot '#{vm.uuid}' restorecurrent"
|
200
|
+
exe "VBoxManage startvm '#{vm.uuid}' --type headless"
|
201
|
+
end
|
202
|
+
end# }}}
|
203
|
+
def take# {{{
|
204
|
+
options = {}
|
205
|
+
opts = OptionParser.new do |opts|
|
206
|
+
opts.banner = "Usage: vagrant snap take [TARGET] [-n SNAP_NAME] [-d DESC]"
|
207
|
+
opts.on("-n", "--name STR", "Name of snapshot" ){ |v| options[:name] = v }
|
208
|
+
opts.on("-d", "--desc STR", "Description of snapshot"){ |v| options[:desc] = v }
|
154
209
|
end
|
155
|
-
end
|
156
210
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
211
|
+
begin
|
212
|
+
argv = parse_options(opts)
|
213
|
+
rescue OptionParser::MissingArgument
|
214
|
+
raise ::Vagrant::Errors::CLIInvalidOptions, :help => opts.help.chomp
|
215
|
+
end
|
216
|
+
return if !argv
|
217
|
+
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
|
218
|
+
# p @sub_args
|
219
|
+
# return
|
220
|
+
# snapshot, target = *@sub_args
|
221
|
+
safe_with_target_vms(target_vmname) do |vm|
|
222
|
+
VBox::SnapShot.parse_tree( vm.uuid )
|
223
|
+
if options[:name] and VBox::SnapShot.include? options[:name]
|
224
|
+
ui.warn "'#{options[:name]}' is already exist"
|
225
|
+
next
|
171
226
|
end
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
else
|
177
|
-
n = lastname.succ
|
178
|
-
n = n.succ while VBox::SnapShot.include? n
|
179
|
-
n
|
180
|
-
end
|
227
|
+
snapshot = options[:name] ? options[:name] : VBox::SnapShot.next_available_snapname
|
228
|
+
cmd = "VBoxManage snapshot '#{vm.uuid}' take '#{snapshot}' --pause"
|
229
|
+
if options[:desc]
|
230
|
+
cmd << " --description '#{options[:desc]}'"
|
181
231
|
end
|
182
|
-
|
183
|
-
system "VBoxManage snapshot '#{vmname}' take '#{new_name}' #{desc} --pause"
|
232
|
+
exe cmd
|
184
233
|
end
|
185
|
-
end
|
234
|
+
end# }}}
|
186
235
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
236
|
+
def delete# {{{
|
237
|
+
options = {}
|
238
|
+
opts = OptionParser.new do |opts|
|
239
|
+
opts.banner = "vagrant snap delete <snapshot> [boxname]"
|
240
|
+
end
|
241
|
+
snapshot, target = *@sub_args
|
242
|
+
unless snapshot
|
243
|
+
puts opts.help
|
244
|
+
return
|
245
|
+
end
|
246
|
+
snapshot, target = *@sub_args
|
247
|
+
safe_with_target_vms(target) do |vm|
|
248
|
+
VBox::SnapShot.parse_tree( vm.uuid )
|
249
|
+
if VBox::SnapShot.include?( snapshot )
|
250
|
+
exe "VBoxManage snapshot '#{vm.uuid}' delete '#{snapshot}'"
|
194
251
|
else
|
195
|
-
warn "#{
|
252
|
+
ui.warn "'#{snapshot}' is not exist"
|
196
253
|
end
|
197
254
|
end
|
198
|
-
end
|
255
|
+
end# }}}
|
199
256
|
end
|
200
257
|
end
|
258
|
+
Vagrant.commands.register(:snap) { ::Snap::Snap }
|
data/vagrant-snap.gemspec
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{vagrant-snap}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.10"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["t9md"]
|
9
|
-
s.date = %q{
|
10
|
-
s.description = %q{vagrant snapshot
|
9
|
+
s.date = %q{2012-01-26}
|
10
|
+
s.description = %q{vagrant snapshot management plugin}
|
11
11
|
s.email = %q{taqumd@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["LICENSE.txt", "README.md", "CHANGELOG", "lib/vagrant_init.rb", "lib/vagrant_snap.rb"]
|
13
13
|
s.files = ["LICENSE.txt", "Manifest", "README.md", "Rakefile", "VERSION", "CHANGELOG", "lib/vagrant_init.rb", "lib/vagrant_snap.rb", "vagrant-snap.gemspec"]
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Vagrant-snap", "--main", "README.md"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubygems_version = %q{1.3.7}
|
18
|
-
s.summary = %q{vagrant snapshot
|
18
|
+
s.summary = %q{vagrant snapshot management plugin}
|
19
19
|
|
20
20
|
if s.respond_to? :specification_version then
|
21
21
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-snap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 10
|
9
|
+
version: "0.10"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- t9md
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2012-01-26 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
version: "0"
|
46
46
|
type: :runtime
|
47
47
|
version_requirements: *id002
|
48
|
-
description: vagrant snapshot
|
48
|
+
description: vagrant snapshot management plugin
|
49
49
|
email: taqumd@gmail.com
|
50
50
|
executables: []
|
51
51
|
|
@@ -106,6 +106,6 @@ rubyforge_project:
|
|
106
106
|
rubygems_version: 1.3.7
|
107
107
|
signing_key:
|
108
108
|
specification_version: 3
|
109
|
-
summary: vagrant snapshot
|
109
|
+
summary: vagrant snapshot management plugin
|
110
110
|
test_files: []
|
111
111
|
|