Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulab-devel
Commits
0bd0358e
Commit
0bd0358e
authored
Aug 31, 2017
by
Leigh B Stoller
Browse files
This file should be in commit
d4a700fa
parent
d4a700fa
Changes
1
Hide whitespace changes
Inline
Side-by-side
db/changeiface.in
0 → 100644
View file @
0bd0358e
#!/usr/bin/perl -w
#
# Copyright (c) 2000-2017 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
Getopt::
Std
;
sub
usage
()
{
print
("
Usage: updateiface [-n] nodeid iface newiface
\n
");
exit
(
-
1
);
}
my
$optlist
=
"
n
";
my
$impotent
=
0
;
# Configure variables
my
$TB
=
"
@prefix
@
";
# Load the Testbed support stuff.
use
lib
"
@prefix
@/lib
";
use
emdb
;
use
Interface
;
use
Node
;
use
Lan
;
use
EmulabConstants
;
# un-taint path
$ENV
{'
PATH
'}
=
'
/bin:/usr/bin:/usr/local/bin
';
delete
@ENV
{'
IFS
',
'
CDPATH
',
'
ENV
',
'
BASH_ENV
'};
# Turn off line buffering on output
$|
=
1
;
# Protos
sub
fatal
($);
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
my
%options
=
();
if
(
!
getopts
(
$optlist
,
\
%options
))
{
usage
();
}
$impotent
=
1
if
(
defined
(
$options
{"
n
"}));
usage
()
if
(
@ARGV
!=
3
);
my
$nodeid
=
$ARGV
[
0
];
my
$iface
=
$ARGV
[
1
];
my
$newiface
=
$ARGV
[
2
];
#
# Grab interface and wire.
#
my
$interface
=
Interface
->
LookupByIface
(
$nodeid
,
$iface
);
if
(
!
defined
(
$interface
))
{
fatal
("
No such iface:
$nodeid
:
$iface
");
}
# Find the wire, need to check both sides.
my
$wire
=
Interface::
Wire
->
LookupAnyByIface
(
$nodeid
,
$iface
);
if
(
!
defined
(
$interface
))
{
fatal
("
No wire for
$nodeid
:
$iface
, why bother?
");
}
# Lan members (iface).
my
@lans
=
Lan
->
FindLansByMember
(
$nodeid
,
$iface
);
foreach
my
$lan
(
@lans
)
{
my
$member
=
$lan
->
FindMember
(
$nodeid
,
$iface
);
if
(
!
defined
(
$member
))
{
fatal
("
Could not lookup member for
$lan
:
$nodeid
:
$iface
");
}
if
(
$impotent
)
{
print
"
Would change
$member
iface
\n
";
}
else
{
print
"
Changing
$member
iface
\n
";
$member
->
SetAttribute
("
iface
",
$newiface
)
==
0
or
fatal
("
Could not update
$member
");
}
}
# vlans (member list).
my
$query_result
=
DBQueryWarn
("
select id from vlans
"
.
"
where members like '%
${nodeid}
:
${iface}
%'
");
while
(
my
(
$lanid
)
=
$query_result
->
fetchrow_array
())
{
my
$vlan
=
VLan
->
Lookup
(
$lanid
);
if
(
!
defined
(
$vlan
))
{
fatal
("
Could not lookup VLan
$lanid
");
}
if
(
$impotent
)
{
print
"
Would change member list for
$vlan
\n
";
}
else
{
my
@added
=
("
${nodeid}
:
${newiface}
");
my
@removed
=
("
${nodeid}
:
${iface}
");
print
"
Changing member list for
$vlan
\n
";
VLan
->
RecordVLanModification
(
$vlan
,
\
@added
,
\
@removed
)
==
0
or
fatal
("
Could not update members for
$vlan
");
}
}
# Delays table.
$query_result
=
DBQueryFatal
("
select distinct node_id,iface0,iface1 from delays
"
.
"
where node_id='
$nodeid
' and
"
.
"
(iface0='
$iface
' or iface1='
$iface
')
");
while
(
my
(
undef
,
$iface0
,
$iface1
)
=
$query_result
->
fetchrow_array
())
{
# Watch for multiplexed delays.
if
(
$iface0
eq
$iface
)
{
if
(
$impotent
)
{
print
"
Would change delays for
$nodeid
:iface0
\n
";
}
else
{
print
"
Changing delay
$nodeid
:iface0
\n
";
DBQueryFatal
("
update delays set iface0='
$newiface
'
"
.
"
where node_id='
$nodeid
' and iface0='
$iface
'
");
}
}
if
(
$iface1
eq
$iface
)
{
if
(
$impotent
)
{
print
"
Would change delays for
$nodeid
:iface1
\n
";
}
else
{
print
"
Changing delay
$nodeid
:iface1
\n
";
DBQueryFatal
("
update delays set iface1='
$newiface
'
"
.
"
where node_id='
$nodeid
' and iface1='
$iface
'
");
}
}
}
# linkdelays
$query_result
=
DBQueryFatal
("
select distinct iface from linkdelays
"
.
"
where node_id='
$nodeid
' and iface='
$iface
'
");
while
(
my
(
$iface
)
=
$query_result
->
fetchrow_array
())
{
if
(
$impotent
)
{
print
"
Would change linkdelays for
$nodeid
:
$iface
\n
";
}
else
{
print
"
Changing linkdelays for
$nodeid
:
$iface
\n
";
DBQueryFatal
("
update linkdelays set iface='
$newiface
'
"
.
"
where node_id='
$nodeid
' and iface='
$iface
'
");
}
}
# interface_settings;
$query_result
=
DBQueryFatal
("
select distinct iface from interface_settings
"
.
"
where node_id='
$nodeid
' and iface='
$iface
'
");
while
(
my
(
$iface
)
=
$query_result
->
fetchrow_array
())
{
if
(
$impotent
)
{
print
"
Would change interface_settings for
$nodeid
:
$iface
\n
";
}
else
{
print
"
Changing interface_settings for
$nodeid
:
$iface
\n
";
DBQueryFatal
("
update interface_settings set iface='
$newiface
'
"
.
"
where node_id='
$nodeid
' and iface='
$iface
'
");
}
}
# port_counters.
$query_result
=
DBQueryFatal
("
select distinct iface from port_counters
"
.
"
where node_id='
$nodeid
' and iface='
$iface
'
");
while
(
my
(
$iface
)
=
$query_result
->
fetchrow_array
())
{
if
(
$impotent
)
{
print
"
Would change port_counters for
$nodeid
:
$iface
\n
";
}
else
{
print
"
Changing port_counters for
$nodeid
:
$iface
\n
";
DBQueryFatal
("
update port_counters set iface='
$newiface
'
"
.
"
where node_id='
$nodeid
' and iface='
$iface
'
");
}
}
# traces
$query_result
=
DBQueryFatal
("
select distinct node_id,iface0,iface1 from traces
"
.
"
where node_id='
$nodeid
' and
"
.
"
(iface0='
$iface
' or iface1='
$iface
')
");
while
(
my
(
undef
,
$iface0
,
$iface1
)
=
$query_result
->
fetchrow_array
())
{
# Watch for multiplexed delays.
if
(
$iface0
eq
$iface
)
{
if
(
$impotent
)
{
print
"
Would change traces for
$nodeid
:iface0
\n
";
}
else
{
print
"
Changing trace for
$nodeid
:iface0
\n
";
DBQueryFatal
("
update traces set iface0='
$newiface
'
"
.
"
where node_id='
$nodeid
' and iface0='
$iface
'
");
}
}
if
(
$iface1
eq
$iface
)
{
if
(
$impotent
)
{
print
"
Would change traces for
$nodeid
:iface1
\n
";
}
else
{
print
"
Changing trace for
$nodeid
:iface1
\n
";
DBQueryFatal
("
update traces set iface1='
$newiface
'
"
.
"
where node_id='
$nodeid
' and iface1='
$iface
'
");
}
}
}
# vinterfaces
$query_result
=
DBQueryFatal
("
select distinct iface from vinterfaces
"
.
"
where node_id='
$nodeid
' and iface='
$iface
'
");
while
(
my
(
$iface
)
=
$query_result
->
fetchrow_array
())
{
if
(
$impotent
)
{
print
"
Would change vinterfaces for
$nodeid
:
$iface
\n
";
}
else
{
print
"
Changing vinterfaces for
$nodeid
:
$iface
\n
";
DBQueryFatal
("
update vinterfaces set iface='
$newiface
'
"
.
"
where node_id='
$nodeid
' and iface='
$iface
'
");
}
}
#
# And the main tables in a single update to avoid consistency
# problems on failure.
#
if
(
$impotent
)
{
print
"
Would change interfaces, interface_state, and wires
\n
";
}
else
{
print
"
Changing interfaces, interface_state, and wires
\n
";
DBQueryFatal
("
update interfaces i
"
.
"
inner join wires w on
"
.
(
$wire
->
node_id1
()
eq
$nodeid
&&
$wire
->
iface1
()
eq
$iface
?
"
(i.node_id=w.node_id1 and i.iface=w.iface1)
"
:
"
(i.node_id=w.node_id2 and i.iface=w.iface2)
")
.
"
inner join interface_state s on
"
.
"
(i.node_id=s.node_id and i.iface=s.iface)
"
.
"
set
"
.
"
i.iface='
$newiface
',s.iface='
$newiface
',
"
.
"
w.iface1='
$newiface
'
"
.
"
where i.node_id='
$nodeid
' and i.iface='
$iface
'
");
}
sub
fatal
($)
{
my
(
$mesg
)
=
@_
;
die
("
*** $0:
\n
"
.
"
$mesg
\n
"
.
"
Must fix this first!
\n
");
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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