vagrant-snap 0.01
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/LICENSE.txt +20 -0
- data/Manifest +7 -0
- data/README.md +25 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/lib/vagrant_init.rb +6 -0
- data/lib/vagrant_snap.rb +99 -0
- data/vagrant-snap.gemspec +35 -0
- metadata +109 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 t9md
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
What's this?
|
2
|
+
==================================
|
3
|
+
vagrant snapshot management plugin
|
4
|
+
|
5
|
+
## install
|
6
|
+
|
7
|
+
gem install vagrant-snap
|
8
|
+
|
9
|
+
## following commands are added
|
10
|
+
|
11
|
+
Tasks:
|
12
|
+
vagrant snap back # back to current snapshot
|
13
|
+
vagrant snap delete SNAP_NAME # delete snapshot
|
14
|
+
vagrant snap go SNAP_NAME # go to specified snapshot
|
15
|
+
vagrant snap help [COMMAND] # Describe subcommands or one specific subcommand
|
16
|
+
vagrant snap list # list snapshot
|
17
|
+
vagrant snap take [desc] # take snapshot
|
18
|
+
|
19
|
+
## limitation
|
20
|
+
|
21
|
+
Currently multi-vm environment is not supported
|
22
|
+
|
23
|
+
## Similar project
|
24
|
+
|
25
|
+
[sahara](https://github.com/jedi4ever/sahara)
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
include Rake::DSL
|
3
|
+
|
4
|
+
require 'echoe'
|
5
|
+
Echoe.new "vagrant-snap", File.read("./VERSION").chomp do |p|
|
6
|
+
p.author = "t9md"
|
7
|
+
p.email = "taqumd@gmail.com"
|
8
|
+
p.summary = %Q{vagrant snapshot managemen plugin}
|
9
|
+
p.project = nil
|
10
|
+
p.url = "http://github.com/t9md/vagrant-snap"
|
11
|
+
p.runtime_dependencies << 'vagrant'
|
12
|
+
p.runtime_dependencies << 'colored'
|
13
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.01
|
data/lib/vagrant_init.rb
ADDED
data/lib/vagrant_snap.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require "colored"
|
2
|
+
|
3
|
+
module Snap
|
4
|
+
module VBox
|
5
|
+
class SnapShot #{{{
|
6
|
+
@@snaps = []
|
7
|
+
class << self
|
8
|
+
def is_endnode?() @@current.uuid == @@snaps.last.uuid end
|
9
|
+
|
10
|
+
def snaps() @@snaps end
|
11
|
+
|
12
|
+
def parse_tree(vmname)
|
13
|
+
vm = VirtualBox::VM.find( vmname )
|
14
|
+
@@current = vm.current_snapshot
|
15
|
+
return unless @@current
|
16
|
+
_parse(vm.root_snapshot)
|
17
|
+
end
|
18
|
+
|
19
|
+
# [TODO] need refactoring
|
20
|
+
def time_elapse(time)
|
21
|
+
_sec = 1
|
22
|
+
_min = _sec * 60
|
23
|
+
_hour = _min * 60
|
24
|
+
_day = _hour * 24
|
25
|
+
|
26
|
+
sec = time.to_i
|
27
|
+
min = sec / _min
|
28
|
+
hour = sec / _hour
|
29
|
+
day = sec / _day
|
30
|
+
|
31
|
+
case
|
32
|
+
when day > 0 then "#{day} day#{day == 1 ? '' : 's'}"
|
33
|
+
when hour > 0 then "#{hour} hour#{hour == 1 ? '' : 's'}"
|
34
|
+
when min > 0 then "#{min} minute#{min == 1 ? '' : 's'}"
|
35
|
+
when sec > 0 then "#{sec} second#{sec == 1 ? '' : 's'}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def _parse(snaps, level=0)
|
40
|
+
@@snaps << snaps.name
|
41
|
+
# time = snaps.time_stamp.strftime "%m%d-%H:%M"
|
42
|
+
time = time_elapse(Time.now - snaps.time_stamp)
|
43
|
+
result = "#{' ' * level}+-#{snaps.name} [ #{time} ]"
|
44
|
+
result << " #{snaps.description}" unless snaps.description.empty?
|
45
|
+
result = result.yellow if snaps.uuid == @@current.uuid
|
46
|
+
result << "\n"
|
47
|
+
snaps.children.each do |e|
|
48
|
+
result << _parse(e, level+1)
|
49
|
+
end
|
50
|
+
result
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end #}}}
|
54
|
+
end
|
55
|
+
class Command < Vagrant::Command::GroupBase
|
56
|
+
register "snap","Manages a snap"
|
57
|
+
|
58
|
+
no_tasks {
|
59
|
+
def vmname
|
60
|
+
@vagrant_env ||= Vagrant::Environment.new
|
61
|
+
@instance_name ||= "#{@vagrant_env.vms[:default].vm.name}"
|
62
|
+
@instance_name
|
63
|
+
end
|
64
|
+
}
|
65
|
+
|
66
|
+
desc "list", "list snapshot"
|
67
|
+
def list
|
68
|
+
result = VBox::SnapShot.parse_tree( vmname )
|
69
|
+
puts result ? result : "no snapshot"
|
70
|
+
end
|
71
|
+
|
72
|
+
desc "go SNAP_NAME", "go to specified snapshot"
|
73
|
+
def go(snapshot_name)
|
74
|
+
system "VBoxManage controlvm #{vmname} poweroff"
|
75
|
+
system "VBoxManage snapshot #{vmname} restore #{snapshot_name}"
|
76
|
+
system "VBoxManage startvm #{vmname} --type headless"
|
77
|
+
end
|
78
|
+
|
79
|
+
desc "back", "back to current snapshot"
|
80
|
+
def back
|
81
|
+
system "VBoxManage controlvm #{vmname} poweroff"
|
82
|
+
system "VBoxManage snapshot #{vmname} restorecurrent"
|
83
|
+
system "VBoxManage startvm #{vmname} --type headless"
|
84
|
+
end
|
85
|
+
|
86
|
+
desc "take [desc]", "take snapshot"
|
87
|
+
def take(desc="")
|
88
|
+
VBox::SnapShot.parse_tree( vmname )
|
89
|
+
last_name = VBox::SnapShot.snaps.sort.reverse.first
|
90
|
+
new_name = last_name.nil? ? vmname + "-01" : last_name.succ
|
91
|
+
system "VBoxManage snapshot #{vmname} take #{new_name} --description '#{desc}' --pause"
|
92
|
+
end
|
93
|
+
|
94
|
+
desc "delete SNAP_NAME", "delete snapshot"
|
95
|
+
def delete(snapshot_name)
|
96
|
+
system "VBoxManage snapshot #{vmname} delete #{snapshot_name}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{vagrant-snap}
|
5
|
+
s.version = "0.01"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["t9md"]
|
9
|
+
s.date = %q{2011-06-06}
|
10
|
+
s.description = %q{vagrant snapshot managemen plugin}
|
11
|
+
s.email = %q{taqumd@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["LICENSE.txt", "README.md", "lib/vagrant_init.rb", "lib/vagrant_snap.rb"]
|
13
|
+
s.files = ["LICENSE.txt", "Manifest", "README.md", "VERSION", "lib/vagrant_init.rb", "lib/vagrant_snap.rb", "Rakefile", "vagrant-snap.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/t9md/vagrant-snap}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Vagrant-snap", "--main", "README.md"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubygems_version = %q{1.3.7}
|
18
|
+
s.summary = %q{vagrant snapshot managemen plugin}
|
19
|
+
|
20
|
+
if s.respond_to? :specification_version then
|
21
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
22
|
+
s.specification_version = 3
|
23
|
+
|
24
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
25
|
+
s.add_runtime_dependency(%q<vagrant>, [">= 0"])
|
26
|
+
s.add_runtime_dependency(%q<colored>, [">= 0"])
|
27
|
+
else
|
28
|
+
s.add_dependency(%q<vagrant>, [">= 0"])
|
29
|
+
s.add_dependency(%q<colored>, [">= 0"])
|
30
|
+
end
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<vagrant>, [">= 0"])
|
33
|
+
s.add_dependency(%q<colored>, [">= 0"])
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-snap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.01"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- t9md
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-06-06 00:00:00 +09:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: vagrant
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: colored
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
description: vagrant snapshot managemen plugin
|
49
|
+
email: taqumd@gmail.com
|
50
|
+
executables: []
|
51
|
+
|
52
|
+
extensions: []
|
53
|
+
|
54
|
+
extra_rdoc_files:
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- lib/vagrant_init.rb
|
58
|
+
- lib/vagrant_snap.rb
|
59
|
+
files:
|
60
|
+
- LICENSE.txt
|
61
|
+
- Manifest
|
62
|
+
- README.md
|
63
|
+
- VERSION
|
64
|
+
- lib/vagrant_init.rb
|
65
|
+
- lib/vagrant_snap.rb
|
66
|
+
- Rakefile
|
67
|
+
- vagrant-snap.gemspec
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://github.com/t9md/vagrant-snap
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options:
|
74
|
+
- --line-numbers
|
75
|
+
- --inline-source
|
76
|
+
- --title
|
77
|
+
- Vagrant-snap
|
78
|
+
- --main
|
79
|
+
- README.md
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 11
|
97
|
+
segments:
|
98
|
+
- 1
|
99
|
+
- 2
|
100
|
+
version: "1.2"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.3.7
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: vagrant snapshot managemen plugin
|
108
|
+
test_files: []
|
109
|
+
|