Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
emulab-devel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Elijah Grubb
emulab-devel
Commits
36e4084a
Commit
36e4084a
authored
Jun 12, 2018
by
Leigh B Stoller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Another new script for setting up a new emulab; for creating stacks
parent
a21dbef6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
204 additions
and
1 deletion
+204
-1
utils/GNUmakefile.in
utils/GNUmakefile.in
+1
-1
utils/addstack.in
utils/addstack.in
+203
-0
No files found.
utils/GNUmakefile.in
View file @
36e4084a
...
...
@@ -59,7 +59,7 @@ SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
addrfdevice addrfpath reserve announce createimagealias \
predict test-reserve notify-reservations \
deprecate_image pushrootkey addinterface addwire cnetwatch \
addswitch addtypetoimages resutil
addswitch addtypetoimages resutil
addstack
WEB_SBIN_SCRIPTS= webnewnode webdeletenode webspewconlog webarchive_list \
webspewimage webdumpdescriptor webemulabfeature \
...
...
utils/addstack.in
0 → 100644
View file @
36e4084a
#!/usr/bin/perl -w
#
# Copyright (c) 2003-2018 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 switch stack to the DB.
#
sub
usage
()
{
print
STDERR
"
Usage: addstack [options] <stack_id> <leader_id>
\n
";
print
STDERR
"
Usage: addstack -r [-f] <stack_id>
\n
";
print
STDERR
"
Options:
\n
";
print
STDERR
"
-r - Remove stack instead.
\n
";
print
STDERR
"
-n - Dry run mode
\n
";
print
STDERR
"
-p passwd - SNMP community string or password
\n
";
print
STDERR
"
-t type - Stack type (defaults to generic)
\n
";
print
STDERR
"
-m min/max - Min/Max vlan numbers. Defaults to 10/750
\n
";
print
STDERR
"
stack_id - Typically, Experiment or Control
\n
";
print
STDERR
"
leader_id - Name of leader switch for the stack.
\n
";
print
STDERR
"
Remember for later when adding switches,
\n
";
print
STDERR
"
you will need a switch with this name.
\n
";
exit
(
-
1
);
}
my
$optlist
=
"
rnt:m:fp:
";
my
$debug
=
0
;
my
$impotent
=
0
;
my
$remove
=
0
;
my
$force
=
0
;
my
$minvlan
=
10
;
my
$maxvlan
=
750
;
my
$stack_type
=
"
generic
";
my
$stack_id
;
my
$stack_leader
;
my
$password
;
# 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
;
#
# 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
{'
f
'}))
{
$force
=
1
;
}
if
(
defined
(
$options
{'
n
'}))
{
$impotent
=
1
;
}
if
(
defined
(
$options
{'
t
'}))
{
$stack_type
=
$options
{'
t
'};
}
if
(
defined
(
$options
{'
p
'}))
{
$password
=
$options
{'
p
'};
}
if
(
defined
(
$options
{'
m
'}))
{
if
(
$options
{'
m
'}
=~
/^(\d+)\/(\d+)$/
)
{
$minvlan
=
$
1
;
$maxvlan
=
$
2
;
if
(
$minvlan
<
10
)
{
fatal
("
Min vlan must be >= 10
");
}
if
(
$maxvlan
>
4096
)
{
fatal
("
Max vlan must be < 4096
");
}
}
else
{
fatal
("
Could not parse -m option
");
}
}
if
(
defined
(
$options
{'
r
'}))
{
$remove
=
1
;
}
if
(
$remove
)
{
usage
()
if
(
@ARGV
!=
1
);
$stack_id
=
$ARGV
[
0
];
}
else
{
usage
()
if
(
@ARGV
!=
2
);
$stack_id
=
$ARGV
[
0
];
$stack_leader
=
$ARGV
[
1
];
}
#
# 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!
");
}
#
# Remove and done.
#
if
(
$remove
)
{
if
(
!
$force
)
{
print
"
Are you sure? This will delete existing stack entries also!
\n
"
.
"
Use the -f (force) option
\n
";
exit
(
0
);
}
DBQueryFatal
("
delete from switch_stacks where stack_id='
$stack_id
'
");
DBQueryFatal
("
delete from switch_stack_types where stack_id='
$stack_id
'
");
exit
(
0
);
}
# Stack must not already exist.
my
$query_result
=
DBQueryFatal
("
select stack_type from switch_stack_types
"
.
"
where stack_id='
$stack_id
'
");
if
(
$query_result
->
numrows
)
{
fatal
("
Stack (
$stack_id
) aleady exists.
");
}
if
(
$impotent
)
{
print
"
Would add stack
$stack_id
: leader:
$stack_leader
type:
$stack_type
"
.
"
minvlan:
$minvlan
maxvlan:
$maxvlan
"
.
(
defined
(
$password
)
?
"
passwd:
$password
"
:
"")
.
"
\n
";
}
else
{
DBQueryFatal
("
insert into switch_stack_types set
"
.
"
stack_id='
$stack_id
',leader='
$stack_leader
',
"
.
"
stack_type='
$stack_type
',single_domain='0',
"
.
(
defined
(
$password
)
?
"
snmp_community='
$password
',
"
:
"")
.
"
min_vlan='
$minvlan
', max_vlan='
$maxvlan
'
");
}
exit
(
0
);
sub
fatal
($)
{
my
(
$mesg
)
=
$_
[
0
];
die
("
*** $0:
\n
"
.
"
$mesg
\n
");
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment