Commit dc522d6c authored by Leigh Stoller's avatar Leigh Stoller

Update to reflect recent change to osids and imageids now being

globally unique IDs. dump-descriptors.in is a lot uglier, but
load-descriptors.in is still reasonable.
parent a0e2535a
This diff is collapsed.
...@@ -22,19 +22,25 @@ sub usage() ...@@ -22,19 +22,25 @@ sub usage()
# #
# These are the images/osids we dump out. We of course get the embedded osids. # These are the images/osids we dump out. We of course get the embedded osids.
# We should probably add an export flag to the tables so we can avoid this # We should probably add an export flag to the tables so we can avoid this
# hardwired list. # hardwired list. Note that all of these are assumed to live in the emulab-ops
# project.
# #
my @images = ('emulab-ops-FBSD410+RHL90-STD', my @imagenames = ('FBSD410+RHL90-STD',
'emulab-ops-FBSD410-STD', 'FBSD410-STD',
'emulab-ops-RHL90-STD'); 'RHL90-STD');
my @osids = ('FREEBSD-MFS', 'FRISBEE-MFS', 'NEWNODE-MFS', my @osnames = ('FREEBSD-MFS', 'FRISBEE-MFS', 'NEWNODE-MFS',
'OPSNODE-BSD', 'FW-IPFW', 'OPSNODE-BSD', 'FW-IPFW',
'RHL-STD', 'FBSD-STD', 'RHL-STD', 'FBSD-STD', 'FBSD-JAIL', 'POWER-CONTROLLER');
'emulab-ops-FBSD-JAIL', 'emulab-ops-POWER-CONTROLLER');
my %osidtoimageid = ("RHL-STD" => "emulab-ops-RHL90-STD", my @osids = ();
"FBSD-STD" => "emulab-ops-FBSD410-STD");
#
# Need to map these dynamically since we do not want to hardwire the actual
# nextosid IDs (numbers) into this table.
#
my %mappings = ("RHL-STD" => "RHL90-STD",
"FBSD-STD" => "FBSD410-STD");
# #
# Configure variables # Configure variables
...@@ -90,8 +96,8 @@ open(OUTPUT, ">$filename") or ...@@ -90,8 +96,8 @@ open(OUTPUT, ">$filename") or
# #
DBQueryFatal("create temporary table temp_images like images"); DBQueryFatal("create temporary table temp_images like images");
DBQueryFatal("insert into temp_images ". DBQueryFatal("insert into temp_images ".
"select * from images where ". "select * from images where pid='$protoproj' and (".
join(" or ", map("imageid='$_'", @images))); join(" or ", map("imagename='$_'", @imagenames)) . ")");
my $query_result = DBQueryFatal("show create table temp_images"); my $query_result = DBQueryFatal("show create table temp_images");
my $create_string = ($query_result->fetchrow_array())[1]; my $create_string = ($query_result->fetchrow_array())[1];
...@@ -155,8 +161,9 @@ foreach my $key (keys(%tempkeys)) { ...@@ -155,8 +161,9 @@ foreach my $key (keys(%tempkeys)) {
# #
DBQueryFatal("create temporary table temp_os_info like os_info"); DBQueryFatal("create temporary table temp_os_info like os_info");
DBQueryFatal("insert into temp_os_info ". DBQueryFatal("insert into temp_os_info ".
"select * from os_info where ". "select * from os_info where pid='$protoproj' and ((".
join(" or ", map("osid='$_'", @osids))); join(" or ", map("osname='$_'", @osnames)) . ") or (".
join(" or ", map("osid='$_'", @osids)) . "))");
$query_result = DBQueryFatal("show create table temp_os_info"); $query_result = DBQueryFatal("show create table temp_os_info");
$create_string = ($query_result->fetchrow_array())[1]; $create_string = ($query_result->fetchrow_array())[1];
...@@ -179,11 +186,20 @@ DBQueryFatal("update temp_os_info set ". ...@@ -179,11 +186,20 @@ DBQueryFatal("update temp_os_info set ".
# We reset the nextosid slots in the -STD osids, rather then worrying # We reset the nextosid slots in the -STD osids, rather then worrying
# about the osid_map table. # about the osid_map table.
# #
foreach my $osid (keys(%osidtoimageid)) { foreach my $osname (keys(%mappings)) {
my $nextosid = $osidtoimageid{$osid}; my $nextosname = $mappings{$osname};
$query_result =
DBQueryFatal("select osid from temp_os_info ".
"where pid='$protoproj' and osname='$nextosname'");
if (! $query_result->numrows) {
print "Could not map $protoproj,$osname to its osid!\n";
exit(-1);
}
my ($nextosid) = $query_result->fetchrow_array();
DBQueryFatal("update temp_os_info set nextosid='$nextosid' ". DBQueryFatal("update temp_os_info set nextosid='$nextosid' ".
"where osid='$osid'"); "where pid='$protoproj' and osname='$osname'");
} }
$query_result = $query_result =
......
...@@ -22,7 +22,7 @@ sub usage() ...@@ -22,7 +22,7 @@ sub usage()
# These are the OSIDs that are used to populate the osidtoimageid table # These are the OSIDs that are used to populate the osidtoimageid table
# using their nextosid entries. # using their nextosid entries.
# #
my @standard_osids = ('RHL-STD', 'FBSD-STD'); my @standard_osnames = ('RHL-STD', 'FBSD-STD');
# #
# Configure variables # Configure variables
...@@ -45,7 +45,9 @@ use Project; ...@@ -45,7 +45,9 @@ use Project;
#$libdb::DBQUERY_DEBUG = 1; #$libdb::DBQUERY_DEBUG = 1;
# Local # Local
my %osidtoimageid = (); my %osidtoimageid = ();
my %local_osids = ();
my %local_imageids = ();
# #
# Turn off line buffering on output # Turn off line buffering on output
...@@ -86,8 +88,9 @@ my $gid = $protoproj->gid(); ...@@ -86,8 +88,9 @@ my $gid = $protoproj->gid();
my $gid_idx = $protoproj->gid_idx(); my $gid_idx = $protoproj->gid_idx();
# Temp tables to hold new rows. # Temp tables to hold new rows.
DBQueryFatal("create temporary table temp_images like images"); DBQueryFatal("create table temp_images like images");
DBQueryFatal("create temporary table temp_os_info like os_info"); DBQueryFatal("create table temp_os_info like os_info");
DBQueryFatal("create table temp_o2i like osidtoimageid");
# #
# Open tempfile. # Open tempfile.
...@@ -135,21 +138,91 @@ while (my $rowref = $describe_result->fetchrow_hashref()) { ...@@ -135,21 +138,91 @@ while (my $rowref = $describe_result->fetchrow_hashref()) {
} }
} }
#
# Go through the new set of os_info entries and assign local IDs to them.
# Remember them since we need to change the new images table too.
#
my $query_result = DBQueryFatal("select osid from temp_os_info");
while (my ($osid) = $query_result->fetchrow_array()) {
$local_osids{$osid} = TBGetUniqueIndex("next_osid", 1000);
}
#
# Update temp_os_info with locally derived osids. nextosid as well.
#
$query_result->dataseek(0);
while (my ($osid) = $query_result->fetchrow_array()) {
my $newosid = $local_osids{$osid};
DBQueryFatal("update temp_os_info set osid='$newosid' ".
"where osid='$osid'");
DBQueryFatal("update temp_os_info set nextosid='$newosid' ".
"where nextosid='$osid'");
}
#
# Go through new set of images entries, but watch for ezid images since they
# have the same ID as its corresponding os_info entry.
#
$query_result = DBQueryFatal("select imageid,ezid from temp_images");
while (my ($imageid,$ezid) = $query_result->fetchrow_array()) {
if ($ezid) {
$local_imageids{$imageid} = $local_osids{$imageid};
}
else {
$local_imageids{$imageid} = TBGetUniqueIndex("next_osid", 1000);
}
}
#
# Update temp_images with locally derived imageids.
#
$query_result->dataseek(0);
while (my ($imageid) = $query_result->fetchrow_array()) {
my $newimageid = $local_imageids{$imageid};
DBQueryFatal("update temp_images set imageid='$newimageid' ".
"where imageid='$imageid'");
}
#
# And then update osids inside temp_images with locally derived imageids.
#
foreach my $osid (keys(%local_osids)) {
my $newosid = $local_osids{$osid};
DBQueryFatal("update temp_images set part1_osid='$newosid' ".
"where part1_osid='$osid'");
DBQueryFatal("update temp_images set part2_osid='$newosid' ".
"where part2_osid='$osid'");
DBQueryFatal("update temp_images set part3_osid='$newosid' ".
"where part3_osid='$osid'");
DBQueryFatal("update temp_images set part4_osid='$newosid' ".
"where part4_osid='$osid'");
DBQueryFatal("update temp_images set default_osid='$newosid' ".
"where default_osid='$osid'");
}
# #
# Use the nextosid slot of the -STD osids to figure out what the default # Use the nextosid slot of the -STD osids to figure out what the default
# images are. # images are.
# #
my $query_result = $query_result =
DBQueryFatal("select nextosid from temp_os_info ". DBQueryFatal("select nextosid from temp_os_info ".
"where nextosid is not null and (". "where nextosid is not null and (".
join(" or ", map("osid='$_'", @standard_osids)) . ")"); join(" or ", map("osname='$_'", @standard_osnames)) . ")");
while (my ($nextosid) = $query_result->fetchrow_array()) { while (my ($nextosid) = $query_result->fetchrow_array()) {
my $subquery_result = my $subquery_result =
DBQueryFatal("select imageid from temp_images where ". DBQueryFatal("select imageid from temp_images ".
"where loadlength=1 and (".
join(" or ", map("$_='$nextosid'", join(" or ", map("$_='$nextosid'",
("part1_osid", "part2_osid", ("part1_osid", "part2_osid",
"part3_osid", "part4_osid")))); "part3_osid", "part4_osid"))) . ")");
if (!$subquery_result->numrows) { if (!$subquery_result->numrows) {
print "*** WARNING: No osidtoimageid mapping for $nextosid\n"; print "*** WARNING: No osidtoimageid mapping for $nextosid\n";
...@@ -160,13 +233,6 @@ while (my ($nextosid) = $query_result->fetchrow_array()) { ...@@ -160,13 +233,6 @@ while (my ($nextosid) = $query_result->fetchrow_array()) {
$osidtoimageid{$nextosid} = $imageid; $osidtoimageid{$nextosid} = $imageid;
} }
#
# Ready to populate the tables. Move the entries from temp_images and
# temp_os_info across to the real tables.
#
DBQueryFatal("replace into images select * from temp_images");
DBQueryFatal("replace into os_info select * from temp_os_info");
# #
# Make up osidtoimageid entries for all local PCs. This is a shotgun # Make up osidtoimageid entries for all local PCs. This is a shotgun
# approach, but for a new testbed is probably the right thing. # approach, but for a new testbed is probably the right thing.
...@@ -178,11 +244,19 @@ while (my ($type) = $query_result->fetchrow_array()) { ...@@ -178,11 +244,19 @@ while (my ($type) = $query_result->fetchrow_array()) {
foreach my $osid (keys(%osidtoimageid)) { foreach my $osid (keys(%osidtoimageid)) {
my $imageid = $osidtoimageid{$osid}; my $imageid = $osidtoimageid{$osid};
DBQueryFatal("replace into osidtoimageid values ". DBQueryFatal("replace into temp_o2i values ".
"('$osid', '$type', '$imageid')"); "('$osid', '$type', '$imageid')");
} }
} }
#
# Ready to populate the tables. Move the entries from temp_images and
# temp_os_info across to the real tables.
#
DBQueryFatal("replace into images select * from temp_images");
DBQueryFatal("replace into os_info select * from temp_os_info");
DBQueryFatal("replace into osidtoimageid select * from temp_o2i");
exit(0); exit(0);
sub fatal($) sub fatal($)
......
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