Commit 2b85c865 authored by Gary Wong's avatar Gary Wong

Scripts for adding RF devices and RF paths.

parent a4eaa086
......@@ -7014,7 +7014,8 @@ outfiles="$outfiles Makeconf GNUmakefile \
utils/remove_old_www utils/epmodeset \
utils/mkblob utils/rmblob utils/ctrladdr utils/tcppd \
utils/mktestbedtest utils/pxelinux_makeconf \
utils/addvpubaddr utils/attend utils/atten \
utils/addvpubaddr utils/attend utils/atten utils/addrfdevice \
utils/addrfpath \
www/GNUmakefile www/defs.php3 www/dbdefs.php3 www/xmlrpc.php3 \
www/xmlrpcpipe.php3 \
www/swish.conf www/websearch \
......
......@@ -1357,7 +1357,8 @@ outfiles="$outfiles Makeconf GNUmakefile \
utils/remove_old_www utils/epmodeset \
utils/mkblob utils/rmblob utils/ctrladdr utils/tcppd \
utils/mktestbedtest utils/pxelinux_makeconf \
utils/addvpubaddr utils/attend utils/atten \
utils/addvpubaddr utils/attend utils/atten utils/addrfdevice \
utils/addrfpath \
www/GNUmakefile www/defs.php3 www/dbdefs.php3 www/xmlrpc.php3 \
www/xmlrpcpipe.php3 \
www/swish.conf www/websearch \
......
......@@ -55,7 +55,8 @@ SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
update_sitevars delete_image sitecheckin sitecheckin_client \
mktestbedtest fixrootcert addservers poolmonitor \
node_exclude managetaint shutdown-shared imagerelease \
runsonxen pxelinux_makeconf attend atten
runsonxen pxelinux_makeconf attend atten \
addrfdevice addrfpath
WEB_SBIN_SCRIPTS= webnewnode webdeletenode webspewconlog webarchive_list \
webwanodecheckin webspewimage webdumpdescriptor \
......
#!/usr/bin/perl -w
#
# Copyright (c) 2003-2016 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
use strict;
use English;
use Getopt::Std;
use Date::Parse;
use Time::Local;
use Data::Dumper;
use File::Temp qw(tempfile);
#
# Add a generic device to the DB.
#
sub usage()
{
print STDERR "Usage: addrfdevice -t <type> <node_id>\n";
print STDERR "Options:\n";
print STDERR " -d - Turn on debugging\n";
print STDERR " -n - Dry run mode\n";
print STDERR " -t type - Type name (eg: nexus5)\n";
exit(-1);
}
my $optlist = "t:dn";
my $debug = 0;
my $impotent = 0;
my $type;
my $experiment;
# Protos
sub fatal($);
sub CreateType($$);
sub CreateNode();
#
# Configure variables
#
my $TB = "@prefix@";
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use emdb;
use EmulabConstants;
use emutil;
use User;
use Node;
use NodeType;
use OSinfo;
use Experiment;
use Interface;
#
# Turn off line buffering on output
#
$| = 1;
#
# Untaint the path
#
$ENV{'PATH'} = "/bin:/sbin:/usr/bin:";
#
# Parse command arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{'h'})) {
usage();
}
if (defined($options{'d'})) {
$debug = 1;
}
if (defined($options{'n'})) {
$impotent = 1;
}
if (defined($options{'t'})) {
$type = $options{'t'};
}
usage()
if (@ARGV != 1 || !(defined($type)));
my $node_id = $ARGV[0];
#
# Verify user, must be admin.
#
my $this_user = User->ThisUser();
if (! defined($this_user)) {
fatal("You ($UID) do not exist!");
}
if (!$this_user->IsAdmin()) {
fatal("You are not a testbed administrator!");
}
#
# The node may not already exist.
#
if (Node->Lookup($node_id)) {
fatal("Node already exists in the DB");
}
#
# These two OSIDs must exist.
#
my $osinfo = OSinfo->LookupByName("GENERICDEV");
if (!defined($osinfo)) {
fatal("Cannot lookup OSID 'GENERICDEV' for physical device");
}
my $osinfo_vm = OSinfo->LookupByName("GENERICDEV-VM");
if (!defined($osinfo_vm)) {
fatal("Cannot lookup OSID 'GENERICDEV-VM' for virtual device");
}
#
# Create the type if it does not exist.
#
my $nodetype = NodeType->Lookup($type);
if (!defined($nodetype)) {
CreateType($type, 0);
$nodetype = NodeType->Lookup($type);
}
CreateNode();
exit(0);
#
# Add a new node type.
#
sub CreateType($$)
{
my ($type, $isvirt) = @_;
my $osid = ($isvirt ? $osinfo_vm->osid() : $osinfo->osid());
#
# Defaults work for almost everything.
#
if ($debug || $impotent) {
print "Creating type: $type - isvirt is $isvirt\n";
}
if (!$impotent) {
DBQueryFatal("replace into node_types set ".
" class='$type', type='$type', ".
" isvirtnode='$isvirt', isdynamic='$isvirt'");
}
#
# Device nodes are neither rebootable nor imageable.
#
if ($debug || $impotent) {
print "Adding false attributes rebootable/imageable\n";
print "Adding true attribute fakenode\n";
print "Setting default osid: " .
($isvirt ? $osinfo_vm->osname() : $osinfo->osname()) . "\n";
}
if (!$impotent) {
DBQueryFatal("replace into node_type_attributes values ".
" ('$type','rebootable','1','boolean')");
DBQueryFatal("replace into node_type_attributes values ".
" ('$type','imageable','1','boolean')");
DBQueryFatal("replace into node_type_attributes values ".
" ('$type','default_osid','$osid','integer')");
}
return 0;
}
#
# Create the node.
#
sub CreateNode()
{
my $blob = {
"type" => $type,
"role" => ($nodetype->isswitch() ?
"testswitch" : "testnode"),
"initial_eventstate" => TBDB_NODESTATE_ISUP(),
};
my $node;
print "Creating new node $node_id\n";
if (!$impotent) {
$node = Node->Create($node_id, $experiment, $blob);
if (!defined($node)) {
fatal("Could not create new node");
}
DBQueryFatal( "INSERT INTO outlets SET node_id='$node_id', " .
"power_id='ue'" );
}
return 0;
}
sub fatal($)
{
my ($mesg) = $_[0];
die("*** $0:\n".
" $mesg\n");
}
#!/usr/bin/perl -w
#
# Copyright (c) 2003-2016 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
use strict;
use English;
use Getopt::Std;
use Date::Parse;
use Time::Local;
use Data::Dumper;
use File::Temp qw(tempfile);
#
# Add an RF path (interfaces and wire) to the DB.
#
sub usage()
{
print STDERR "Usage: addrfpath <node_id1> <card1> <iface_id1> <node_id2> <card2> <iface_id2> <path>\n";
print STDERR "Options:\n";
print STDERR " -d - Turn on debugging\n";
print STDERR " -f - force, modify path for existing interfaces\n";
print STDERR " -n - Dry run mode\n";
print STDERR " node_id - ue1, ue2, etc\n";
print STDERR " path - attenuator path (must be an integer)\n";
print STDERR " iface_id - rf0, rf1, etc (must end in an integer)\n";
exit(-1);
}
my $optlist = "dfn";
my $debug = 0;
my $impotent = 0;
my $force = 0;
# Protos
sub fatal($);
#
# Configure variables
#
my $TB = "@prefix@";
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use emdb;
use EmulabConstants;
use emutil;
use User;
use Node;
use NodeType;
use OSinfo;
use Interface;
#
# Turn off line buffering on output
#
$| = 1;
#
# Untaint the path
#
$ENV{'PATH'} = "/bin:/sbin:/usr/bin:";
#
# Parse command arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{'h'})) {
usage();
}
if (defined($options{'d'})) {
$debug = 1;
}
if (defined($options{'n'})) {
$impotent = 1;
}
if (defined($options{'f'})) {
$force = 1;
}
usage()
if (@ARGV != 7);
my $node_id1 = $ARGV[ 0 ];
my $card1 = $ARGV[ 1 ];
my $iface_id1 = $ARGV[ 2 ];
my $node_id2 = $ARGV[ 3 ];
my $card2 = $ARGV[ 4 ];
my $iface_id2 = $ARGV[ 5 ];
my $path = $ARGV[ 6 ];
#
# Verify user, must be admin.
#
my $this_user = User->ThisUser();
if (! defined($this_user)) {
fatal("You ($UID) do not exist!");
}
if (!$this_user->IsAdmin()) {
fatal("You are not a testbed administrator!");
}
my $node1 = Node->Lookup($node_id1);
if (!defined($node1)) {
fatal("Node does not exist in the DB")
}
my $interface1 = Interface->LookupByIface($node1, $iface_id1);
fatal( "Node already has an interface named $iface_id1" )
if( defined( $interface1 ) && !defined( $force ) );
my $node2 = Node->Lookup($node_id2);
if (!defined($node2)) {
fatal("Node does not exist in the DB")
}
my $interface2 = Interface->LookupByIface($node2, $iface_id2);
fatal( "Node already has an interface named $iface_id2" )
if( defined( $interface2 ) && !defined( $force ) );
#
# Add the interfaces.
#
my $ifaceargs = {
"card" => $card1,
"iface" => $iface_id1,
"role" => TBDB_IFACEROLE_EXPERIMENT(),
"type" => "P2PLTE",
"max_speed" => 100,
"trunk" => 0,
"mac" => "000000000000",
};
print "Creating interface with arguments:\n";
print Dumper($ifaceargs);
if (!$impotent) {
Interface->Create($node1, $ifaceargs)
or $force or fatal("Could not create interface entry");
}
$ifaceargs = {
"card" => $card2,
"iface" => $iface_id2,
"role" => TBDB_IFACEROLE_EXPERIMENT(),
"type" => "P2PLTE",
"max_speed" => 100,
"trunk" => 0,
"mac" => "000000000000",
};
print "Creating interface with arguments:\n";
print Dumper($ifaceargs);
if (!$impotent) {
Interface->Create($node2, $ifaceargs)
or $force or fatal("Could not create interface entry");
}
DBQueryWarn( "INSERT INTO wires SET cable=$path, type='Node', " .
"node_id1='$node_id1', card1=$card1, port1=1, " .
"node_id2='$node_id2', card2=$card2, port2=1" );
exit(0);
sub fatal($)
{
my ($mesg) = $_[0];
die("*** $0:\n".
" $mesg\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