Commit 37ffe0b9 authored by Leigh Stoller's avatar Leigh Stoller

A bunch of little changes to make bootstrapping images work properly.

Basically, we cannot create an image descriptor without any types
defined, and we cannot create any types without a default image
descriptor. I broke the circle by adding a stub pc type into the
database fill file so that all Emulabs start with a predefined type.
Then you can load the descriptor file, create your actual types, and
then go back and edit the image descriptors to set the types those
images run on (you always had to do this).
parent 24dd8e41
......@@ -315,6 +315,18 @@ my $types_result =
" a.attrvalue!='0'");
# Save the valid types in a new array for later.
my @mtypes_array;
if ($types_result->numrows) {
while (my ($type) = $types_result->fetchrow_array()) {
push(@mtypes_array, $type);
$xmlfields{"mtype_$type"} = ["mtype", $SLOT_OPTIONAL];
}
}
else {
@mtypes_array = ("pc");
$xmlfields{"mtype_pc"} = ["mtype", $SLOT_OPTIONAL];
}
while (my ($type) = $types_result->fetchrow_array()) {
push(@mtypes_array, $type);
$xmlfields{"mtype_$type"} = ["mtype", $SLOT_OPTIONAL];
......@@ -487,7 +499,8 @@ foreach $key (grep(/^mtype_/, keys(%newimageid_args))) {
UserError("Node Types: Must select at least one node type")
if ($node_types_selected == 0 && !$force);
my $typeclause = join(" or ", map("type='$_'", @mtype_keys));
my $typeclause =
($node_types_selected ? join(" or ", map("type='$_'", @mtype_keys)) : "0");
#
# Check sanity of node name and that user can create an image from it.
......
......@@ -319,10 +319,18 @@ my $types_result = DBQueryFatal($types_querystring);
# Save the valid types in a new array for later.
my @mtypes_array;
while (my ($type) = $types_result->fetchrow_array()) {
push(@mtypes_array, $type);
$xmlfields{"mtype_$type"} = ["mtype", $SLOT_OPTIONAL];
if ($types_result->numrows) {
while (my ($type) = $types_result->fetchrow_array()) {
push(@mtypes_array, $type);
$xmlfields{"mtype_$type"} = ["mtype", $SLOT_OPTIONAL];
}
}
else {
@mtypes_array = ("pc");
$xmlfields{"mtype_pc"} = ["mtype", $SLOT_OPTIONAL];
}
## printf "%s mtypes\n", $#mtypes_array + 1;
## foreach my $x (@mtypes_array) { printf "%s\n", $x; }
## print "\n";
......@@ -599,7 +607,8 @@ $newimageid_args{"loadlength"} = $loadlen;
$newimageid_args{"default_osid"} = $osid;
# Create the osidtoimageid mapping too.
$newimageid_args{"makedefault"} = 1;
$newimageid_args{"makedefault"} = 1
if ($node_types_selected);
my $new_image = Image->Create($project, $group, $this_user, $imagename, $osid,
\%newimageid_args, \$usrerr);
......
......@@ -148,34 +148,17 @@ while (<OUTPUT>) {
close(OUTPUT);
#
# Prepass to make sure the XML files verify.
# Must create the OSids first since the images reference them. But must
# do this in two passes since there are nextosid references. But, the EZ
# imageIDs also create OSids that can be referenced by nextosid, so must
# do those after the first OSid pass but before the second one.
#
foreach my $osname (keys(%osinfos)) {
my ($xmlparse, $string) = @{ $osinfos{$osname} };
my $nextosid = exists($xmlparse->{'attribute'}->{"nextosid"});
open(NEW, "| $NEWOSID -v -")
or fatal("Cannot start $NEWOSID");
print NEW $string;
close(NEW)
or fatal("OS $osname does not verify");
}
foreach my $imagename (keys(%images)) {
my ($xmlparse, $string) = @{ $images{$imagename} };
my $ezid = exists($xmlparse->{'attribute'}->{"OS"});
my $which = ($ezid ? $NEWIMAGE_EZ : $NEWIMAGE);
open(NEW, "| $which -v -f -")
or fatal("Cannot start $which");
print NEW $string;
close(NEW)
or fatal("Image $imagename does not verify");
}
#
# Must create the OSids first since the images reference them.
#
foreach my $osname (keys(%osinfos)) {
my ($xmlparse, $string) = @{ $osinfos{$osname} };
next
if ($nextosid);
my $osinfo = OSinfo->Lookup("$PROTOPROJ,$osname");
if (defined($osinfo) && !$force) {
......@@ -190,10 +173,8 @@ foreach my $osname (keys(%osinfos)) {
fatal("$osname could not be created");
}
}
#
# Two passes. First do the ezid images, then the other. This is cause
# multiple images can reference the OSids created with an EZid.
# Do the EZ images
#
foreach my $imagename (keys(%images)) {
my ($xmlparse, $string) = @{ $images{$imagename} };
......@@ -217,6 +198,32 @@ foreach my $imagename (keys(%images)) {
fatal("Image $imagename could not be created");
}
}
#
# Now the rest of the OSids.
#
foreach my $osname (keys(%osinfos)) {
my ($xmlparse, $string) = @{ $osinfos{$osname} };
my $nextosid = exists($xmlparse->{'attribute'}->{"nextosid"});
next
if (!$nextosid);
my $osinfo = OSinfo->Lookup("$PROTOPROJ,$osname");
if (defined($osinfo) && !$force) {
print STDERR "OS $osname already exists. Skipping; use -f option\n";
next;
}
open(NEW, "| $NEWOSID -")
or fatal("Cannot start $NEWOSID");
print NEW $string;
if (!close(NEW)) {
print STDERR "$string\n";
fatal("$osname could not be created");
}
}
#
# And the rest of the images.
#
foreach my $imagename (keys(%images)) {
my ($xmlparse, $string) = @{ $images{$imagename} };
my $ezid = exists($xmlparse->{'attribute'}->{"OS"});
......
......@@ -5,6 +5,8 @@
-- these is not idempotent, since a site may have changed them for some reason.
--
INSERT IGNORE INTO `node_types` VALUES ('pc','pc',NULL,NULL,0,0,0,0,0,0,0,0,0,0,0,0);
INSERT IGNORE INTO`node_type_attributes` VALUES ('pc','imageable','1','boolean');
INSERT IGNORE INTO `node_types` VALUES ('pcvm','pcvm',NULL,NULL,1,0,1,1,0,0,0,0,0,0,0,0);
INSERT IGNORE INTO `node_types` VALUES ('pcvwa','pcvwa',NULL,NULL,1,0,0,1,1,0,0,0,0,0,0,0);
INSERT IGNORE INTO `node_type_attributes` VALUES ('pcvwa','default_osid','0','integer');
......
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