Commit 057205ef authored by Srikanth Raju's avatar Srikanth Raju Committed by Leigh B Stoller
Browse files

Remove old files

parent 3768c21d
#!/usr/bin/perl -d:Trace
#
# 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; }
#
# Take a raw image and make a proper emulab image based off of it
#
sub usage()
{
print STDOUT "Usage: create_ndz <project> <user> <osid>";
exit(-1);
}
my $optlist = "";
#
# Turn off line buffering on output
#
$| = 1;
# Need this for predicates.
use libsetup;
#
# No configure vars.
#
my $WORK_BASE = "/q/import_temp/";
my $IN_BASE = "/q/indir/";
#TODO something in some script that creates these two directories
my $TAR = "tar";
my $sudo;
my $zipper = "/usr/local/bin/imagezip";
my $uploader = "/usr/local/etc/emulab/frisupload";
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 != 3) {
usage();
}
my $project = $ARGV[0];
my $user = $ARGV[1];
my $osid = $ARGV[2];
my $infile = $IN_BASE . $project . "/" . $user . "/" . $osid . ".tar.gz";
my $workdir = $WORK_BASE . $project . "/" . $user . "/" . $osid . "-tmp";
#
# Untaint the arguments.
#
# Note different taint check (allow /).
#TODO UNTAINT
if (! -e $infile){
print STDERR "*** Input tar image not found.\n";
print STDERR "Looking for:" . $infile . "\n";
goto cleanup;
}
# Unzip into the working dir
system("mkdir -p $workdir");
system("tar -xvzf $infile -C $workdir");
# 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, '>', "$workdir/xm.conf") or goto cleanup;
print FH $heredoc;
close(FH);
# Image zip the raw image
if (system("$zipper -o -l $workdir/image $workdir/sda")) {
print STDERR "*** Failed to greate image!\n";
print STDERR " command: $zipper -o -l $workdir/image $workdir/sda";
$error = 1;
}
# Tar everything up and then imagezip
my $cmd = "$TAR zcf - -C $workdir sda xm.conf kernel initrd | $zipper -f - $osid.ndz";
if (system("$cmd")) {
print STDERR "*** Failed to create image!\n";
print STDERR " command: '$cmd'\n";
$error = 1;
goto cleanup;
}
cleanup:
# Clean up the directory.
system("$sudo /bin/rm -rf $workdir");
#!/usr/bin/ruby
class EmulabExport
attr_accessor :identity
def initialize()
@target = "~~SERVER~~" + ":" + "~~IN_DIR~~" + "~~IN_FILE~~"
@user = "~~USER~~"
@identity = nil
end
def finalize()
system("rm -Rf ec2-ami-tools-1.4.0.9 > /dev/null 2>&1")
system("rm ec2-ami-tools.zip > /dev/null 2>&1")
end
def create_image()
raise "Failed fetching ec2-utils" unless
system("wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip")
raise "Failed unzippinging 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 check_prereqs()
raise "No unzip found. Please install unzip" unless system("command -v unzip >/dev/null 2>&1")
end
def get_kernel()
version = `uname -a`
version = version.split[2]
if File.exists?("/boot/vmlinuz-" + version)
raise "Couldn't copy kernel" unless
system("cp /boot/vmlinuz-" + version + " kernel")
end
if File.exists?("/boot/initramfs-" + version + ".img")
raise "Couldn't copy initramfs" unless
system("cp /boot/initramfs-" + version + ".img initrd")
end
end
def get_bootopts()
raise "Couldn't get bootopts" unless
system("cat /proc/cmdline > bootopts")
end
def gen_tar()
raise "Couldn't tar" unless
system("tar -cvzf emulab.tar.gz kernel initrd bootopts -C /tmp/ image 2>&1")
end
#TODO: Perhaps pull this from a specific emulab server, auto generate
def inject_pubkey()
f = File.new(File.expand_path("~") + "/.ssh/authorized_keys", "a+")
f.write("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyHww/vuwQ4adLRzUCKdP5/DubwWJjg/YcGwumuHB24Y0u53KX0qd3oprntw0o/ngntlKXdmAuQ/9lb74Vqpoy0LFVU7adPhNRj1z6WbvRo4cwt5BUBxWlTLQFKs3118kATAkMSKFZbXs54y7GvyFWPTdrgfquEizSaKaPcT3Un0FjWobmK81B7etfSZaaD8fMyWuUHHKYq67ZKDJUc4URRHLMZRIHk7wzbMBV0MEeR7y3se1vBKQDV4IzsTnQF4Mur0HBBc2Kif9oDFh8pykatslvSSjAc8J/t9Lp1RADxon3LHX7TFbvHEgAt0t9g8udOOtw4vB7t9l2VrgV5ZLuw== jetru@myboss.metadata.utahstud.emulab.net\n")
f.close
end
def push_to_emulab()
if @identity == nil
cmd = "scp emulab.tar.gz " + @user + "@" + @target
else
cmd = "scp -i " + @identity + " emulab.tar.gz " + @user + "@" + @target
end
puts "Transferring tarred file with: " + cmd
if system(cmd) == false
puts "scp failed with error code " + $?.to_s
puts "You might want to rerun the push using a SSH keyfile using -i"
puts "Also use the -p flag to only attempt the file transfer and no recreate the image"
end
end
end
if __FILE__ == $0
raise 'Must run as root' unless Process.uid == 0
ex = EmulabExport.new()
pushonly = false
require 'getoptlong'
#Parse options
opts = GetoptLong.new(
['--identity', '-i', GetoptLong::REQUIRED_ARGUMENT],
['--push-only', '-p', GetoptLong::NO_ARGUMENT]
)
opts.each do |opt, arg|
case opt
when '--identity'
ex.identity = arg
when '--push-only'
pushonly = true
end
end
begin
if pushonly == false
ex.check_prereqs
ex.create_image
ex.get_kernel
ex.get_bootopts
ex.gen_tar
end
ex.push_to_emulab
rescue Exception => e
print "Error while creating an image: \n"
puts e.message
print e.backtrace.join("\n")
ensure
ex.finalize()
end
end
#!/usr/bin/perl -d:Trace
#
# 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;
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
use libtestbed;
sub usage()
{
print STDOUT "Usage: generate-export.pl <outfile> <out_file>";
exit(-1);
}
if (@ARGV != 2){
usage();
}
my $osid = $ARGV[0];
$osid =~ "s/\//\\\/g";
my $out = `who`;
my ($user) = split /\s+/, $out;
#TODO: Depends on who is running this script on ops...runasuser() thingy???
#TODO - find the correct ops node and pull in and shit from some sane config
system("sed 's/~~SERVER~~/myops.metadata.utahstud.emulab.net/' < export-template.rb | sed 's/~~IN_DIR~~/\\/q\\/indir\\//' | sed 's/~~IN_FILE~~/$osid/' | sed 's/~~USER~~/$user/' > $ARGV[1]");}
#!/usr/bin/perl -d:Trace
#
# 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; }
#
# Take a raw image and make a proper emulab image based off of it
#
sub usage()
{
print STDOUT "Usage: import-image remote-user remote-addr project user osid";
exit(-1);
}
my $optlist = "";
#
# Turn off line buffering on output
#
$| = 1;
# Need this for predicates.
use libsetup;
#
# No configure vars.
#
my $WORK_BASE = "/q/import_temp/";
my $IN_BASE = "/q/indir/";
#TODO something in some script that creates these two directories
my $TAR = "tar";
my $sudo;
my $zipper = "/usr/local/bin/imagezip";
my $uploader = "/usr/local/etc/emulab/frisupload";
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 != 5) {
usage();
}
my $ruser = $ARGV[0];
my $remote = $ARGV[1];
my $project = $ARGV[2];
my $user = $ARGV[3];
my $osid = $ARGV[4];
my $infile = $IN_BASE . $project . "/" . $user . "/" . $osid . ".tar.gz";
my $workdir = $WORK_BASE . $project . "/" . $user . "/" . $osid . "-tmp";
# Man, this really needs some exception handling
if(system("ssh -t -t -l $ruser $remote 'mkdir ~/.emulab'")){
print STDERR "Couldn't mkdir ~/.emulab";
goto cleanup;
}
# Remotely execute the export script
if(system("scp export-template-remote.rb $ruser\@$remote:~/.emulab/export.rb")){
print STDERR "Couldn't scp exporter script into $remote\n";
goto cleanup;
}
if(system("ssh -t -t -l $ruser $remote 'sudo ruby < ~/.emulab/export.rb'")){
print STDERR "Remote image creation failed\n";
goto cleanup;
}
# SCP back the generated image file
# TODO Saner name for tar and .emulab?
if(system("scp $ruser\@$remote:~/.emulab/emulab.tar.gz $infile")){
print STDERR "Couldn't scp image back into ops\n";
goto cleanup;
}
# Process the tar blah image
if (! -e $infile){
print STDERR "*** Input tar image not found.\n";
print STDERR "Looking for:" . $infile . "\n";
goto cleanup;
}
# Unzip into the working dir
if (system("mkdir -p $workdir")){
print STDERR "Couldn't mkdir $workdir \n";
goto cleanup;
}
if (system("tar -xvzf $infile -C $workdir")){
print STDERR "Failed to extract $infile \n";
goto cleanup;
}
my $filesize = ceil((-s "$workdir/image")/(1024*1024*1024));
$filesize = $filesize + 4;
# TODO: Proper xvda1 size based on image size?
# TODO: Maybe handle bootopts
# Create the "special" xm.conf
my $heredoc = <<XMCONF;
disksizes = 'xvda2:2.00g,xvda1:$filesize.00g'
memory = '256'
disk = ['phy:/dev/xen-vg/pcvm666-1,xvda1,w','phy:/dev/xen-vg/pcvm666.swap,xvda2,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/xvda1 boot_verbose=1 vfs.root.mountfrom=ufs:/dev/da0a kern.bootfile=/boot/kernel/kernel console=xvc0 selinux=0'
XMCONF
open(FH, '>', "$workdir/xm.conf") or goto cleanup;
print FH $heredoc;
close(FH);
# Image zip the raw image
if (system("$zipper -o -l $workdir/image $workdir/xvda1")) {
print STDERR "*** Failed to greate image!\n";
print STDERR " command: $zipper -o -l $workdir/image $workdir/xvda1\n";
}
# Tar everything up and then imagezip
my $cmd = "$TAR zcf - -C $workdir xvda1 xm.conf kernel initrd | $zipper -f - $osid.ndz";
if (system("$cmd")) {
print STDERR "*** Failed to create image!\n";
print STDERR " command: '$cmd'\n";
goto cleanup;
}
cleanup:
# Clean up the directory.
print STDOUT "Performing cleanup...\n";
system("$sudo /bin/rm -rf $workdir 2>/dev/null");
system("ssh -t -t -l $ruser $remote 'rm -Rf ~/.emulab'");
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