Commit 04c35b0b authored by Leigh Stoller's avatar Leigh Stoller

Add runsonxen script to set the bits of DB state required.

	usage: runsonxen [-p <parent>] <imageid>
	usage: runsonxen -a [-p <parent>]
	usage: runsonxen -c <imageid>
	Options:
	 -n      - Impotent mode
	 -c      - Clear XEN parent settings completely
	 -a      - Operate on all current XEN capable images
	 -p      - Set default parent; currently XEN43-64-STD
parent f6a67dc8
...@@ -55,6 +55,7 @@ my $TBGROUP_DIR = "@GROUPSROOT_DIR@"; ...@@ -55,6 +55,7 @@ my $TBGROUP_DIR = "@GROUPSROOT_DIR@";
my $TBPROJ_DIR = "@PROJROOT_DIR@"; my $TBPROJ_DIR = "@PROJROOT_DIR@";
my $CREATEIMAGE = "$TB/bin/create_image"; my $CREATEIMAGE = "$TB/bin/create_image";
my $CLONEIMAGE = "$TB/sbin/clone_image"; my $CLONEIMAGE = "$TB/sbin/clone_image";
my $RUNSONXEN = "$TB/sbin/runsonxen";
# #
# Untaint the path # Untaint the path
...@@ -761,13 +762,7 @@ if (defined($parentos)) { ...@@ -761,13 +762,7 @@ if (defined($parentos)) {
# Temp hack until we put all mappings into XML file. # Temp hack until we put all mappings into XML file.
# #
if ($parentos->osname() =~ /^XEN4/) { if ($parentos->osname() =~ /^XEN4/) {
my $other = ($parentos->osname() =~ /^XEN41/ ? system("$RUNSONXEN $imagepid,$imagename");
"XEN43-64-STD" : "XEN41-64-STD");
my $otheros = OSinfo->LookupByName($other);
if (defined($otheros)) {
$new_osinfo->SetRunsOnParent($otheros);
}
} }
} }
......
...@@ -53,7 +53,8 @@ SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \ ...@@ -53,7 +53,8 @@ SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
prereserve_check tcppd addexternalnetwork \ prereserve_check tcppd addexternalnetwork \
update_sitevars delete_image sitecheckin sitecheckin_client \ update_sitevars delete_image sitecheckin sitecheckin_client \
mktestbedtest fixrootcert addservers poolmonitor \ mktestbedtest fixrootcert addservers poolmonitor \
node_exclude managetaint shutdown-shared imagerelease node_exclude managetaint shutdown-shared imagerelease \
runsonxen
WEB_SBIN_SCRIPTS= webnewnode webdeletenode webspewconlog webarchive_list \ WEB_SBIN_SCRIPTS= webnewnode webdeletenode webspewconlog webarchive_list \
webwanodecheckin webspewimage webdumpdescriptor \ webwanodecheckin webspewimage webdumpdescriptor \
......
#!/usr/bin/perl -w
#
# Copyright (c) 2010-2014 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 strict;
use Getopt::Std;
#
# Mark an image as running on XEN.
#
my $DEFAULT_PARENT = "XEN43-64-STD";
my @OTHER_PARENTS = ("XEN44-64-BIGFS", "XEN41-64-STD");
sub usage()
{
print STDERR "usage: runsonxen [-p <parent>] <imageid>\n";
print STDERR "usage: runsonxen -a [-p <parent>]\n";
print STDERR "usage: runsonxen -c <imageid>\n";
print STDERR "Options:\n";
print STDERR " -n - Impotent mode\n";
print STDERR " -c - Clear XEN parent settings completely\n";
print STDERR " -a - Operate on all current XEN capable images\n";
print STDERR " -p - Set default parent; currently $DEFAULT_PARENT\n";
exit(1);
}
my $optlist = "acp:n";
my $doall = 0;
my $clear = 0;
my $impotent = 0;
my $parent = $DEFAULT_PARENT;
# Protos
sub fatal($);
#
# Turn off line buffering on output
#
$| = 1;
#
# Load the Testbed support stuff.
#
use lib "/usr/testbed/lib";
use emdb;
use Image;
use OSinfo;
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"c"})) {
$clear = 1;
}
if (defined($options{"a"})) {
$doall = 1;
}
if (defined($options{"n"})) {
$impotent = 1;
}
if (defined($options{"p"})) {
$parent = $options{"p"};
@OTHER_PARENTS = ($DEFAULT_PARENT, @OTHER_PARENTS);
}
usage()
if (!$doall && !@ARGV);
#
# List of images to operate on.
#
my @images = ();
if ($doall) {
my $query_result =
DBQueryFatal("select distinct v.osid from os_info_versions as v ".
"left join os_info_versions as v2 on ".
" v2.osid=v.def_parentosid ".
"where v.deleted is null and ".
" v.def_parentosid is not null and ".
" FIND_IN_SET('xen-host', v2.osfeatures)");
while (my ($osid) = $query_result->fetchrow_array()) {
my $image = Image->Lookup($osid);
push(@images, $image)
if (defined($image));
}
}
else {
my $image = Image->Lookup($ARGV[0]);
if (!defined($image)) {
fatal("No such image");
}
@images = ($image);
}
if ($clear) {
foreach my $image (@images) {
my $osinfo = OSinfo->Lookup($image->imageid());
if (!defined($osinfo)) {
fatal("Could not find osinfo for $image");
}
my $imageid = $image->imageid();
my $osid = $osinfo->osid();
if ($impotent) {
print "Would clear parents for $image\n";
}
else {
DBQueryFatal("delete from osidtoimageid ".
"where osid='$imageid' and type='pcvm'");
DBQueryFatal("delete from os_submap ".
"where osid='$imageid'");
DBQueryFatal("update os_info set def_parentosid=NULL ".
"where osid='$imageid'");
}
}
exit(0);
}
#
# Find the "default" parent image and the list of others parents.
#
my $parent_image = Image->LookupByName($parent);
if (!defined($parent_image)) {
fatal("No such parent $parent");
}
my $parent_osinfo = OSinfo->Lookup($parent_image->imageid());
if (!defined($parent_osinfo)) {
fatal("No osinfo for $parent");
}
my @other_parents = ();
foreach my $imagename (@OTHER_PARENTS) {
my $osinfo = OSinfo->LookupByName($imagename);
push(@other_parents, $osinfo)
if (defined($osinfo));
}
#
# Loop through all images.
#
foreach my $image (@images) {
my $osinfo = OSinfo->Lookup($image->imageid());
if (!defined($osinfo)) {
fatal("Could not find osinfo for $image");
}
if ($impotent) {
print "Would set $image to run on $parent_osinfo (default)\n";
}
else {
$osinfo->SetParentOS($parent_osinfo);
$osinfo->SetRunsOnParent($parent_osinfo);
}
# And the rest of the parents.
foreach my $other_parent (@other_parents) {
if ($impotent) {
print " Would set $image to run on $other_parent\n";
}
else {
$osinfo->SetRunsOnParent($other_parent);
}
}
if ($impotent) {
print " Setting $image to run on type pcvm\n";
}
else {
$image->SetRunsOnNodeType("pcvm");
}
}
exit(0);
sub fatal($) {
my ($mesg) = $_[0];
print STDERR "*** $0:\n".
" $mesg\n";
exit(-1);
}
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