Commit 7397a70c authored by Srikanth Raju's avatar Srikanth Raju Committed by Leigh B Stoller

Some basic image importing scripts

parent f8e85f89
#!/usr/bin/perl -d:Trace [78/1805]
#
# Copyright (c) 2013 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
use English;
use Getopt::Std;
use strict;
# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
my $EXTRAFS = "/q/image-import";
my $TAR = "tar";
#
# Take a raw image and make a proper emulab image based off of it
#
sub usage()
{
print STDOUT "Usage: create-_ndz ". "<filename>\n";
exit(-1);
}
my $optlist = "";
#
# Turn off line buffering on output
#
$| = 1;
# Need this for predicates.
use libsetup;
#
# No configure vars.
#
my $sudo;
my $zipper = "/usr/local/bin/imagezip";
my $uploader = "/usr/local/etc/emulab/frisupload";
my $filename = "blah-uniqid.ndz";
my $iserver;
my $imageid;
my $error = 0;
for my $path (qw#/usr/local/bin /usr/bin#) {
if (-e "$path/sudo") {
$sudo = "$path/sudo";
last;
}
}
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (@ARGV != 2) {
usage();
}
my $hostaddress = $ARGV[0];
my $emulabtar = $ARGV[1];
#
# Untaint the arguments.
#
# Note different taint check (allow /).
#TODO UNTAINT
# SCP the in
# TODO: somefile that don't exist
print "$sudo scp -l ec2-user $hostaddress:$emulabtar $EXTRAFS/blah-uniqid.tar\n";
system("$sudo scp -i vhost-import ec2-user\@$hostaddress:$emulabtar $EXTRAFS/blah-uniqid.tar");
system("$sudo mkdir $EXTRAFS/blah-uniqid/");
# Unzip the thingy into extrafs
system("$sudo tar -xvzf $EXTRAFS/blah-uniqid.tar -C $EXTRAFS/blah-uniqid/");
# TODO: Proper sda size based on image size
# TODO: Maybe handle bootopts
# Create the "special" xm.conf
my $heredoc = <<XMCONF;
disksizes = 'sdb:2.00g,sda:12.00g'
memory = '256'
disk = ['phy:/dev/xen-vg/pcvm666-1,sda,w','phy:/dev/xen-vg/pcvm666.swap,sdb,w']
kernel = 'kernel'
ramdisk = 'initrd'
vif = ['mac=02:bf:bb:b9:ae:9c, ip=172.19.140.1, bridge=xenbr0']
name = 'pcvm666-1'
extra = 'root=/dev/sda boot_verbose=1 vfs.root.mountfrom=ufs:/dev/da0a kern.bootfile=/boot/kernel/kernel console=xvc0 selinux=0'
XMCONF
open(FH, '>', "$EXTRAFS/blah-uniqid/xm.conf") or goto cleanup;
print FH $heredoc;
close(FH);
# Image zip the raw image
if (system(("$sudo $zipper -o -l $EXTRAFS/blah-uniqid/tmp/image $EXTRAFS/blah-uniqid/sda"))) {
print STDERR "*** Failed to create image!\n";
print STDERR " command: '$sudo \n";
$error = 1;
}
# Tar everything up and then imagezip
my $cmd = "$TAR zcf - -C $EXTRAFS/blah-uniqid sda xm.conf kernel initrd | $zipper -f - $filename.ndz";
if (system("$sudo $cmd")) {
print STDERR "*** Failed to create image!\n";
print STDERR " command: '$sudo $cmd'\n";
$error = 1;
}
cleanup:
# Clean up the directory.
system("$sudo /bin/rm -rf $EXTRAFS/blah-uniqid");
#!/usr/bin/ruby
class EmulabExport
def finalize()
system("rm -Rf ec2-ami-tools-1.4.0.9")
system("rm ec2-ami-tools.zip")
end
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
system("wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip")
raise "Failed untaring ec2-utils" unless
system("unzip ec2-ami-tools.zip")
$: << Dir.pwd + "/ec2-ami-tools-1.4.0.9/lib/"
require 'ec2/platform/current'
excludes = ['/tmp/image', '/dev', '/media', '/mnt', '/proc', '/sys', '/', '/proc/sys/fs/binfmt_misc', '/dev/pts']
image = EC2::Platform::Current::Image.new("/",
"/tmp/image",
10* 1024,
excludes,
[],
true,
nil,
true)
image.make
end
def get_kernel()
version_crap = `uname -a`
version = version_crap.split[2]
if File.exists?("/boot/vmlinuz-" + version)
system("cp /boot/vmlinuz-" + version + " kernel")
end
if File.exists?("/boot/initramfs-" + version + ".img")
system("cp /boot/initramfs-" + version + ".img initrd")
end
end
def get_bootopts()
system("cat /proc/cmdline > bootopts")
end
def gen_tar()
system("tar -cvzf emulab.tar.gz /tmp/image kernel initrd bootopts")
end
def inject_pubkey()
f = File.new(File.expand_path("~") + "/.ssh/authorized_keys", "a+")
f.write("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyHww/vuwQ4adLRzUCKdP5/DubwWJjg/YcGwumuHB24Y0u53KX0qd3oprntw0o/ngntlKXdmAuQ/9lb74Vqpoy0LFVU7adPhNRj1z6WbvRo4cwt5BUBxWlTLQFKs3118kATAkMSKFZbXs54y7GvyFWPTdrgfquEizSaKaPcT3Un0FjWobmK81B7etfSZaaD8fMyWuUHHKYq67ZKDJUc4URRHLMZR
IHk7wzbMBV0MEeR7y3se1vBKQDV4IzsTnQF4Mur0HBBc2Kif9oDFh8pykatslvSSjAc8J/t9Lp1RADxon3LHX7TFbvHEgAt0t9g8udOOtw4vB7t9l2VrgV5ZLuw== jetru@myboss.metadata.utahstud.emulab.net\n")
f.close
end
end
if __FILE__ == $0
ex = EmulabExport.new()
ex.create_image
ex.get_kernel
ex.get_bootopts
ex.gen_tar
ex.inject_pubkey
end
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAyHww/vuwQ4adLRzUCKdP5/DubwWJjg/YcGwumuHB24Y0u53K
X0qd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DzgpvOPcAK6UAVFJgjqBIHIPGiS/Ie
zvB+4dDtDkNh0fmhffAFo4Cp9jDsRcCgbBtQLhIlvrIi2lO5nTAZCs/XBU95bN7K
I/7nefJ6lUF3OFUMVk7DAoGBAJY4aIOhuMJCypWLTYwCsXex9T+8dGZYNJC6eO4w
/l4JmbnnYUgFB6Rq4/5FF46FJaZEG/HuFgxL7cOp/vEvcmf88H4tA8ZFk0M7Oobt
1Wjm8kxg3shb8EkhCaFQ8YJgVZBCIDyPZTVTCcDhWryhqUOhdbV7GlfKeXCvU+IY
hxr7AoGBAOBTzeOqaPNlFlqjMuamNN4KIKVSa9EQtKJ29++GkjEM8BBO+vt8u0jP
VbkIUbRUxLX8VmSBnKz9gKsW6xAOetWKmVU8u7hDSANlZlLLVBX0noJuUwTk11MC
wLxjxeiVN8IG0l/TSxbzbCrklw8Bh9khFuynAaad/0j3hkK89AaR
-----END RSA PRIVATE KEY-----
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyHww/vuwQ4adLRzUCKdP5/DubwWJjg/YcGwumuHB24Y0u53KX0qd3oprntw0o/ngntlKXdmAuQ/9lb74Vqpoy0LFVU7adPhNRj1z6WbvRo4cwt5BUBxWlTLQFKs3118kATAkMSKFZbXs54y7GvyFWPTdrgfquEizSaKaPcT3Un0FjWobmK81B7etfSZaaD8fMyWuUHHKYq67ZKDJUc4URRHLMZRIHk7wzbMBV0MEeR7y3se1vBKQDV4IzsTnQF4Mur0HBBc2Kif9oDFh8pykatslvSSjAc8J/t9Lp1RADxon3LHX7TFbvHEgAt0t9g8udOOtw4vB7t9l2VrgV5ZLuw== jetru@myboss.metadata.utahstud.emulab.net
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