Commit 9a0d26bd authored by Leigh Stoller's avatar Leigh Stoller

Minor mods for adding next_boot_osid to nodes table.

parent efca7883
......@@ -30,11 +30,13 @@ query_bootinfo_db(struct in_addr ipaddr, boot_what_t *info)
char dbquery[] =
"select n.next_boot_path, n.next_boot_cmd_line, "
"n.def_boot_osid, p.partition, n.def_boot_cmd_line, "
"n.def_boot_path, o.path from nodes "
"n.def_boot_path, o1.path, "
"n.next_boot_osid, o2.path from nodes "
"as n left join partitions as p on n.node_id=p.node_id and "
"n.def_boot_osid=p.osid left join interfaces as i on "
"i.node_id=n.node_id "
"left join os_info as o on o.osid=n.def_boot_osid "
"left join os_info as o1 on o1.osid=n.def_boot_osid "
"left join os_info as o2 on o2.osid=n.next_boot_osid "
"where i.IP = '%s'";
#define NEXT_BOOT_PATH 0
......@@ -43,7 +45,9 @@ query_bootinfo_db(struct in_addr ipaddr, boot_what_t *info)
#define PARTITION 3
#define DEF_BOOT_CMD_LINE 4
#define DEF_BOOT_PATH 5
#define OSID_PATH 6
#define DEF_BOOT_OSID_PATH 6
#define NEXT_BOOT_OSID 7
#define NEXT_BOOT_OSID_PATH 8
n = snprintf(querybuf, sizeof querybuf, dbquery, inet_ntoa(ipaddr));
if (n > sizeof querybuf) {
......@@ -96,7 +100,7 @@ query_bootinfo_db(struct in_addr ipaddr, boot_what_t *info)
ncols = (int)mysql_num_fields(res);
switch (ncols) {
case 7: /* Should have 7 fields */
case 9: /* Should have 9 fields */
break;
default:
syslog(LOG_ERR, "%s: %d fields in query for IP %s!",
......@@ -110,9 +114,17 @@ query_bootinfo_db(struct in_addr ipaddr, boot_what_t *info)
/*
* Check next_boot_path. If set, assume it is a multiboot kernel.
*/
if (row[NEXT_BOOT_PATH] != 0 && row[NEXT_BOOT_PATH][0] != '\0') {
if ((row[NEXT_BOOT_PATH] != 0 &&
row[NEXT_BOOT_PATH][0] != '\0') ||
(row[NEXT_BOOT_OSID_PATH] != 0 &&
row[NEXT_BOOT_OSID_PATH][0] != '\0')) {
info->type = BIBOOTWHAT_TYPE_MB;
parse_multiboot_path(row[NEXT_BOOT_PATH], info);
if (row[NEXT_BOOT_PATH] != 0 &&
row[NEXT_BOOT_PATH][0] != '\0')
parse_multiboot_path(row[NEXT_BOOT_PATH], info);
else
parse_multiboot_path(row[NEXT_BOOT_OSID_PATH], info);
if (row[NEXT_BOOT_CMD_LINE] != 0 &&
row[NEXT_BOOT_CMD_LINE][0] != '\0')
......@@ -132,9 +144,10 @@ query_bootinfo_db(struct in_addr ipaddr, boot_what_t *info)
info->type = BIBOOTWHAT_TYPE_MB;
parse_multiboot_path(row[DEF_BOOT_PATH], info);
}
else if (row[OSID_PATH] != 0 && row[OSID_PATH][0] != '\0') {
else if (row[DEF_BOOT_OSID_PATH] != 0 &&
row[DEF_BOOT_OSID_PATH][0] != '\0') {
info->type = BIBOOTWHAT_TYPE_MB;
parse_multiboot_path(row[OSID_PATH], info);
parse_multiboot_path(row[DEF_BOOT_OSID_PATH], info);
}
else if (row[PARTITION] != 0 && row[PARTITION][0] != '\0') {
info->type = BIBOOTWHAT_TYPE_PART;
......@@ -164,7 +177,9 @@ query_bootinfo_db(struct in_addr ipaddr, boot_what_t *info)
#undef PARTITION
#undef DEF_BOOT_CMD_LINE
#undef DEF_BOOT_PATH
#undef OSID_PATH
#undef DEF_BOOT_OSID_PATH
#undef NEXT_BOOT_OSID
#undef NEXT_BOOT_OSID_PATH
}
int
......@@ -177,7 +192,8 @@ ack_bootinfo_db(struct in_addr ipaddr, boot_what_t *info)
MYSQL_ROW row;
n = snprintf(querybuf, sizeof querybuf,
"select i.node_id,n.next_boot_path,n.next_boot_cmd_line "
"select i.node_id,"
"n.next_boot_osid,n.next_boot_path,n.next_boot_cmd_line "
"from nodes as n left join interfaces as i on "
"i.node_id=n.node_id where i.IP = '%s'",
inet_ntoa(ipaddr));
......@@ -226,7 +242,8 @@ ack_bootinfo_db(struct in_addr ipaddr, boot_what_t *info)
row = mysql_fetch_row(res);
if (row[1] == 0 || row[1][0] == '\0') {
if ((row[1] == 0 || row[1][0] == '\0') &&
(row[2] == 0 || row[2][0] == '\0')) {
/* Nothing to do */
mysql_free_result(res);
mysql_close(&db);
......@@ -237,7 +254,7 @@ ack_bootinfo_db(struct in_addr ipaddr, boot_what_t *info)
* Update the database to reflect that the boot has been done.
*/
n = snprintf(querybuf, sizeof querybuf,
"update nodes set next_boot_path='',"
"update nodes set next_boot_osid='',next_boot_path='',"
"next_boot_cmd_line='' where node_id='%s'",
row[0]);
mysql_free_result(res);
......
......@@ -14,14 +14,16 @@ use Getopt::Std;
# The nodes and partitions tables are updated appropriately.
#
# usage: os_load [-s] <imageid> <node> [node ...]
# usage: os_load -l
#
sub usage()
{
print STDOUT "Usage: os_load [-s] <imageid> <node> [node ...]\n".
"Use the -s to setup reload only, but do not issue a reboot\n";
"Use -s to setup reload only, but do not issue a reboot\n".
"Use -l to get a list of images you are permitted to load\n";
exit(-1);
}
my $optlist = "s";
my $optlist = "sld";
#
# Configure variables
......@@ -36,7 +38,7 @@ require libdb;
my $BOSSADDR = "boss.emulab.net";
my $USERADDR = "users.emulab.net";
my $NETDISK = "$BOSSADDR:/tftpboot/netdisk";
my $NETDISKOSID = "NETDISK-STD";
my $nodereboot = "$TB/bin/node_reboot";
my $dbg = 0;
my @row;
......@@ -60,6 +62,10 @@ $| = 1; #Turn off line buffering on output
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"l"})) {
dolisting();
exit(0);
}
if (@ARGV < 2) {
usage();
}
......@@ -202,7 +208,7 @@ foreach my $node (@nodes) {
print STDOUT "Setting up reload for $pc\n";
DBQueryFatal("update nodes set ".
"next_boot_path='$NETDISK',".
"next_boot_osid='$NETDISKOSID',".
"next_boot_cmd_line='$cmdline' ".
"where node_id='$pc'");
}
......@@ -218,3 +224,32 @@ if (! $setuponly) {
print STDOUT "OS Reload Done!\n";
exit $failures;
#
# Print a listing of imageids.
#
sub dolisting()
{
my($query_result);
if ($UID && !TBAdmin($UID)) {
my ($me) = getpwuid($UID);
$query_result =
DBQueryFatal("select distinct i.* from images as i ".
"left join proj_memb as p on ".
" i.pid IS NULL or p.pid=i.pid ".
"where p.uid='$me' order by i.pid,o.imageid");
}
else {
$query_result =
DBQueryFatal("SELECT * FROM images order by imageid");
}
for ($i = 0; $i < $query_result->numrows; $i++) {
my %row = $query_result->fetchhash();
my $id = $row{'imageid'};
my $desc = $row{'description'};
printf "%-20s %s\n", $id, $desc;
}
}
......@@ -54,6 +54,7 @@ $insert_result = mysql_db_query($TBDBNAME,
"def_boot_osid=\"$def_boot_osid\", ".
"def_boot_path=\"$def_boot_path\", ".
"def_boot_cmd_line=\"$def_boot_cmd_line\", ".
"next_boot_osid=\"$next_boot_osid\", ".
"next_boot_path=\"$next_boot_path\", ".
"next_boot_cmd_line=\"$next_boot_cmd_line\", ".
"startupcmd='$startupcmd', ".
......
......@@ -56,6 +56,7 @@ $type = $row[type];
$def_boot_osid = $row[def_boot_osid];
$def_boot_path = $row[def_boot_path];
$def_boot_cmd_line = $row[def_boot_cmd_line];
$next_boot_osid = $row[next_boot_osid];
$next_boot_path = $row[next_boot_path];
$next_boot_cmd_line = $row[next_boot_cmd_line];
$rpms = $row[rpms];
......@@ -144,6 +145,28 @@ echo "<tr>
</tr>\n";
mysql_data_seek($osid_result, 0);
echo "<tr>
<td>Next Boot OSID:</td>";
echo " <td><select name=\"next_boot_osid\">\n";
echo " <option value=\"None\">No OSID</option>\n";
while ($row = mysql_fetch_array($osid_result)) {
$osid = $row[osid];
$pid = $row[pid];
if (!$pid)
$pid = "testbed";
echo "<option ";
if ($next_boot_osid == $osid) {
echo "selected ";
}
echo "value=\"$osid\">$pid - $osid</option>\n";
}
echo " </select>";
echo " </td>
</tr>\n";
echo "<tr>
<td>Next Boot Path:</td>
<td class=\"left\">
......
......@@ -43,6 +43,7 @@ echo "<tr>
<td align=center>Default<br>OSID</td>
<td align=center>Default<br>Path</td>
<td align=center>Default<br>Cmdline</td>
<td align=center>Next<br>OSID</td>
<td align=center>Next<br>Path</td>
<td align=center>Next<br>Cmdline</td>
</tr>\n";
......@@ -53,17 +54,18 @@ while ($row = mysql_fetch_array($query_result)) {
$def_boot_osid = $row[def_boot_osid];
$def_boot_path = $row[def_boot_path];
$def_boot_cmd_line = $row[def_boot_cmd_line];
$next_boot_osid = $row[next_boot_osid];
$next_boot_path = $row[next_boot_path];
$next_boot_cmd_line = $row[next_boot_cmd_line];
if (!$def_boot_cmd_line)
$def_boot_cmd_line = "NULL";
$def_boot_cmd_line = "&nbsp";
if (!$def_boot_path)
$def_boot_path = "NULL";
$def_boot_path = "&nbsp";
if (!$next_boot_path)
$next_boot_path = "NULL";
$next_boot_path = "&nbsp";
if (!$next_boot_cmd_line)
$next_boot_cmd_line = "NULL";
$next_boot_cmd_line = "&nbsp";
#
# If the node is reserved, lets get the PID/EID from that table
......@@ -97,9 +99,17 @@ while ($row = mysql_fetch_array($query_result)) {
$def_boot_osid</A></td>\n";
else
echo "<td>&nbsp</td>\n";
echo " <td>$def_boot_path</td>
<td>$def_boot_cmd_line</td>
<td>$next_boot_path</td>
<td>$def_boot_cmd_line</td>\n";
if ($next_boot_osid)
echo "<td><A href='showosinfo.php3?osid=$next_boot_osid'>
$next_boot_osid</A></td>\n";
else
echo "<td>&nbsp</td>\n";
echo " <td>$next_boot_path</td>
<td>$next_boot_cmd_line</td>
</tr>\n";
}
......
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