Commit 5cc03c0e authored by Leigh Stoller's avatar Leigh Stoller

Checkpoint some small changes made for Geni.

parent a3dd5200
......@@ -89,6 +89,17 @@ sub LookupAll($$$)
$interface->{"DBROW"} = $rowref;
bless($interface, $class);
#
# Grab the wires table entry.
#
my $wires_result =
DBQueryWarn("select * from wires ".
"where node_id1='$nodeid' and ".
" card1='$card' and port1='$port'");
if ($wires_result && $wires_result->numrows) {
$interface->{'WIRES'} = $wires_result->fetchrow_hashref();
}
# Cache by card,port and by iface
$all_interfaces{"$nodeid:$card:$port"} = $interface;
$all_interfaces{"$nodeid:$iface"} = $interface;
......@@ -113,6 +124,11 @@ sub role($) { return field($_[0], 'role'); }
sub type($) { return field($_[0], 'interface_type'); }
sub mask($) { return field($_[0], 'mask'); }
sub uuid($) { return field($_[0], 'uuid'); }
# Wires table
sub wire_type($) { return $_[0]->{'WIRES'}->{'type'}; }
sub switch_id($) { return $_[0]->{'WIRES'}->{'node_id2'}; }
sub switch_card($) { return $_[0]->{'WIRES'}->{'card2'}; }
sub switch_port($) { return $_[0]->{'WIRES'}->{'port2'}; }
sub IsExperimental($)
{
......@@ -150,6 +166,17 @@ sub Lookup($$$$)
$interface->{"DBROW"} = $query_result->fetchrow_hashref();
bless($interface, $class);
#
# Grab the wires table entry.
#
$query_result =
DBQueryWarn("select * from wires ".
"where node_id1='$nodeid' and ".
" card1='$card' and port1='$port'");
if ($query_result && $query_result->numrows) {
$interface->{'WIRES'} = $query_result->fetchrow_hashref();
}
# Cache by card,port and by iface
my $iface = $interface->iface();
......@@ -328,6 +355,32 @@ sub Stringify($)
return "[Interface: $nodeid:$iface]";
}
#
# Temporary cruft for geni widearea switches.
#
sub LookUpWideAreaSwitch($$)
{
my ($class, $hrn) = @_;
my $safe_hrn = DBQuoteSpecial($hrn);
my $query_result =
DBQueryWarn("select node_id from widearea_switches ".
"where hrn=$safe_hrn");
return undef
if (!$query_result);
if ($query_result->numrows) {
my ($switch_id) = $query_result->fetchrow_array();
return $switch_id;
}
my $next_id = TBGetUniqueIndex('next_switch', 1);
my $switch_id = "widearea_switch$next_id";
return $switch_id
if (DBQueryWarn("insert into widearea_switches set ".
" hrn=$safe_hrn, node_id='$switch_id'"));
return undef;
}
# _Always_ make sure that this 1 is at the end of the file...
1;
......@@ -1430,6 +1430,13 @@ sub SetAttribute($$$;$)
return $self->GetMember()->SetAttribute($key, $value, $type);
}
sub memberid($)
{
my ($self) = @_;
return $self->GetMember()->memberid();
}
############################################################################
#
# A protolan is for creating a lan without sending it to the DB until
......@@ -1772,6 +1779,42 @@ sub MemberList($)
return keys(%{ $self->{'MEMBERS'} });
}
#
# Return member node.
#
sub MemberNode($$)
{
my ($self, $member) = @_;
return undef
if (! exists($self->{'MEMBERS'}->{$member}));
return $self->{'MEMBERS'}->{$member}->{'node'};
}
#
# Return the ifacelist
#
sub IfaceList($)
{
my ($self) = @_;
return keys(%{ $self->{'IFACES'} });
}
#
# Return member node.
#
sub IfaceNode($$)
{
my ($self, $member) = @_;
return undef
if (! exists($self->{'IFACES'}->{$member}));
return $self->{'IFACES'}->{$member}->{'node'};
}
#
# Set value of an attribute.
#
......
......@@ -196,6 +196,7 @@ sub field($$) { return ((! ref($_[0])) ? -1 : $_[0]->{'DBROW'}->{$_[1]}); }
sub node_id($) { return field($_[0], 'node_id'); }
sub uuid($) { return field($_[0], 'uuid'); }
sub type($) { return field($_[0], 'type'); }
sub role($) { return field($_[0], 'role'); }
sub eventstate($) { return field($_[0], 'eventstate'); }
sub allocstate($) { return field($_[0], 'allocstate'); }
sub jailflag($) { return field($_[0], 'jailflag'); }
......@@ -234,27 +235,33 @@ sub Create($$$$)
my $isremote = $typeinfo->isremotenode();
if ($typeinfo->virtnode_capacity(\$virtnode_capacity)) {
print STDERR "*** No virtnode_capacity for $type! Using zero.\n";
$virtnode_capacity = 0;
}
if ($typeinfo->adminmfs_osid(\$adminmfs_osid)) {
print STDERR "*** No adminmfs osid for $type!\n";
return undef;
}
# Find object for the adminfs.
if (defined($adminmfs_osid)) {
$adminmfs = OSinfo->Lookup($adminmfs_osid);
if ($role eq "testnode") {
if ($typeinfo->virtnode_capacity(\$virtnode_capacity)) {
print STDERR "*** No virtnode_capacity for $type! Using zero.\n";
$virtnode_capacity = 0;
}
if ($typeinfo->adminmfs_osid(\$adminmfs_osid)) {
print STDERR "*** No adminmfs osid for $type!\n";
return undef;
}
# Find object for the adminfs.
if (defined($adminmfs_osid)) {
$adminmfs = OSinfo->Lookup($adminmfs_osid);
}
else {
$adminmfs = OSinfo->Lookup(TBOPSPID(), $MFS_INITIAL);
}
if (!defined($adminmfs)) {
print STDERR "*** Could not find OSinfo object for adminmfs!\n";
return undef;
}
$osid = $adminmfs->osid();
$opmode = $adminmfs->op_mode();
}
else {
$adminmfs = OSinfo->Lookup(TBOPSPID(), $MFS_INITIAL);
}
if (!defined($adminmfs)) {
print STDERR "*** Could not find OSinfo object for adminmfs!\n";
return undef;
$osid = 0;
$opmode = "";
}
$osid = $adminmfs->osid();
$opmode = $adminmfs->op_mode();
$state = $STATE_INITIAL;
#
......@@ -282,22 +289,24 @@ sub Create($$$$)
" op_mode_timestamp=unix_timestamp(NOW())")
or goto bad;
DBQueryWarn("insert into node_hostkeys (node_id) ".
"values ('$node_id')")
or goto bad;
if ($role eq "testnode") {
DBQueryWarn("insert into node_hostkeys (node_id) ".
"values ('$node_id')")
or goto bad;
DBQueryWarn("insert into node_status ".
"(node_id, status, status_timestamp) ".
"values ('$node_id', 'down', now()) ")
or goto bad;
DBQueryWarn("insert into node_status ".
"(node_id, status, status_timestamp) ".
"values ('$node_id', 'down', now()) ")
or goto bad;
DBQueryWarn("insert into node_activity ".
"(node_id) values ('$node_id')")
or goto bad;
DBQueryWarn("insert into node_activity ".
"(node_id) values ('$node_id')")
or goto bad;
DBQueryWarn("insert into node_utilization ".
"(node_id) values ('$node_id')")
or goto bad;
DBQueryWarn("insert into node_utilization ".
"(node_id) values ('$node_id')")
or goto bad;
}
if (defined($experiment)) {
my $exptidx = $experiment->idx();
......@@ -1751,6 +1760,26 @@ sub GetGeniSliverInfo($$;$)
return 0;
}
#
# Set the status slot for a node.
#
sub SetStatus($$)
{
my ($self, $status) = @_;
# Must be a real reference.
return -1
if (! ref($self));
my $node_id = $self->node_id();
return -1
if (! DBQueryWarn("update node_status set status='$status' ".
"where node_id='$node_id'"));
$self->{"DBROW"}->{'node_status'} = $status;
return 0;
}
# _Always_ make sure that this 1 is at the end of the file...
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