Commit 32213f95 authored by Leigh Stoller's avatar Leigh Stoller

Minor change to DefaultImageID() interface; let the caller know when

there is not default imageid, so it can generate an error!
parent 38ff37a7
......@@ -1771,12 +1771,13 @@ sub VnameToNodeid ($$$$) {
#
# Get the default ImageID for a particular node, from the node_types table.
#
# usage: DefaultImageID(char *nodeid)
# returns imageid if the node is valid and has a default imageid.
# usage: DefaultImageID(char *nodeid, \*imageid)
# returns 1 if the node is valid and has a default imageid.
# Imageid is returned in reference param
# returns 0 if there are problems.
#
sub DefaultImageID ($) {
my($nodeid) = @_;
sub DefaultImageID ($$) {
my($nodeid,$imageid) = @_;
my $query_result =
DBQueryFatal("select imageid from nodes as n ".
......@@ -1784,11 +1785,17 @@ sub DefaultImageID ($) {
"where n.node_id='$nodeid'");
if (! $query_result->num_rows) {
$$imageid = undef;
return 0;
}
my @row = $query_result->fetchrow_array();
return $row[0];
my ($res) = $query_result->fetchrow_array();
if (!defined($res) || $res eq "") {
$$imageid = undef;
return 0;
}
$$imageid = $res;
return 1;
}
#
......@@ -2703,6 +2710,8 @@ sub TBGetSiteVar($)
#
@virtualTables = ("virt_nodes",
"virt_lans",
"virt_lan_settings",
"virt_lan_member_settings",
"virt_trafgens",
"virt_agents",
"virt_routes",
......
......@@ -150,7 +150,8 @@ sub osload ($$) {
# Get default imageid for this node.
my $default_imageid;
if (! ($default_imageid = DefaultImageID($node))) {
if (! DefaultImageID($node, \$default_imageid) ||
! defined($default_imageid)) {
print STDERR "*** osload ($node): No default imageid defined!\n";
goto failednode;
}
......
......@@ -276,7 +276,7 @@ foreach my $node (@nodes) {
$sth = DBQueryFatal("select node_id from nodes where node_id='$pc'");
if ($sth->num_rows() != 1) {
print STDERR "Node $pc doesn't exist. Skipping $pc.\n";
print STDERR "Node $pc does not exist. Skipping $pc.\n";
next;
}
......@@ -284,9 +284,10 @@ foreach my $node (@nodes) {
# Get default imageid for this node if none specified on comand line.
#
if ($usedefault) {
if (! ($imageid = DefaultImageID($node))) {
die("*** $0:\n".
" No default imageid is defined for $node!\n");
if (! DefaultImageID($node, \$imageid) || !defined($imageid)) {
print STDERR
"*** Node $pc does not have a default imageid. Skipping!\n";
next;
}
}
......
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