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
Issues
143
Issues
143
List
Boards
Labels
Service Desk
Milestones
Merge Requests
6
Merge Requests
6
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
emulab
emulab-devel
Commits
02bc6116
Commit
02bc6116
authored
Jan 16, 2009
by
Leigh B. Stoller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some tidbits for automating the db migration process. See dbupdate.in.
parent
dd942894
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
6 deletions
+44
-6
db/emdbi.pm.in
db/emdbi.pm.in
+32
-1
db/libdb.pm.in
db/libdb.pm.in
+12
-5
No files found.
db/emdbi.pm.in
View file @
02bc6116
#
!/usr/bin/perl -w
#
#
EMULAB
-
COPYRIGHT
#
Copyright
(
c
)
2008
University
of
Utah
and
the
Flux
Group
.
#
Copyright
(
c
)
2008
,
2009
University
of
Utah
and
the
Flux
Group
.
#
All
rights
reserved
.
#
package
emdbi
;
...
...
@@ -425,6 +425,37 @@ sub DBErr()
return $DB[0]->err;
}
#
# Some utility routines for doing migration (DB upgrades).
#
sub DBTableExistsN($$)
{
my($dbnum, $table) = @_;
my $result =
DBQueryN($dbnum, "
show
tables
like
'$table'
");
if (! $result) {
DBWarn("
DB
Query
failed
");
}
return $result->numrows;
}
sub DBTableExists($) { return DBTableExistsN(0,$_[0]); }
sub DBSlotExistsN($$$)
{
my($dbnum, $table, $slot) = @_;
my $result =
DBQueryN($dbnum, "
show
columns
from
`$
table
`
like
'$slot'
");
if (! $result) {
DBWarn("
DB
Query
failed
");
}
return $result->numrows;
}
sub DBSlotExists($$) { return DBSlotExistsN(0,$_[0],$_[1]); }
END {
# Call it here otherwise may get:
# (in cleanup) Can't call method "
FETCH
" on an undefined value at
...
...
db/libdb.pm.in
View file @
02bc6116
...
...
@@ -2,7 +2,7 @@
#
#
EMULAB
-
COPYRIGHT
#
Copyright
(
c
)
2000
-
200
8
University
of
Utah
and
the
Flux
Group
.
#
Copyright
(
c
)
2000
-
200
9
University
of
Utah
and
the
Flux
Group
.
#
All
rights
reserved
.
#
...
...
@@ -163,6 +163,7 @@ use vars qw(@ISA @EXPORT);
DBQuery DBQueryFatal DBQueryWarn DBWarn DBFatal DBErr
NewTBDBHandle DBQueryN DBQueryFatalN DBQueryWarnN DBErrN
DBQuerySingleFatal DBQuerySingleFatalN
DBTableExists DBSlotExists
DBQuoteSpecial ExpState
ExpNodes ExpNodeVnames ExpNodesOldReserved
DBDateTime DefaultImageID
...
...
@@ -301,6 +302,8 @@ sub DBQueryWarn($) { return emdbi::DBQueryWarn($_[0]);}
sub DBQuoteSpecial($) { return emdbi::DBQuoteSpecial($_[0]); }
sub DBErrN($) { return emdbi::DBErrN($_[0]); }
sub DBErr() { return emdbi::DBErr(); }
sub DBTableExists($) { return emdbi::DBTableExists($_[0]); }
sub DBSlotExists($$) { return emdbi::DBSlotExists($_[0], $_[1]); }
# These are handled differently cause of tblog stuff.
sub DBWarn($;$) { DBError(\&tbwarn, $_[0], $_[1]); }
sub DBFatal($;$) { DBError(\&tbdie, $_[0], $_[1]); }
...
...
@@ -3099,7 +3102,7 @@ sub TBSetExptFirewallVlan($$$$) {
my
$
exptidx
;
if
(
!TBExptIDX($pid, $eid, \$exptidx)) {
print
"*** WARNING: No such experiment $pid/$eid!
\n
"
;
return
-
1
;
return
0
;
}
#
...
...
@@ -3110,7 +3113,7 @@ sub TBSetExptFirewallVlan($$$$) {
DBQueryWarn
(
"select fwname from virt_firewalls "
.
"WHERE pid='$pid' AND eid='$eid'"
);
return
-
1
return
0
if
(
!$query_result || $query_result->num_rows == 0);
my
($
fwname
)
=
$
query_result
->
fetchrow_array
();
...
...
@@ -3120,13 +3123,17 @@ sub TBSetExptFirewallVlan($$$$) {
#
DBQueryWarn
(
"replace into firewalls (exptidx,pid,eid,fwname,vlan,vlanid) "
.
"values ('$exptidx', '$pid', '$eid', "
.
" '$fwname', $fwvlan, $fwvlanid)"
);
" '$fwname', $fwvlan, $fwvlanid)"
)
or
return
0
;
#
#
Change
the
reserved
table
entries
for
all
firewalled
nodes
to
reflect
it
.
#
DBQueryWarn
(
"UPDATE reserved set cnet_vlan=$fwvlan "
.
"WHERE pid='$pid' AND eid='$eid' AND node_id!='$fwnode'"
);
"WHERE pid='$pid' AND eid='$eid' AND node_id!='$fwnode'"
)
or
return
0
;
return
1
;
}
#
...
...
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