Permalink
Browse files

Snapshots get taken now after each step:

- 0 for initial install
- 1... for each script provided in the postinstall

Soon we will be able to resume a state when a script fails. This should ease debugging postinstallation stuff
  • Loading branch information...
1 parent 1fc34fa commit 495234db7801236575ba87f8f45054e9f3fab544 @jedi4ever committed Nov 14, 2010
View
@@ -1,5 +1,6 @@
-ENV['GEM_PATH']=File.join(File.dirname(__FILE__),"gems")
-ENV['GEM_HOME']=File.join(File.dirname(__FILE__),"gems")
+#We set this in the ENV file
+#ENV['GEM_PATH']=File.join(File.dirname(__FILE__),"gems")
+#ENV['GEM_HOME']=File.join(File.dirname(__FILE__),"gems")
def check_environment
begin
@@ -34,6 +35,8 @@ template_dir=File.expand_path(File.join(veewee_dir, "templates"))
vbox_dir=File.expand_path(File.join(veewee_dir, "tmp"))
tmp_dir=File.expand_path(File.join(veewee_dir, "tmp"))
iso_dir=File.expand_path(File.join(veewee_dir, "iso"))
+
+#needs to be moved to the config files to be allowed override
ENV['VBOX_USER_HOME']=vbox_dir
#Load Veewee::Session libraries
View
@@ -44,6 +44,8 @@ def self.vagrant(boxname,boxdir,definition)
Veewee::Shell.execute("#{export_command}") #hmm, needs to get the gem_home set?
puts
+ #add_ssh_nat_mapping back!!!!
+
puts "To import it into vagrant type:"
puts "vagrant box add '#{boxname}' '#{box_path}'"
puts ""
View
@@ -1,3 +1,4 @@
+require 'digest/md5'
require 'socket'
require 'net/scp'
@@ -154,7 +155,10 @@ def self.build(boxname)
verify_iso(@definition[:iso_file])
- transaction(boxname,"initial","initial") do
+ checksum= Digest::MD5.hexdigest(@definition.to_s)
+ puts "Initial: #{checksum}"
+
+ transaction(boxname,"0-initial",checksum) do
#Create the Virtualmachine and set all the memory and other stuff
create_vm(boxname)
@@ -188,9 +192,10 @@ def self.build(boxname)
#snapshot initial stuff
end
end #initial Transaction
+
Veewee::Ssh.when_ssh_login_works("localhost",ssh_options) do
-
+
#Transfer version of Virtualbox to $HOME/.vbox_version
versionfile=File.join(@tmp_dir,".vbox_version")
File.open(versionfile, 'w') {|f| f.write("#{VirtualBox::Global.global.lib.virtualbox.version}") }
@@ -199,8 +204,9 @@ def self.build(boxname)
counter=0
@definition[:postinstall_files].each do |postinstall_file|
- filename=File.join(@definition_dir,boxname,postinstall_file)
- transaction(boxname,"#{counter}-#{filename}","postinstall") do
+ filename=File.join(@definition_dir,boxname,postinstall_file)
+ checksum= Digest::MD5.hexdigest(File.read(filename))
+ transaction(boxname,"#{counter}-#{filename}",checksum) do
Veewee::Ssh.transfer_file("localhost",filename,ssh_options)
command=@definition[:sudo_cmd]
@@ -381,11 +387,20 @@ def self.local_ip
Socket.do_not_reverse_lookup = orig
end
- def self.transaction(boxname,name,checksum_params, &block)
- if checksum_params=="initial2"
- puts "skipping"
+ def self.transaction(boxname,name,checksum, &block)
+ vm=VirtualBox::VM.find(boxname)
+ if vm.nil?
+ #this is our first installation
+ yield
+ end
+ if vm.find_snapshot(name+"-"+checksum)
+ puts "skipping - snapshot already there"
else
+ #check if we have older snapshots (otherwise delete them)
yield
+ puts "taking snapshot #{boxname}-#{name}-#{checksum}"
+ vm.take_snapshot(name+"-"+checksum,"created by veewee")
+ vm.reload
end
end
View
@@ -5,25 +5,25 @@ def transaction(name,params, &block)
end
def transaction2(name,options= { :checksum => "nochecksum"}, &block)
- if @provider.snapshot_exists(@vmname,name+"-"+options[:checksum])
- @provider.load_snapshot_vmachine(@vmname,name+"-"+options[:checksum])
+ if snapshot_exists(@vmname,name+"-"+options[:checksum])
+ load_snapshot_vmachine(@vmname,name+"-"+options[:checksum])
else
- if @provider.snapshot_version_exists(@vmname,name)
- @provider.rollback_snapshot(@vmname,name)
+ if snapshot_version_exists(@vmname,name)
+ rollback_snapshot(@vmname,name)
#rollback to snapshot prior to this one
end
yield
- @provider.create_snapshot_vmachine(@vmname,name+"-"+options[:checksum])
+ create_snapshot_vmachine(@vmname,name+"-"+options[:checksum])
end
#end
end
def self.remove_snapshot_vmachine(vmname,snapname)
- Shellutil.execute("VBoxManage snapshot '#{vmname}' delete '#{snapname}'")
+ Veewee::Shell.execute("VBoxManage snapshot '#{vmname}' delete '#{snapname}'")
end
def self.create_snapshot_vmachine(vmname,snapname)
- Shellutil.execute("VBoxManage snapshot '#{vmname}' take '#{snapname}'")
+ Veewee::Shell.execute("VBoxManage snapshot '#{vmname}' take '#{snapname}'")
end
def self.load_snapshot_vmachine(vmname,snapname)
@@ -32,10 +32,10 @@ def self.load_snapshot_vmachine(vmname,snapname)
stop_vmachine(vmname)
end
- Shellutil.execute("VBoxManage snapshot '#{vmname}' restore '#{snapname}'")
+ Veewee::Shell.execute("VBoxManage snapshot '#{vmname}' restore '#{snapname}'")
#sometimes it takes some time to shutdown
sleep 2
- Shellutil.execute("VBoxManage startvm '#{vmname}'")
+ Veewee::Shell.execute("VBoxManage startvm '#{vmname}'")
end
def self.snapshot_exists(vmname,snapname)
@@ -61,7 +61,7 @@ def self.rollback_snapshot(vmname,snapname)
savestate_recover=false
if (state_vmachine(vmname)=="running")
- Shellutil.execute("VBoxManage controlvm '#{vmname}' savestate")
+ Veewee::Shell.execute("VBoxManage controlvm '#{vmname}' savestate")
savestate_recover=true
end
@@ -77,17 +77,17 @@ def self.rollback_snapshot(vmname,snapname)
sleep 2
- Shellutil.execute("VBoxManage startvm '#{vmname}'")
+ Veewee::Shell.execute("VBoxManage startvm '#{vmname}'")
if (savestate_recover)
#Recovering from savestate nukes the network! This trick seem to work
#Also within the vm /etc/init.d/networking restart , but that is OS specific
#http://www.virtualbox.org/ticket/5666
#http://www.virtualbox.org/ticket/5654
#This is supposed to be fixed: http://www.virtualbox.org/changeset/25205 but alas
- Shellutil.execute("VBoxManage controlvm '#{vmname}' nic1 nat")
- Shellutil.execute("VBoxManage controlvm '#{vmname}' setlinkstate1 off")
- Shellutil.execute("VBoxManage controlvm '#{vmname}' setlinkstate1 on")
+ Veewee::Shell.execute("VBoxManage controlvm '#{vmname}' nic1 nat")
+ Veewee::Shell.execute("VBoxManage controlvm '#{vmname}' setlinkstate1 off")
+ Veewee::Shell.execute("VBoxManage controlvm '#{vmname}' setlinkstate1 on")
sleep 2
#hmmm, virtualbox => when recovering from a restore , it looses the nat settings!!! So we need to do this again!!
@@ -101,7 +101,7 @@ def self.rollback_snapshot(vmname,snapname)
def self.list_snapshots(vmname)
- snapshotresult=Shellutil.execute("VBoxManage showvminfo --machinereadable '#{vmname}' |grep ^SnapshotName| cut -d '=' -f 2").stdout
+ snapshotresult=Veewee::Shell.execute("VBoxManage showvminfo --machinereadable '#{vmname}' |grep ^SnapshotName| cut -d '=' -f 2").stdout
snapshotlist=snapshotresult.gsub(/\"/,'').split(/\n/)
return snapshotlist
end
@@ -23,7 +23,7 @@ rm ruby-enterprise-1.8.7-2010.02.tar.gz
#Installing vagrant keys
mkdir /home/vagrant/.ssh
-chmod 600 /home/vagrant/.ssh
+chmod 700 /home/vagrant/.ssh
cd /home/vagrant/.ssh
wget --no-check-certificate 'http://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub' -O authorized_keys
chown -R vagrant /home/vagrant/.ssh
@@ -21,10 +21,9 @@ rm ruby-enterprise-1.8.7-2010.02.tar.gz
#Installing chef
/opt/ruby/bin/gem install chef
-
#Installing vagrant keys
mkdir /home/vagrant/.ssh
-chmod 600 /home/vagrant/.ssh
+chmod 700 /home/vagrant/.ssh
cd /home/vagrant/.ssh
wget --no-check-certificate 'http://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub' -O authorized_keys
chown -R vagrant /home/vagrant/.ssh

0 comments on commit 495234d

Please sign in to comment.