From 4df776d0b3eb19ff7555b7f74f9ae0505621b218 Mon Sep 17 00:00:00 2001 From: Leigh B Stoller Date: Thu, 8 Apr 2010 13:55:03 -0600 Subject: [PATCH] New script to dump an imageid or and osid, in the same format that the web interfaces feeds to backend/newosid and newimageid. The idea is to use this to dump and load the base IDs on a new emulab installation. --- utils/GNUmakefile.in | 5 +- utils/dumpdescriptor.in | 211 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 utils/dumpdescriptor.in diff --git a/utils/GNUmakefile.in b/utils/GNUmakefile.in index 98a36d4ec..22b5c1e2e 100644 --- a/utils/GNUmakefile.in +++ b/utils/GNUmakefile.in @@ -1,6 +1,6 @@ # # EMULAB-COPYRIGHT -# Copyright (c) 2000-2009 University of Utah and the Flux Group. +# Copyright (c) 2000-2010 University of Utah and the Flux Group. # All rights reserved. # @@ -24,7 +24,8 @@ SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \ grabswitchconfig backupswitches cvsinit checkquota \ spewconlog opsdb_control newnode suchown archive_list \ wanodecheckin wanodecreate spewimage \ - anonsendmail epmodeset fixexpinfo node_traffic + anonsendmail epmodeset fixexpinfo node_traffic \ + dumpdescriptor WEB_SBIN_SCRIPTS= webnewnode webdeletenode webspewconlog webarchive_list \ webwanodecheckin webspewimage diff --git a/utils/dumpdescriptor.in b/utils/dumpdescriptor.in new file mode 100644 index 000000000..3519160bb --- /dev/null +++ b/utils/dumpdescriptor.in @@ -0,0 +1,211 @@ +#!/usr/bin/perl -w +# +# EMULAB-COPYRIGHT +# Copyright (c) 2010 University of Utah and the Flux Group. +# All rights reserved. +# +use English; +use strict; +use Getopt::Std; +use CGI; +use Data::Dumper; + +# +# Dump an EZ descriptor out. +# +sub usage() +{ + print("Usage: dumpimage [-d] [-i ] | [-o ] \n"); + exit(-1); +} +my $optlist = "di:o:"; +my $debug = 0; + +# +# Configure variables +# +my $TB = "@prefix@"; +my $TBOPS = "@TBOPSEMAIL@"; +my $TBAUDIT = "@TBAUDITEMAIL@"; +my $TBGROUP_DIR = "@GROUPSROOT_DIR@"; +my $TBPROJ_DIR = "@PROJROOT_DIR@"; + +# +# Untaint the path +# +$ENV{'PATH'} = "$TB/bin:$TB/sbin:/bin:/usr/bin:/usr/bin:/usr/sbin"; +delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; + +# +# Turn off line buffering on output +# +$| = 1; + +# +# Load the Testbed support stuff. +# +use lib "@prefix@/lib"; +use libdb; +use libtestbed; +use User; +use Project; +use Image; +use OSinfo; + +# Protos +sub fatal($); +sub DumpImage($); +sub DumpOS($); + +# +# 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 (defined($options{"d"})) { + $debug = 1; +} +if (@ARGV) { + usage(); +} + +if (defined($options{"i"})) { + my $imageid = $options{"i"}; + my $image = Image->Lookup($imageid); + if (!defined($image)) { + fatal("No such image: $imageid"); + } + DumpImage($image); +} +elsif (defined($options{"o"})) { + my $osid = $options{"o"}; + my $osinfo = OSinfo->Lookup($osid); + if (!defined($osinfo)) { + fatal("No such osid: $osid"); + } + DumpOS($osinfo); +} +else { + fatal("Must supply an image or os ID"); +} + +sub DumpImage($) +{ + my ($image) = @_; + + # Array of string values to print. + my %xmlfields = (); + + $xmlfields{"imagename"} = $image->imagename(); + $xmlfields{"pid"} = $image->pid(); + $xmlfields{"gid"} = $image->gid(); + $xmlfields{"description"} = $image->description(); + $xmlfields{"loadpart"} = $image->loadpart(); + $xmlfields{"global"} = $image->global(); + $xmlfields{"shared"} = $image->shared(); + $xmlfields{"path"} = $image->path(); + #$xmlfields{"mbr_version"} = $image->mbr_version(); + + sub MapOS($) { + my ($osid) = @_; + return "none" + if (!defined($osid)); + + my $osinfo = OSinfo->Lookup($osid); + if (!defined($osinfo)) { + fatal("Could not find osid $osid"); + } + return $osinfo->pid() . "," . $osinfo->osname(); + } + + if (!$image->ezid()) { + $xmlfields{"loadlength"} = $image->loadlength(); + $xmlfields{"part1_osid"} = MapOS($image->part1_osid()); + $xmlfields{"part2_osid"} = MapOS($image->part2_osid()); + $xmlfields{"part3_osid"} = MapOS($image->part3_osid()); + $xmlfields{"part4_osid"} = MapOS($image->part4_osid()); + $xmlfields{"default_osid"} = MapOS($image->default_osid()); + } + else { + my $osinfo = OSinfo->Lookup($image->imageid()); + if (!defined($osinfo)) { + fatal("Could not find osid for $image"); + } + $xmlfields{"OS"} = $osinfo->OS(); + $xmlfields{"version"} = $osinfo->version(); + $xmlfields{"op_mode"} = $osinfo->op_mode(); + $xmlfields{"osfeatures"} = $osinfo->osfeatures(); + $xmlfields{"reboot_waittime"} = $osinfo->reboot_waittime() + if (defined($osinfo->reboot_waittime())); + } + print "\n"; + foreach my $key (keys(%xmlfields)) { + my $val = $xmlfields{$key}; + + print " \n"; + print " " . CGI::escapeHTML($val) . "\n"; + print " \n"; + } + print "\n"; + + return 0; +} + +sub DumpOS($) +{ + my ($osinfo) = @_; + + # Array of string values to print. + my %xmlfields = (); + + $xmlfields{"description"} = $osinfo->description(); + $xmlfields{"osname"} = $osinfo->osname(); + $xmlfields{"pid"} = $osinfo->pid(); + $xmlfields{"OS"} = $osinfo->OS(); + $xmlfields{"version"} = $osinfo->version(); + $xmlfields{"path"} = $osinfo->path() + if (defined($osinfo->path())); + $xmlfields{"magic"} = $osinfo->magic() + if (defined($osinfo->magic())); + $xmlfields{"op_mode"} = $osinfo->op_mode(); + $xmlfields{"features"} = $osinfo->osfeatures(); + $xmlfields{"shared"} = $osinfo->shared(); + $xmlfields{"mustclean"} = $osinfo->mustclean(); + $xmlfields{"reboot_waittime"} = $osinfo->reboot_waittime() + if (defined($osinfo->reboot_waittime())); + + if (defined($osinfo->nextosid()) && $osinfo->nextosid()) { + my $nextosinfo = OSinfo->Lookup($osinfo->nextosid()); + if (!defined($nextosinfo)) { + fatal("Could not look up nextosid for $osinfo"); + } + $xmlfields{"nextosid"} = + $nextosinfo->pid() . "," . $nextosinfo->osname(); + } + + print "\n"; + foreach my $key (keys(%xmlfields)) { + my $val = $xmlfields{$key}; + + print " \n"; + print " " . CGI::escapeHTML($val) . "\n"; + print " \n"; + } + print "\n"; + + return 0; +} +exit(0); + +sub fatal($) +{ + my ($mesg) = @_; + + print STDERR "*** $0:\n". + " $mesg\n"; + exit(-1); +} + -- GitLab