Commit 5abc2b82 authored by Srikanth Raju's avatar Srikanth Raju Committed by Leigh B Stoller

Some error handling in export script

parent af9ed869
...@@ -3,18 +3,14 @@ ...@@ -3,18 +3,14 @@
class EmulabExport class EmulabExport
def finalize() def finalize()
system("rm -Rf ec2-ami-tools-1.4.0.9") system("rm -Rf ec2-ami-tools-1.4.0.9 > /dev/null 2>&1")
system("rm ec2-ami-tools.zip") system("rm ec2-ami-tools.zip > /dev/null 2>&1")
end end
def create_image() def create_image()
raise 'Must run as root' unless Process.uid == 0
ObjectSpace.define_finalizer(self, self.method(:finalize))
raise "Failed fetching ec2-utils" unless raise "Failed fetching ec2-utils" unless
system("wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip") system("wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip")
raise "Failed untaring ec2-utils" unless raise "Failed unzippinging ec2-utils" unless
system("unzip ec2-ami-tools.zip") system("unzip ec2-ami-tools.zip")
$: << Dir.pwd + "/ec2-ami-tools-1.4.0.9/lib/" $: << Dir.pwd + "/ec2-ami-tools-1.4.0.9/lib/"
...@@ -22,53 +18,70 @@ class EmulabExport ...@@ -22,53 +18,70 @@ class EmulabExport
excludes = ['/tmp/image', '/dev', '/media', '/mnt', '/proc', '/sys', '/', '/proc/sys/fs/binfmt_misc', '/dev/pts'] excludes = ['/tmp/image', '/dev', '/media', '/mnt', '/proc', '/sys', '/', '/proc/sys/fs/binfmt_misc', '/dev/pts']
image = EC2::Platform::Current::Image.new("/", image = EC2::Platform::Current::Image.new("/",
"/tmp/image", "/tmp/image",
10* 1024, 10* 1024,
excludes, excludes,
[], [],
true, true,
nil, nil,
true) true)
image.make image.make
end end
def check_prereqs()
raise "No unzip found. Please install unzip" unless system("command -v fo >/dev/null 2>&1")
end
def get_kernel() def get_kernel()
version_crap = `uname -a` version = `uname -a`
version = version_crap.split[2] version = version.split[2]
if File.exists?("/boot/vmlinuz-" + version) if File.exists?("/boot/vmlinuz-" + version)
system("cp /boot/vmlinuz-" + version + " kernel") raise "Couldn't copy kernel" unless
system("cp /boot/vmlinuz-" + version + " kernel")
end end
if File.exists?("/boot/initramfs-" + version + ".img") if File.exists?("/boot/initramfs-" + version + ".img")
system("cp /boot/initramfs-" + version + ".img initrd") raise "Couldn't copy initramfs" unless
system("cp /boot/initramfs-" + version + ".img initrd")
end end
end end
def get_bootopts() def get_bootopts()
system("cat /proc/cmdline > bootopts") raise "Couldn't get bootopts" unless
system("cat /proc/cmdline > bootopts")
end end
def gen_tar() def gen_tar()
system("tar -cvzf emulab.tar.gz /tmp/image kernel initrd bootopts") raise "Couldn't tar" unless
system("tar -cvzf emulab.tar.gz kernel initrd bootopts -C /tmp/ image 2>&1")
end end
#TODO: Perhaps pull this from a specific emulab server, auto generate
def inject_pubkey() def inject_pubkey()
f = File.new(File.expand_path("~") + "/.ssh/authorized_keys", "a+") f = File.new(File.expand_path("~") + "/.ssh/authorized_keys", "a+")
f.write("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyHww/vuwQ4adLRzUCKdP5/DubwWJjg/YcGwumuHB24Y0u53KX0qd3oprntw0o/ngntlKXdmAuQ/9lb74Vqpoy0LFVU7adPhNRj1z6WbvRo4cwt5BUBxWlTLQFKs3118kATAkMSKFZbXs54y7GvyFWPTdrgfquEizSaKaPcT3Un0FjWobmK81B7etfSZaaD8fMyWuUHHKYq67ZKDJUc4URRHLMZR f.write("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyHww/vuwQ4adLRzUCKdP5/DubwWJjg/YcGwumuHB24Y0u53KX0qd3oprntw0o/ngntlKXdmAuQ/9lb74Vqpoy0LFVU7adPhNRj1z6WbvRo4cwt5BUBxWlTLQFKs3118kATAkMSKFZbXs54y7GvyFWPTdrgfquEizSaKaPcT3Un0FjWobmK81B7etfSZaaD8fMyWuUHHKYq67ZKDJUc4URRHLMZRIHk7wzbMBV0MEeR7y3se1vBKQDV4IzsTnQF4Mur0HBBc2Kif9oDFh8pykatslvSSjAc8J/t9Lp1RADxon3LHX7TFbvHEgAt0t9g8udOOtw4vB7t9l2VrgV5ZLuw== jetru@myboss.metadata.utahstud.emulab.net\n")
IHk7wzbMBV0MEeR7y3se1vBKQDV4IzsTnQF4Mur0HBBc2Kif9oDFh8pykatslvSSjAc8J/t9Lp1RADxon3LHX7TFbvHEgAt0t9g8udOOtw4vB7t9l2VrgV5ZLuw== jetru@myboss.metadata.utahstud.emulab.net\n")
f.close f.close
end end
end end
if __FILE__ == $0 if __FILE__ == $0
raise 'Must run as root' unless Process.uid == 0
ex = EmulabExport.new() ex = EmulabExport.new()
ex.create_image begin
ex.get_kernel ex.check_prereqs
ex.get_bootopts ex.create_image
ex.gen_tar ex.get_kernel
ex.inject_pubkey ex.get_bootopts
ex.gen_tar
ex.inject_pubkey
rescue Exception => e
print "Error while creating an image: ", e, "\n"
ensure
ex.finalize()
end
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment