Commit c87849aa authored by Leigh Stoller's avatar Leigh Stoller

Changes to add boss/ops/fs to the database so that we can do

arp lockdown properly. Well, only ops is needed for this, but
might as well add the others.
parent 4c3ffd18
<nodetype>
<attribute name="new_type"> <value>1</value></attribute>
<attribute name="class"> <value>misc</value></attribute>
<attribute name="isvirtnode"> <value>0</value></attribute>
<attribute name="isjailed"> <value>0</value></attribute>
<attribute name="isdynamic"> <value>0</value></attribute>
<attribute name="isremotenode"> <value>0</value></attribute>
<attribute name="issubnode"> <value>0</value></attribute>
<attribute name="isplabdslice"> <value>0</value></attribute>
<attribute name="issimnode"> <value>0</value></attribute>
<attribute name="isgeninode"> <value>0</value></attribute>
<attribute name="isfednode"> <value>0</value></attribute>
<attribute name="isswitch"> <value>0</value></attribute>
<attribute name="attr_integer_bootdisk_unit"> <value>0</value></attribute>
<attribute name="attr_string_control_interface"> <value>eth0</value></attribute>
<attribute name="attr_integer_control_network"> <value>0</value></attribute>
<attribute name="attr_integer_delay_capacity"> <value>0</value></attribute>
<attribute name="attr_boolean_imageable"> <value>0</value></attribute>
<attribute name="attr_integer_max_interfaces"> <value>1</value></attribute>
<attribute name="attr_boolean_rebootable"> <value>0</value></attribute>
<attribute name="attr_integer_simnode_capacity"> <value>0</value></attribute>
<attribute name="attr_integer_virtnode_capacity"> <value>0</value></attribute>
<attribute name="attr_string_default_osid"> <value>emulab-ops,OPSNODE-BSD</value></attribute>
<attribute name="node_type"> <value>ctrlnode</value></attribute>
</nodetype>
#
# Add boss/ops to DB.
#
use strict;
use libinstall;
use installvars;
use libEmulab;
use Node;
use NodeType;
my $NODETYPEXML = "$TOP_SRCDIR/install/ctrltype.xml";
my $NODETYPE = "ctrlnode";
my $CREATETYPE = "$PREFIX/bin/editnodetype";
my $ADDSERVERS = "$PREFIX/sbin/addservers";
sub Install($$$)
{
my ($server, $isupdate, $impotent) = @_;
# Replace if this script does an update for ip/domain.
return 0
if ($isupdate);
Phase "servers", "Creating control nodes", sub {
Phase "nodetype", "Creating control nodetype", sub {
my $nodetype = NodeType->Lookup($NODETYPE);
PhaseSkip("already created")
if (defined($nodetype));
ExecQuietFatal("$SUDO -u $PROTOUSER ".
" $WAP $CREATETYPE $NODETYPEXML");
};
# Do not run this in a genirack setup; must wait till later.
if (!$PROTOGENI_GENIRACK) {
Phase "adding", "Adding control nodes", sub {
PhaseSkip("already added")
if (defined(Node->Lookup("ops")));
ExecQuietFatal("$SUDO -u $PROTOUSER $WAP $ADDSERVERS");
};
}
};
return 0;
}
# Local Variables:
# mode:perl
# End:
......@@ -50,7 +50,7 @@ SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
addvpubaddr imageinfo ctrladdr image_import \
prereserve_check tcppd addexternalnetwork \
update_sitevars delete_image sitecheckin sitecheckin_client \
mktestbedtest fixrootcert
mktestbedtest fixrootcert addservers
WEB_SBIN_SCRIPTS= webnewnode webdeletenode webspewconlog webarchive_list \
webwanodecheckin webspewimage webdumpdescriptor \
......
#!/usr/bin/perl -w
#
# Copyright (c) 2013 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 English;
use Socket;
use strict;
use Getopt::Std;
#
# Add servers (boss, ops, fs) to db.
#
sub usage()
{
print("Usage: addservers\n");
exit(-1);
}
my $optlist = "dn";
my $debug = 0;
my $impotent= 0;
#
# Configure variables
#
my $TB = "@prefix@";
my $NEWSCRIPT = "$TB/bin/newscript";
my $GW_IP = "@CONTROL_ROUTER_IP@";
my $BOSS_IP = "@BOSSNODE_IP@";
my $OPS_IP = "@USERNODE_IP@";
my $FS_IP = "@FSNODE_IP@";
#
# Untaint the path
#
$ENV{'PATH'} = "$TB/bin:$TB/sbin:/bin:/usr/bin:/usr/bin:/usr/sbin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Turn off line buffering on output
#
$| = 1;
#
# Load the Testbed support stuff.
#
use lib "@prefix@/lib";
use emdb;
use libEmulab;
use emutil;
# Protos
sub fatal($);
sub AddServer($$$);
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"d"})) {
$debug = 1;
}
if (defined($options{"n"})) {
$impotent = 1;
}
usage()
if (@ARGV);
#
# Boss
#
my $ip = $BOSS_IP;
my $mac = GetSiteVar("node/boss_mac");
fatal("No MAC for boss")
if (!defined($mac));
AddServer("boss", $ip, $mac) == 0
or fatal("Could not add boss to the DB");
#
# Ops
#
$ip = $OPS_IP;
$mac = GetSiteVar("node/ops_mac");
fatal("No MAC for ops")
if (!defined($mac));
AddServer("ops", $ip, $mac) == 0
or fatal("Could not add ops to the DB");
#
# fs
#
if ($OPS_IP ne $FS_IP) {
$ip = $FS_IP;
$mac = GetSiteVar("node/fs_mac");
fatal("No MAC for fs")
if (!defined($mac));
AddServer("fs", $ip, $mac) == 0
or fatal("Could not add fs to the DB");
}
exit(0);
sub AddServer($$$)
{
my ($server, $ip, $mac) = @_;
my $newid = 696969;
my $file = "/tmp/$$";
$mac =~ s/://g;
if (!$impotent) {
DBQueryFatal("delete from new_nodes where new_node_id='$newid'");
DBQueryFatal("delete from new_interfaces where new_node_id='$newid'");
}
open(TFILE, ">$file")
or fatal("Could not open $file for writing");
print TFILE "<newnode>\n";
print TFILE " <attribute name='table'><value>node</value></attribute>\n";
print TFILE " <attribute name='command'><value>add</value></attribute>\n";
print TFILE " <attribute name='node_id'><value>$server</value></attribute>\n";
print TFILE " <attribute name='id'><value>$newid</value></attribute>\n";
print TFILE " <attribute name='type'><value>ctrlnode</value></attribute>\n";
print TFILE " <attribute name='IP'><value>$ip</value></attribute>\n";
print TFILE " <attribute name='identifier'><value>$server</value></attribute>\n";
print TFILE " <attribute name='role'><value>ctrlnode</value></attribute>\n";
print TFILE "</newnode>\n";
close(TFILE);
if ($debug) {
system("cat $file");
}
if (!$impotent) {
system("$NEWSCRIPT < $file") == 0
or fatal("Could not add new_nodes for $server");
}
open(TFILE, ">$file")
or fatal("Could not open $file for writing");
print TFILE "<newinterface>\n";
print TFILE " <attribute name='table'><value>interface</value></attribute>\n";
print TFILE " <attribute name='command'><value>add</value></attribute>\n";
print TFILE " <attribute name='node_id'><value>$newid</value></attribute>\n";
print TFILE " <attribute name='id'><value>$newid</value></attribute>\n";
print TFILE " <attribute name='card'><value>0</value></attribute>\n";
print TFILE " <attribute name='port'><value>1</value></attribute>\n";
print TFILE " <attribute name='mac'><value>$mac</value></attribute>\n";
print TFILE " <attribute name='type'><value>generic</value></attribute>\n";
print TFILE " <attribute name='role'><value>ctrl</value></attribute>\n";
print TFILE "</newinterface>\n";
close(TFILE);
if ($debug) {
system("cat $file");
}
if (!$impotent) {
system("$NEWSCRIPT < $file") == 0
or fatal("Could not add new_interfaces for $server");
}
open(TFILE, ">$file")
or fatal("Could not open $file for writing");
print TFILE "<newnode>\n";
print TFILE " <attribute name='table'><value>node</value></attribute>\n";
print TFILE " <attribute name='command'><value>commit</value></attribute>\n";
print TFILE " <attribute name='id'><value>$newid</value></attribute>\n";
print TFILE "</newnode>\n";
close(TFILE);
if ($debug) {
system("cat $file");
}
if (!$impotent) {
system("$NEWSCRIPT < $file") == 0
or fatal("Could not commit $server");
}
return 0;
}
sub fatal($)
{
my ($mesg) = @_;
print STDERR "*** $0:\n".
" $mesg\n";
exit(-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