sahara 0.0.1
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/.gitignore +6 -0
- data/.rvmrc +5 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +48 -0
- data/README.md +19 -0
- data/Rakefile +5 -0
- data/lib/sahara.rb +2 -0
- data/lib/sahara/command.rb +33 -0
- data/lib/sahara/session.rb +178 -0
- data/lib/sahara/shell.rb +58 -0
- data/lib/sahara/version.rb +3 -0
- data/lib/vagrant_init.rb +6 -0
- data/sahara.gemspec +27 -0
- metadata +145 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sahara (0.0.1)
|
5
|
+
popen4 (~> 0.1.2)
|
6
|
+
thor (~> 0.14.6)
|
7
|
+
vagrant (~> 0.7.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
Platform (0.4.0)
|
13
|
+
abstract (1.0.0)
|
14
|
+
archive-tar-minitar (0.5.2)
|
15
|
+
erubis (2.6.6)
|
16
|
+
abstract (>= 1.0.0)
|
17
|
+
ffi (0.6.3)
|
18
|
+
rake (>= 0.8.7)
|
19
|
+
i18n (0.5.0)
|
20
|
+
json (1.5.1)
|
21
|
+
mario (0.0.6)
|
22
|
+
net-scp (1.0.4)
|
23
|
+
net-ssh (>= 1.99.1)
|
24
|
+
net-ssh (2.1.4)
|
25
|
+
open4 (1.0.1)
|
26
|
+
popen4 (0.1.2)
|
27
|
+
Platform (>= 0.4.0)
|
28
|
+
open4 (>= 0.4.0)
|
29
|
+
rake (0.8.7)
|
30
|
+
thor (0.14.6)
|
31
|
+
vagrant (0.7.3)
|
32
|
+
archive-tar-minitar (= 0.5.2)
|
33
|
+
erubis (~> 2.6.6)
|
34
|
+
i18n (~> 0.5.0)
|
35
|
+
json (~> 1.5.1)
|
36
|
+
mario (~> 0.0.6)
|
37
|
+
net-scp (~> 1.0.4)
|
38
|
+
net-ssh (~> 2.1.0)
|
39
|
+
thor (~> 0.14.6)
|
40
|
+
virtualbox (~> 0.8.3)
|
41
|
+
virtualbox (0.8.3)
|
42
|
+
ffi (~> 0.6.3)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
sahara!
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Description
|
2
|
+
|
3
|
+
Sahara allows vagrant to operate in sandbox mode
|
4
|
+
|
5
|
+
Typical usage:
|
6
|
+
|
7
|
+
- Enter sandbox mode: <pre>vagrant sandbox on</pre>
|
8
|
+
- Do some stuff: <pre>vagrant ssh </pre>
|
9
|
+
- If satisfied apply the changes: <pre>vagrant sandbox commit</pre>
|
10
|
+
- If not satisfied you can rollback: <pre>vagrant sandbox rollback</pre>
|
11
|
+
- To leave sandbox mod: <pre>vagrant sandbox off</pre>
|
12
|
+
|
13
|
+
Many kudos go to the creators of [vagrant](http://vagrantup.com)
|
14
|
+
|
15
|
+
# Installation
|
16
|
+
|
17
|
+
This is now available as gem:
|
18
|
+
|
19
|
+
<pre>gem install sahara</pre>
|
data/Rakefile
ADDED
data/lib/sahara.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'sahara/session'
|
2
|
+
|
3
|
+
module Sahara
|
4
|
+
class Command < Vagrant::Command::GroupBase
|
5
|
+
register "sandbox","Manages a sandbox"
|
6
|
+
|
7
|
+
desc "status [NAME]", "Shows the status of the sandbox"
|
8
|
+
def status(boxname=nil)
|
9
|
+
Sahara::Session.status(boxname)
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "on [NAME]", "Enters sandbox state"
|
13
|
+
def on(boxname=nil)
|
14
|
+
Sahara::Session.on(boxname)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "commit [NAME]", "Commits changes - moves sandbox initial state to currentstate"
|
18
|
+
def commit(boxname=nil)
|
19
|
+
Sahara::Session.commit(boxname)
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "rollback [NAME]", "Rollback changes since sandbox state was entered "
|
23
|
+
def rollback(boxname=nil)
|
24
|
+
Sahara::Session.rollback(boxname)
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "off [NAME] ", "Leaves sandbox state"
|
28
|
+
def off(boxname=nil)
|
29
|
+
Sahara::Session.off(boxname)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'pp'
|
2
|
+
|
3
|
+
require 'drift/shell'
|
4
|
+
|
5
|
+
module Drift
|
6
|
+
module Session
|
7
|
+
|
8
|
+
def self.determine_vboxcmd
|
9
|
+
return "VBoxManage"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.initialize
|
13
|
+
@vagrant_env=Vagrant::Environment.new
|
14
|
+
@vboxcmd=determine_vboxcmd
|
15
|
+
@sandboxname="drift-sandbox"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.status(selection)
|
19
|
+
self.initialize
|
20
|
+
|
21
|
+
on_selected_vms(selection) do |boxname|
|
22
|
+
if is_snapshot_mode_on?(boxname)
|
23
|
+
puts "[#{boxname}] - snapshot mode is on"
|
24
|
+
else
|
25
|
+
puts "[#{boxname}] - snapshot mode is off"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.on(selection)
|
32
|
+
self.initialize
|
33
|
+
|
34
|
+
on_selected_vms(selection) do |boxname|
|
35
|
+
if is_snapshot_mode_on?(boxname)
|
36
|
+
puts "[#{boxname}] - snapshot mode is already on"
|
37
|
+
else
|
38
|
+
instance_name="#{@vagrant_env.vms[boxname.to_sym].vm.name}"
|
39
|
+
|
40
|
+
#Creating a snapshot
|
41
|
+
puts "[#{boxname}] - Enabling sandbox"
|
42
|
+
|
43
|
+
execute("#{@vboxcmd} snapshot '#{instance_name}' take '#{@sandboxname}'")
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.commit(selection)
|
50
|
+
|
51
|
+
self.initialize
|
52
|
+
on_selected_vms(selection) do |boxname|
|
53
|
+
|
54
|
+
|
55
|
+
if !is_snapshot_mode_on?(boxname)
|
56
|
+
puts "[#{boxname}] - this requires that sandbox mode is on."
|
57
|
+
else
|
58
|
+
instance_name="#{@vagrant_env.vms[boxname.to_sym].vm.name}"
|
59
|
+
|
60
|
+
#Discard snapshot so current state is the latest state
|
61
|
+
puts "[#{boxname}] - unwinding sandbox"
|
62
|
+
execute("#{@vboxcmd} snapshot '#{instance_name}' delete '#{@sandboxname}'")
|
63
|
+
|
64
|
+
#Now retake the snapshot
|
65
|
+
puts "[#{boxname}] - fastforwarding sandbox"
|
66
|
+
|
67
|
+
execute("#{@vboxcmd} snapshot '#{instance_name}' take '#{@sandboxname}'")
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.rollback(selection)
|
76
|
+
self.initialize
|
77
|
+
|
78
|
+
on_selected_vms(selection) do |boxname|
|
79
|
+
|
80
|
+
if !is_snapshot_mode_on?(boxname)
|
81
|
+
puts "[#{boxname}] - this requires that sandbox mode is on."
|
82
|
+
else
|
83
|
+
instance_name="#{@vagrant_env.vms[boxname.to_sym].vm.name}"
|
84
|
+
|
85
|
+
puts "[#{boxname}] - powering off machine"
|
86
|
+
|
87
|
+
#Poweroff machine
|
88
|
+
execute("#{@vboxcmd} controlvm '#{instance_name}' poweroff")
|
89
|
+
|
90
|
+
puts "[#{boxname}] - roll back machine"
|
91
|
+
|
92
|
+
#Rollback until snapshot
|
93
|
+
execute("#{@vboxcmd} snapshot '#{instance_name}' restore '#{@sandboxname}'")
|
94
|
+
|
95
|
+
puts "[#{boxname}] - starting the machine again"
|
96
|
+
|
97
|
+
#Startvm again
|
98
|
+
execute("#{@vboxcmd} startvm --type headless '#{instance_name}' ")
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.off(selection)
|
108
|
+
self.initialize
|
109
|
+
|
110
|
+
on_selected_vms(selection) do |boxname|
|
111
|
+
|
112
|
+
|
113
|
+
instance_name="#{@vagrant_env.vms[boxname.to_sym].vm.name}"
|
114
|
+
|
115
|
+
if !is_snapshot_mode_on?(boxname)
|
116
|
+
puts "[#{boxname}] - this requires that sandbox mode is on."
|
117
|
+
else
|
118
|
+
puts "[#{boxname}] - switching sandbox off"
|
119
|
+
|
120
|
+
# We might wanna check for sandbox changes or not
|
121
|
+
|
122
|
+
#Discard snapshot
|
123
|
+
execute("#{@vboxcmd} snapshot '#{instance_name}' delete '#{@sandboxname}' ")
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.execute(command)
|
131
|
+
#puts "#{command}"
|
132
|
+
output=Sahara::Shell.execute("#{command}")
|
133
|
+
return output
|
134
|
+
end
|
135
|
+
|
136
|
+
def self.is_vm_created?(boxname)
|
137
|
+
return !@vagrant_env.vms[boxname.to_sym].vm.nil?
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.list_snapshots(boxname)
|
141
|
+
|
142
|
+
instance_name="#{@vagrant_env.vms[boxname.to_sym].vm.name}"
|
143
|
+
snapshotlist=Array.new
|
144
|
+
snapshotresult=execute("#{@vboxcmd} showvminfo --machinereadable '#{instance_name}' |grep ^SnapshotName| cut -d '=' -f 2")
|
145
|
+
snapshotresult.each do |result|
|
146
|
+
clean=result.gsub(/\"/,'').chomp
|
147
|
+
snapshotlist << clean
|
148
|
+
end
|
149
|
+
return snapshotlist
|
150
|
+
end
|
151
|
+
|
152
|
+
def self.is_snapshot_mode_on?(boxname)
|
153
|
+
snapshots=list_snapshots(boxname)
|
154
|
+
return snapshots.include?(@sandboxname)
|
155
|
+
end
|
156
|
+
|
157
|
+
def self.on_selected_vms(selection,&block)
|
158
|
+
if selection.nil?
|
159
|
+
#puts "no selection was done"
|
160
|
+
@vagrant_env.vms.each do |name,vm|
|
161
|
+
#puts "Processing #{name}"
|
162
|
+
yield name
|
163
|
+
end
|
164
|
+
else
|
165
|
+
yield selection
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
#command="#{@vboxcmd} unregistervm '#{boxname}' --delete"
|
173
|
+
#puts command
|
174
|
+
#puts "Deleting vm #{boxname}"
|
175
|
+
|
176
|
+
#Exec and system stop the execution here
|
177
|
+
#Veewee::Shell.execute("#{command}")
|
178
|
+
|
data/lib/sahara/shell.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#require 'open4'
|
2
|
+
|
3
|
+
module Sahara
|
4
|
+
class Shell
|
5
|
+
|
6
|
+
def self.execute(command,options = {})
|
7
|
+
STDOUT.sync = true
|
8
|
+
output=nil
|
9
|
+
result=IO.popen("#{command}") {|f| output=f.readlines}
|
10
|
+
#{ |f| print "#{f}, #{f.class}" }
|
11
|
+
# output=result.read
|
12
|
+
return output
|
13
|
+
end
|
14
|
+
|
15
|
+
#pty allows you to gradually see the output of a local command
|
16
|
+
#http://www.shanison.com/?p=415
|
17
|
+
def self.execute2(command, options = {} )
|
18
|
+
require "pty"
|
19
|
+
begin
|
20
|
+
PTY.spawn( command ) do |r, w, pid|
|
21
|
+
begin
|
22
|
+
#r.each { }
|
23
|
+
r.each { |line| print line;}
|
24
|
+
|
25
|
+
rescue Errno::EIO
|
26
|
+
end
|
27
|
+
end
|
28
|
+
rescue PTY::ChildExited => e
|
29
|
+
puts "The child process exited!"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
#occassinally fails with 'no child processes
|
34
|
+
def self.execute3(command, options = {} )
|
35
|
+
defaults= { :port => "22", :exitcode => "0", :user => "root"}
|
36
|
+
options=defaults.merge(options)
|
37
|
+
|
38
|
+
status = POpen4::popen4(command) do |stdout,stderr,stdin|
|
39
|
+
stdout.each do |line|
|
40
|
+
puts line
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
@status=status.to_i
|
45
|
+
|
46
|
+
if (@status.to_s != options[:exitcode] )
|
47
|
+
if (options[:exitcode]=="*")
|
48
|
+
#its a test so we don't need to worry
|
49
|
+
else
|
50
|
+
raise "Exitcode was not what we expected"
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end #Class
|
58
|
+
end #Module
|
data/lib/vagrant_init.rb
ADDED
data/sahara.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/sahara/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "sahara"
|
6
|
+
s.version = Sahara::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Patrick Debois"]
|
9
|
+
s.email = ["patrick.debois@jedi.be"]
|
10
|
+
s.homepage = "http://github.com/jedi4ever/sahara/"
|
11
|
+
s.summary = %q{Vagrant box creation}
|
12
|
+
s.description = %q{Allows you to sandbox your vagrant}
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "sahara"
|
16
|
+
|
17
|
+
s.add_dependency "vagrant", "~> 0.7.0"
|
18
|
+
s.add_dependency "popen4", "~> 0.1.2"
|
19
|
+
s.add_dependency "thor", "~> 0.14.6"
|
20
|
+
|
21
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
22
|
+
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
25
|
+
s.require_path = 'lib'
|
26
|
+
end
|
27
|
+
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sahara
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Patrick Debois
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-28 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 7
|
31
|
+
- 0
|
32
|
+
version: 0.7.0
|
33
|
+
type: :runtime
|
34
|
+
requirement: *id001
|
35
|
+
name: vagrant
|
36
|
+
prerelease: false
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 31
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
- 1
|
47
|
+
- 2
|
48
|
+
version: 0.1.2
|
49
|
+
type: :runtime
|
50
|
+
requirement: *id002
|
51
|
+
name: popen4
|
52
|
+
prerelease: false
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 43
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
- 14
|
63
|
+
- 6
|
64
|
+
version: 0.14.6
|
65
|
+
type: :runtime
|
66
|
+
requirement: *id003
|
67
|
+
name: thor
|
68
|
+
prerelease: false
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 23
|
76
|
+
segments:
|
77
|
+
- 1
|
78
|
+
- 0
|
79
|
+
- 0
|
80
|
+
version: 1.0.0
|
81
|
+
type: :development
|
82
|
+
requirement: *id004
|
83
|
+
name: bundler
|
84
|
+
prerelease: false
|
85
|
+
description: Allows you to sandbox your vagrant
|
86
|
+
email:
|
87
|
+
- patrick.debois@jedi.be
|
88
|
+
executables: []
|
89
|
+
|
90
|
+
extensions: []
|
91
|
+
|
92
|
+
extra_rdoc_files: []
|
93
|
+
|
94
|
+
files:
|
95
|
+
- .gitignore
|
96
|
+
- .rvmrc
|
97
|
+
- Gemfile
|
98
|
+
- Gemfile.lock
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- lib/sahara.rb
|
102
|
+
- lib/sahara/command.rb
|
103
|
+
- lib/sahara/session.rb
|
104
|
+
- lib/sahara/shell.rb
|
105
|
+
- lib/sahara/version.rb
|
106
|
+
- lib/vagrant_init.rb
|
107
|
+
- sahara.gemspec
|
108
|
+
has_rdoc: true
|
109
|
+
homepage: http://github.com/jedi4ever/sahara/
|
110
|
+
licenses: []
|
111
|
+
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: 3
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 23
|
132
|
+
segments:
|
133
|
+
- 1
|
134
|
+
- 3
|
135
|
+
- 6
|
136
|
+
version: 1.3.6
|
137
|
+
requirements: []
|
138
|
+
|
139
|
+
rubyforge_project: sahara
|
140
|
+
rubygems_version: 1.4.2
|
141
|
+
signing_key:
|
142
|
+
specification_version: 3
|
143
|
+
summary: Vagrant box creation
|
144
|
+
test_files: []
|
145
|
+
|