Commit 4975c07e authored by Leigh Stoller's avatar Leigh Stoller

Remove direct query insertion of wires,interfaces, use Interface library

instead. Also create interface for switch side of wire.
parent c2886c8c
#!/usr/bin/perl -w
#
# Copyright (c) 2003-2016 University of Utah and the Flux Group.
# Copyright (c) 2003-2017 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -37,9 +37,14 @@ use English;
use OSImage;
use Getopt::Std;
use EmulabFeatures;
use EmulabConstants;
use Interface;
use Node;
use strict;
sub fatal($);
my $TB = "@prefix@";
my $ELABINELAB = @ELABINELAB@;
my $GENIRACK = @PROTOGENI_GENIRACK@;
......@@ -428,6 +433,11 @@ NODE: foreach my $node_id (@node_ids) {
DBQueryFatal("insert into node_utilization ".
"(node_id) values ('$node_id')");
my $node = Node->Lookup($node_id);
if (!defined($node)) {
fatal("Could not lookup node after creating it");
}
#
# Copy data into the location_info table, if they provided any
#
......@@ -473,6 +483,7 @@ NODE: foreach my $node_id (@node_ids) {
my $iface = "eth$card";
my $wire_type;
my $iface_role;
my $current_speed = $max_speed;
# Role from new_interfaces overrides anything we decide here.
if (defined($ifrole)) {
......@@ -496,44 +507,78 @@ NODE: foreach my $node_id (@node_ids) {
}
else {
# Experimental interfaces start with no speed set.
$max_speed = 0;
$current_speed = 0;
$wire_type = "Node";
}
if (! defined($iface_IP)) {
$iface_IP = "";
}
my $guidstr = defined($guid) ? "guid='$guid'," : "";
if (!$useScriptFeature || !defined($port))
{
$port = 1;
}
DBQueryFatal("INSERT INTO interfaces SET node_id='$node_id'," .
"card=$card,port='$port',mac='$MAC',$guidstr".
"IP='$iface_IP',interface_type='$iface_type',".
"iface='$iface',uuid=UUID(),current_speed='$max_speed',".
"duplex=$duplex,role='$iface_role'");
DBQueryFatal("INSERT INTO interface_state SET node_id='$node_id', " .
"card=$card, port='$port', iface='$iface'");
my $ifaceargs = {
"node_id" => $node_id,
"card" => $card,
"port" => $port,
"mac" => $MAC,
"IP" => $iface_IP,
"type" => $iface_type,
"iface" => $iface,
"max_speed" => $current_speed / 1000,
"duplex" => $duplex ? "full" : "half",
"role" => $iface_role,
};
if (defined($guid)) {
$ifaceargs->{"guid"} = $guid;
}
my $interface1 = Interface->Create($node, $ifaceargs);
if (!defined($interface1)) {
fatal("Could not create interface for node");
}
if (!$switch_id) {
print "No switch found for ${node_id}:$iface - skipping wire\n";
next;
}
my $cable_len = "";
if ($cable) {
$cable_len .= ", cable=$cable";
#
# Create interface for switch side.
#
my $switch = Node->Lookup($switch_id);
if (!defined($switch)) {
fatal("Cannot lookup switch $switch_id");
}
if ($len) {
$cable_len .= ", len=$len";
my $interface2 = Interface->Lookup($switch, $switch_card, $switch_port);
if (!defined($interface2)) {
my $itype = Interface::Type->GenericType($max_speed);
if (!defined($itype)) {
fatal("Cannot determing a generic interface type for $max_speed");
}
$ifaceargs = {
"node_id" => $switch_id,
"card" => $switch_card,
"port" => $switch_port,
"type" => $itype->type(),
"iface" => $switch_card . "/" . $switch_port,
"max_speed" => $max_speed / 1000,
"duplex" => $duplex ? "full" : "half",
"role" => TBDB_IFACEROLE_OTHER(),
"mac" => "000000000000",
};
$interface2 = Interface->Create($switch, $ifaceargs);
if (!defined($interface2)) {
fatal("Could not create interface for switch side");
}
}
if (! $useScriptFeature) {
DBQueryFatal("INSERT INTO wires SET type='$wire_type', " .
"node_id1='$node_id', card1=$card, port1=1, " .
"node_id2='$switch_id', card2='$switch_card', " .
"port2='$switch_port' $cable_len");
my $wireargs = {};
$wireargs->{"cable"} = $cable if (defined($cable));
$wireargs->{"length"} = $len if (defined($len));
my $wire = Interface::Wire->Create($interface1, $interface2,
$wire_type, $wireargs);
if (!defined($wire)) {
fatal("Could not create wire for $interface1,$interface2");
}
}
}
......@@ -608,6 +653,16 @@ if (!$quiet) {
print "correctly, use nfree on boss to free them from the emulab-ops/hwdown\n";
print "experiment.\n";
}
exit(0);
sub fatal($)
{
my ($mesg) = @_;
print STDERR "*** $0:\n".
" $mesg\n";
exit(-1);
}
#
# TODO -
......
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