Commit 83e4616c authored by Leigh Stoller's avatar Leigh Stoller

Add UUID (Universally Unique Identifiers) to various tables. I was

working on this a few weeks ago when I got sidetracked by the pubsub
project.
parent 5451c540
...@@ -339,6 +339,13 @@ sub Create($$$$) ...@@ -339,6 +339,13 @@ sub Create($$$$)
} }
} }
# And a UUID (universally unique identifier).
my $uuid = NewUUID();
if (!defined($uuid)) {
print "*** WARNING: Could not generate a UUID!\n";
return undef;
}
# #
# Insert the record. This reserves the pid/eid for us. # Insert the record. This reserves the pid/eid for us.
# #
...@@ -360,7 +367,7 @@ sub Create($$$$) ...@@ -360,7 +367,7 @@ sub Create($$$$)
# Append the rest # Append the rest
$query .= ",expt_created=FROM_UNIXTIME('$now')"; $query .= ",expt_created=FROM_UNIXTIME('$now')";
$query .= ",expt_locked=now(),pid='$pid',eid='$eid'"; $query .= ",expt_locked=now(),pid='$pid',eid='$eid',eid_uuid='$uuid'";
$query .= ",pid_idx='$pid_idx',gid='$gid',gid_idx='$gid_idx'"; $query .= ",pid_idx='$pid_idx',gid='$gid',gid_idx='$gid_idx'";
$query .= ",expt_name=$description"; $query .= ",expt_name=$description";
$query .= ",noswap_reason=$noswap_reason"; $query .= ",noswap_reason=$noswap_reason";
...@@ -396,11 +403,11 @@ sub Create($$$$) ...@@ -396,11 +403,11 @@ sub Create($$$$)
# #
if (! DBQueryWarn("insert into experiment_stats ". if (! DBQueryWarn("insert into experiment_stats ".
"(eid, pid, creator, creator_idx, gid, created, ". "(eid, pid, creator, creator_idx, gid, created, ".
" batch, exptidx, rsrcidx, pid_idx, gid_idx) ". " batch, exptidx, rsrcidx, pid_idx, gid_idx, eid_uuid) ".
"values('$eid', '$pid', '$creator_uid', '$creator_idx',". "values('$eid', '$pid', '$creator_uid', '$creator_idx',".
" '$gid', FROM_UNIXTIME('$now'), ". " '$gid', FROM_UNIXTIME('$now'), ".
" $batchmode, $exptidx, $rsrcidx, ". " $batchmode, $exptidx, $rsrcidx, ".
" $pid_idx, $gid_idx)")) { " $pid_idx, $gid_idx, '$uuid')")) {
DBQueryWarn("delete from experiments where pid='$pid' and eid='$eid'"); DBQueryWarn("delete from experiments where pid='$pid' and eid='$eid'");
DBQueryWarn("delete from experiment_resources where idx=$rsrcidx"); DBQueryWarn("delete from experiment_resources where idx=$rsrcidx");
DBQueryWarn("unlock tables"); DBQueryWarn("unlock tables");
......
...@@ -284,6 +284,13 @@ sub Create($$$$$$) ...@@ -284,6 +284,13 @@ sub Create($$$$$$)
} }
} }
# And a UUID (universally unique identifier).
my $uuid = NewUUID();
if (!defined($uuid)) {
print "*** WARNING: Could not generate a UUID!\n";
return undef;
}
if (!DBQueryWarn("insert into groups set ". if (!DBQueryWarn("insert into groups set ".
" pid='$pid', gid='$gid', ". " pid='$pid', gid='$gid', ".
" leader='" . $leader->uid() . "'," . " leader='" . $leader->uid() . "'," .
...@@ -291,14 +298,16 @@ sub Create($$$$$$) ...@@ -291,14 +298,16 @@ sub Create($$$$$$)
" created=now(), ". " created=now(), ".
" description='$description', ". " description='$description', ".
" unix_name='$unix_name', ". " unix_name='$unix_name', ".
" gid_uuid='$uuid', ".
" gid_idx=$gid_idx, ". " gid_idx=$gid_idx, ".
" pid_idx=$pid_idx, ". " pid_idx=$pid_idx, ".
" unix_gid=$unix_gid")) { " unix_gid=$unix_gid")) {
return undef; return undef;
} }
if (! DBQueryWarn("insert into group_stats (pid, gid, gid_idx, pid_idx) ". if (! DBQueryWarn("insert into group_stats ".
"values ('$pid', '$gid', $gid_idx, $pid_idx)")) { " (pid, gid, gid_idx, pid_idx, gid_uuid) ".
"values ('$pid','$gid',$gid_idx,$pid_idx,'$uuid')")) {
DBQueryFatal("delete from groups where gid_idx='$gid_idx'"); DBQueryFatal("delete from groups where gid_idx='$gid_idx'");
return undef; return undef;
} }
......
...@@ -406,6 +406,13 @@ sub Create($$$$) ...@@ -406,6 +406,13 @@ sub Create($$$$)
# And a verification key. # And a verification key.
my $verify_key = TBGenSecretKey(); my $verify_key = TBGenSecretKey();
# And a UUID (universally unique identifier).
my $uuid = NewUUID();
if (!defined($uuid)) {
print "*** WARNING: Could not generate a UUID!\n";
return undef;
}
# Now tack on other stuff we need. # Now tack on other stuff we need.
push(@insert_data, "wikionly='1'") push(@insert_data, "wikionly='1'")
if ($wikionly); if ($wikionly);
...@@ -417,6 +424,7 @@ sub Create($$$$) ...@@ -417,6 +424,7 @@ sub Create($$$$)
push(@insert_data, "unix_uid=$unix_uid"); push(@insert_data, "unix_uid=$unix_uid");
push(@insert_data, "mailman_password='$mailman_password'"); push(@insert_data, "mailman_password='$mailman_password'");
push(@insert_data, "verify_key='$verify_key'"); push(@insert_data, "verify_key='$verify_key'");
push(@insert_data, "uid_uuid='$uuid'");
push(@insert_data, "uid_idx='$uid_idx'"); push(@insert_data, "uid_idx='$uid_idx'");
push(@insert_data, "uid='$uid'"); push(@insert_data, "uid='$uid'");
...@@ -440,8 +448,8 @@ sub Create($$$$) ...@@ -440,8 +448,8 @@ sub Create($$$$)
DBQueryWarn("insert into users set " . join(",", @insert_data)) DBQueryWarn("insert into users set " . join(",", @insert_data))
or return undef; or return undef;
if (! DBQueryWarn("insert into user_stats (uid, uid_idx) ". if (! DBQueryWarn("insert into user_stats (uid, uid_idx, uid_uuid) ".
"VALUES ('$uid', $uid_idx)")) { "VALUES ('$uid', $uid_idx, '$uuid')")) {
DBQueryFatal("delete from users where uid_idx='$uid_idx'"); DBQueryFatal("delete from users where uid_idx='$uid_idx'");
return undef; return undef;
} }
......
...@@ -108,7 +108,7 @@ my $create_string = ($query_result->fetchrow_array())[1]; ...@@ -108,7 +108,7 @@ my $create_string = ($query_result->fetchrow_array())[1];
# it simplifies backwards compatability. # it simplifies backwards compatability.
# #
DBQueryFatal("alter table temp_images ". DBQueryFatal("alter table temp_images ".
"drop pid_idx, drop gid_idx, drop creator_idx"); "drop pid_idx, drop gid_idx, drop creator_idx, drop uuid");
# #
# Before we dump the table contents, reset a few things. # Before we dump the table contents, reset a few things.
...@@ -174,7 +174,7 @@ $create_string = ($query_result->fetchrow_array())[1]; ...@@ -174,7 +174,7 @@ $create_string = ($query_result->fetchrow_array())[1];
# it simplifies backwards compatability. # it simplifies backwards compatability.
# #
DBQueryFatal("alter table temp_os_info ". DBQueryFatal("alter table temp_os_info ".
"drop pid_idx, drop creator_idx"); "drop pid_idx, drop creator_idx, drop uuid");
# #
# Before we dump the table contents, reset a few things. # Before we dump the table contents, reset a few things.
......
...@@ -86,6 +86,7 @@ my $pid = $protoproj->pid(); ...@@ -86,6 +86,7 @@ my $pid = $protoproj->pid();
my $pid_idx = $protoproj->pid_idx(); my $pid_idx = $protoproj->pid_idx();
my $gid = $protoproj->gid(); my $gid = $protoproj->gid();
my $gid_idx = $protoproj->gid_idx(); my $gid_idx = $protoproj->gid_idx();
my $douuids = 0;
# Temp tables to hold new rows. # Temp tables to hold new rows.
DBQueryFatal("create table temp_images like images"); DBQueryFatal("create table temp_images like images");
...@@ -120,6 +121,9 @@ while (my $rowref = $describe_result->fetchrow_hashref()) { ...@@ -120,6 +121,9 @@ while (my $rowref = $describe_result->fetchrow_hashref()) {
elsif ($slot eq "creator_idx") { elsif ($slot eq "creator_idx") {
DBQueryFatal("update temp_images set creator_idx='$user_idx'"); DBQueryFatal("update temp_images set creator_idx='$user_idx'");
} }
elsif ($slot eq "uuid") {
douuids++;
}
} }
# #
...@@ -160,6 +164,12 @@ while (my ($osid) = $query_result->fetchrow_array()) { ...@@ -160,6 +164,12 @@ while (my ($osid) = $query_result->fetchrow_array()) {
"where osid='$osid'"); "where osid='$osid'");
DBQueryFatal("update temp_os_info set nextosid='$newosid' ". DBQueryFatal("update temp_os_info set nextosid='$newosid' ".
"where nextosid='$osid'"); "where nextosid='$osid'");
if ($uuids) {
my $uuid = NewUUID();
DBQueryFatal("update temp_os_info set uuid='$uuid' ".
"where nextosid='$osid'");
}
} }
# #
...@@ -187,6 +197,13 @@ while (my ($imageid) = $query_result->fetchrow_array()) { ...@@ -187,6 +197,13 @@ while (my ($imageid) = $query_result->fetchrow_array()) {
DBQueryFatal("update temp_images set imageid='$newimageid' ". DBQueryFatal("update temp_images set imageid='$newimageid' ".
"where imageid='$imageid'"); "where imageid='$imageid'");
if ($uuids) {
my $uuid = NewUUID();
DBQueryFatal("update temp_images set uuid='$uuid' ".
"where imageid='$imageid'");
}
} }
# #
......
...@@ -562,6 +562,7 @@ CREATE TABLE `experiment_stats` ( ...@@ -562,6 +562,7 @@ CREATE TABLE `experiment_stats` (
`pid` varchar(12) NOT NULL default '', `pid` varchar(12) NOT NULL default '',
`pid_idx` mediumint(8) unsigned NOT NULL default '0', `pid_idx` mediumint(8) unsigned NOT NULL default '0',
`eid` varchar(32) NOT NULL default '', `eid` varchar(32) NOT NULL default '',
`eid_uuid` varchar(40) NOT NULL default '',
`creator` varchar(8) NOT NULL default '', `creator` varchar(8) NOT NULL default '',
`creator_idx` mediumint(8) unsigned NOT NULL default '0', `creator_idx` mediumint(8) unsigned NOT NULL default '0',
`exptidx` int(10) unsigned NOT NULL default '0', `exptidx` int(10) unsigned NOT NULL default '0',
...@@ -590,7 +591,8 @@ CREATE TABLE `experiment_stats` ( ...@@ -590,7 +591,8 @@ CREATE TABLE `experiment_stats` (
`dpdbname` varchar(64) default NULL, `dpdbname` varchar(64) default NULL,
PRIMARY KEY (`exptidx`), PRIMARY KEY (`exptidx`),
KEY `rsrcidx` (`rsrcidx`), KEY `rsrcidx` (`rsrcidx`),
KEY `pideid` (`pid`,`eid`) KEY `pideid` (`pid`,`eid`),
KEY `eid_uuid` (`eid_uuid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --
...@@ -860,6 +862,7 @@ CREATE TABLE `experiment_templates` ( ...@@ -860,6 +862,7 @@ CREATE TABLE `experiment_templates` (
DROP TABLE IF EXISTS `experiments`; DROP TABLE IF EXISTS `experiments`;
CREATE TABLE `experiments` ( CREATE TABLE `experiments` (
`eid` varchar(32) NOT NULL default '', `eid` varchar(32) NOT NULL default '',
`eid_uuid` varchar(40) NOT NULL default '',
`pid_idx` mediumint(8) unsigned NOT NULL default '0', `pid_idx` mediumint(8) unsigned NOT NULL default '0',
`gid_idx` mediumint(8) unsigned NOT NULL default '0', `gid_idx` mediumint(8) unsigned NOT NULL default '0',
`pid` varchar(12) NOT NULL default '', `pid` varchar(12) NOT NULL default '',
...@@ -953,7 +956,8 @@ CREATE TABLE `experiments` ( ...@@ -953,7 +956,8 @@ CREATE TABLE `experiments` (
UNIQUE KEY `pideid` (`pid`,`eid`), UNIQUE KEY `pideid` (`pid`,`eid`),
UNIQUE KEY `pididxeid` (`pid_idx`,`eid`), UNIQUE KEY `pididxeid` (`pid_idx`,`eid`),
KEY `batchmode` (`batchmode`), KEY `batchmode` (`batchmode`),
KEY `state` (`state`) KEY `state` (`state`),
KEY `eid_uuid` (`eid_uuid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --
...@@ -1131,6 +1135,7 @@ CREATE TABLE `group_stats` ( ...@@ -1131,6 +1135,7 @@ CREATE TABLE `group_stats` (
`gid` varchar(12) NOT NULL default '', `gid` varchar(12) NOT NULL default '',
`pid_idx` mediumint(8) unsigned NOT NULL default '0', `pid_idx` mediumint(8) unsigned NOT NULL default '0',
`gid_idx` mediumint(8) unsigned NOT NULL default '0', `gid_idx` mediumint(8) unsigned NOT NULL default '0',
`gid_uuid` varchar(40) NOT NULL default '',
`exptstart_count` int(11) unsigned default '0', `exptstart_count` int(11) unsigned default '0',
`exptstart_last` datetime default NULL, `exptstart_last` datetime default NULL,
`exptpreload_count` int(11) unsigned default '0', `exptpreload_count` int(11) unsigned default '0',
...@@ -1148,7 +1153,8 @@ CREATE TABLE `group_stats` ( ...@@ -1148,7 +1153,8 @@ CREATE TABLE `group_stats` (
`allexpt_pnodes` int(11) unsigned default '0', `allexpt_pnodes` int(11) unsigned default '0',
`allexpt_pnode_duration` int(11) unsigned default '0', `allexpt_pnode_duration` int(11) unsigned default '0',
PRIMARY KEY (`gid_idx`), PRIMARY KEY (`gid_idx`),
UNIQUE KEY `pidgid` (`pid`,`gid`) UNIQUE KEY `pidgid` (`pid`,`gid`),
KEY `gid_uuid` (`gid_uuid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --
...@@ -1161,6 +1167,7 @@ CREATE TABLE `groups` ( ...@@ -1161,6 +1167,7 @@ CREATE TABLE `groups` (
`gid` varchar(12) NOT NULL default '', `gid` varchar(12) NOT NULL default '',
`pid_idx` mediumint(8) unsigned NOT NULL default '0', `pid_idx` mediumint(8) unsigned NOT NULL default '0',
`gid_idx` mediumint(8) unsigned NOT NULL default '0', `gid_idx` mediumint(8) unsigned NOT NULL default '0',
`gid_uuid` varchar(40) NOT NULL default '',
`leader` varchar(8) NOT NULL default '', `leader` varchar(8) NOT NULL default '',
`leader_idx` mediumint(8) unsigned NOT NULL default '0', `leader_idx` mediumint(8) unsigned NOT NULL default '0',
`created` datetime default NULL, `created` datetime default NULL,
...@@ -1176,7 +1183,8 @@ CREATE TABLE `groups` ( ...@@ -1176,7 +1183,8 @@ CREATE TABLE `groups` (
KEY `unix_gid` (`unix_gid`), KEY `unix_gid` (`unix_gid`),
KEY `gid` (`gid`), KEY `gid` (`gid`),
KEY `pid` (`pid`), KEY `pid` (`pid`),
KEY `pididx` (`pid_idx`,`gid_idx`) KEY `pididx` (`pid_idx`,`gid_idx`),
KEY `gid_uuid` (`gid_uuid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --
...@@ -1196,7 +1204,7 @@ CREATE TABLE `iface_counters` ( ...@@ -1196,7 +1204,7 @@ CREATE TABLE `iface_counters` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --
-- Table structure for table `images ` -- Table structure for table `images`
-- --
DROP TABLE IF EXISTS `images`; DROP TABLE IF EXISTS `images`;
...@@ -1207,6 +1215,7 @@ CREATE TABLE `images` ( ...@@ -1207,6 +1215,7 @@ CREATE TABLE `images` (
`pid` varchar(12) NOT NULL default '', `pid` varchar(12) NOT NULL default '',
`gid` varchar(12) NOT NULL default '', `gid` varchar(12) NOT NULL default '',
`imageid` int(8) unsigned NOT NULL default '0', `imageid` int(8) unsigned NOT NULL default '0',
`uuid` varchar(40) NOT NULL default '',
`old_imageid` varchar(45) NOT NULL default '', `old_imageid` varchar(45) NOT NULL default '',
`creator` varchar(8) default NULL, `creator` varchar(8) default NULL,
`creator_idx` mediumint(8) unsigned NOT NULL default '0', `creator_idx` mediumint(8) unsigned NOT NULL default '0',
...@@ -1231,7 +1240,8 @@ CREATE TABLE `images` ( ...@@ -1231,7 +1240,8 @@ CREATE TABLE `images` (
PRIMARY KEY (`imageid`), PRIMARY KEY (`imageid`),
UNIQUE KEY `pid` (`pid`,`imagename`), UNIQUE KEY `pid` (`pid`,`imagename`),
KEY `gid` (`gid`), KEY `gid` (`gid`),
KEY `old_imageid` (`old_imageid`) KEY `old_imageid` (`old_imageid`),
KEY `uuid` (`uuid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --
...@@ -2070,6 +2080,7 @@ CREATE TABLE `os_info` ( ...@@ -2070,6 +2080,7 @@ CREATE TABLE `os_info` (
`pid` varchar(12) NOT NULL default '', `pid` varchar(12) NOT NULL default '',
`pid_idx` mediumint(8) unsigned NOT NULL default '0', `pid_idx` mediumint(8) unsigned NOT NULL default '0',
`osid` int(8) unsigned NOT NULL default '0', `osid` int(8) unsigned NOT NULL default '0',
`uuid` varchar(40) NOT NULL default '',
`old_osid` varchar(35) NOT NULL default '', `old_osid` varchar(35) NOT NULL default '',
`creator` varchar(8) default NULL, `creator` varchar(8) default NULL,
`creator_idx` mediumint(8) unsigned NOT NULL default '0', `creator_idx` mediumint(8) unsigned NOT NULL default '0',
...@@ -2094,7 +2105,8 @@ CREATE TABLE `os_info` ( ...@@ -2094,7 +2105,8 @@ CREATE TABLE `os_info` (
UNIQUE KEY `pid` (`pid`,`osname`), UNIQUE KEY `pid` (`pid`,`osname`),
KEY `OS` (`OS`), KEY `OS` (`OS`),
KEY `path` (`path`(255)), KEY `path` (`path`(255)),
KEY `old_osid` (`old_osid`) KEY `old_osid` (`old_osid`),
KEY `uuid` (`uuid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --
...@@ -2850,6 +2862,7 @@ DROP TABLE IF EXISTS `user_stats`; ...@@ -2850,6 +2862,7 @@ DROP TABLE IF EXISTS `user_stats`;
CREATE TABLE `user_stats` ( CREATE TABLE `user_stats` (
`uid` varchar(8) NOT NULL default '', `uid` varchar(8) NOT NULL default '',
`uid_idx` mediumint(8) unsigned NOT NULL default '0', `uid_idx` mediumint(8) unsigned NOT NULL default '0',
`uid_uuid` varchar(40) NOT NULL default '',
`weblogin_count` int(11) unsigned default '0', `weblogin_count` int(11) unsigned default '0',
`weblogin_last` datetime default NULL, `weblogin_last` datetime default NULL,
`exptstart_count` int(11) unsigned default '0', `exptstart_count` int(11) unsigned default '0',
...@@ -2868,7 +2881,8 @@ CREATE TABLE `user_stats` ( ...@@ -2868,7 +2881,8 @@ CREATE TABLE `user_stats` (
`allexpt_vnode_duration` int(11) unsigned default '0', `allexpt_vnode_duration` int(11) unsigned default '0',
`allexpt_pnodes` int(11) unsigned default '0', `allexpt_pnodes` int(11) unsigned default '0',
`allexpt_pnode_duration` int(11) unsigned default '0', `allexpt_pnode_duration` int(11) unsigned default '0',
PRIMARY KEY (`uid_idx`) PRIMARY KEY (`uid_idx`),
KEY `uid_uuid` (`uid_uuid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --
...@@ -2879,6 +2893,7 @@ DROP TABLE IF EXISTS `users`; ...@@ -2879,6 +2893,7 @@ DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` ( CREATE TABLE `users` (
`uid` varchar(8) NOT NULL default '', `uid` varchar(8) NOT NULL default '',
`uid_idx` mediumint(8) unsigned NOT NULL default '0', `uid_idx` mediumint(8) unsigned NOT NULL default '0',
`uid_uuid` varchar(40) NOT NULL default '',
`usr_created` datetime default NULL, `usr_created` datetime default NULL,
`usr_expires` datetime default NULL, `usr_expires` datetime default NULL,
`usr_modified` datetime default NULL, `usr_modified` datetime default NULL,
...@@ -2926,7 +2941,8 @@ CREATE TABLE `users` ( ...@@ -2926,7 +2941,8 @@ CREATE TABLE `users` (
PRIMARY KEY (`uid_idx`), PRIMARY KEY (`uid_idx`),
UNIQUE KEY `uid` (`uid`), UNIQUE KEY `uid` (`uid`),
KEY `unix_uid` (`unix_uid`), KEY `unix_uid` (`unix_uid`),
KEY `status` (`status`) KEY `status` (`status`),
KEY `uid_uuid` (`uid_uuid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --
......
...@@ -3971,3 +3971,10 @@ last_net_act,last_cpu_act,last_ext_act); ...@@ -3971,3 +3971,10 @@ last_net_act,last_cpu_act,last_ext_act);
alter table plab_slices add alter table plab_slices add
`slicemeta_legacy` text `slicemeta_legacy` text
after slicemeta; after slicemeta;
4.119: Add UUIDs to lots of tables.
All of the sql changes are made in the following script:
./step5_newids.pl
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2006, 2007 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use lib "/usr/testbed/lib";
use libdb;
use libtestbed;
#
# Untaint the path
#
$ENV{'PATH'} = '/bin:/usr/bin:/usr/sbin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# See if a table has been changed by looking for the existence of a field.
#
sub TableChanged($$)
{
my ($table, $slot) = @_;
my $describe_result =
DBQueryFatal("describe $table $slot");
return $describe_result->numrows;
}
# users
DBQueryFatal("lock tables users write, user_stats write");
if (! TableChanged("users", "uid_uuid")) {
DBQueryFatal("alter table users ".
"add `uid_uuid` varchar(40) NOT NULL default '' after uid_idx, ".
"add KEY uid_uuid (`uid_uuid`)");
}
if (! TableChanged("user_stats", "uid_uuid")) {
DBQueryFatal("alter table user_stats ".
"add `uid_uuid` varchar(40) NOT NULL default '' after uid_idx, ".
"add KEY uid_uuid (`uid_uuid`)");
}
my $query_result = DBQueryFatal("select uid_idx from users ".
"where uid_uuid=''");
while (my ($uid_idx) = $query_result->fetchrow_array()) {
my $uuid = NewUUID();
if (!defined($uuid)) {
die("*** $0:\n".
" Could not generate a UUID for user: $uid_idx\n");
}
DBQueryFatal("update users set uid_uuid='$uuid' where uid_idx='$uid_idx'");
DBQueryFatal("update user_stats set uid_uuid='$uuid' ".
"where uid_idx='$uid_idx'");
select(undef, undef, undef, 0.02);
}
$query_result = DBQueryFatal("select uid_idx from user_stats ".
"where uid_uuid=''");
while (my ($uid_idx) = $query_result->fetchrow_array()) {
my $uuid = NewUUID();
if (!defined($uuid)) {
die("*** $0:\n".
" Could not generate a UUID for user: $uid_idx\n");
}
DBQueryFatal("update user_stats set uid_uuid='$uuid' ".
"where uid_idx='$uid_idx'");
select(undef, undef, undef, 0.02);
}
DBQueryFatal("unlock tables");
# groups (no point in doing the project).
DBQueryFatal("lock tables groups write, group_stats write");
if (! TableChanged("groups", "gid_uuid")) {
DBQueryFatal("alter table groups ".
"add `gid_uuid` varchar(40) NOT NULL default '' after gid_idx, ".
"add KEY gid_uuid (`gid_uuid`)");
}
if (! TableChanged("group_stats", "gid_uuid")) {
DBQueryFatal("alter table group_stats ".
"add `gid_uuid` varchar(40) NOT NULL default '' after gid_idx, ".
"add KEY gid_uuid (`gid_uuid`)");
}
$query_result = DBQueryFatal("select gid_idx from groups ".
"where gid_uuid=''");
while (my ($gid_idx) = $query_result->fetchrow_array()) {
my $uuid = NewUUID();
if (!defined($uuid)) {
die("*** $0:\n".
" Could not generate a UUID for group: $gid_idx\n");
}
DBQueryFatal("update groups set gid_uuid='$uuid' ".
"where gid_idx='$gid_idx'");
DBQueryFatal("update group_stats set gid_uuid='$uuid' ".
"where gid_idx='$gid_idx'");
select(undef, undef, undef, 0.02);
}
$query_result = DBQueryFatal("select gid_idx from group_stats ".
"where gid_uuid=''");
while (my ($gid_idx) = $query_result->fetchrow_array()) {
my $uuid = NewUUID();
if (!defined($uuid)) {
die("*** $0:\n".
" Could not generate a UUID for group: $gid_idx\n");
}
DBQueryFatal("update group_stats set gid_uuid='$uuid' ".
"where gid_idx='$gid_idx'");
select(undef, undef, undef, 0.02);
}
DBQueryFatal("unlock tables");
# experiments
DBQueryFatal("lock tables experiments write, experiment_stats write");
if (! TableChanged("experiments", "eid_uuid")) {
DBQueryFatal("alter table experiments ".
"add `eid_uuid` varchar(40) NOT NULL default '' after eid, ".
"add KEY eid_uuid (`eid_uuid`)");
}
if (! TableChanged("experiment_stats", "eid_uuid")) {
DBQueryFatal("alter table experiment_stats ".
"add `eid_uuid` varchar(40) NOT NULL default '' after eid, ".
"add KEY eid_uuid (`eid_uuid`)");
}
$query_result = DBQueryFatal("select idx from experiments ".
"where eid_uuid=''");
while (my ($exptidx) = $query_result->fetchrow_array()) {
my $uuid = NewUUID();
if (!defined($uuid)) {
die("*** $0:\n".
" Could not generate a UUID for exptidx: $exptidx\n");
}
DBQueryFatal("update experiments set eid_uuid='$uuid' ".
"where idx='$exptidx'");
DBQueryFatal("update experiment_stats set eid_uuid='$uuid' ".
"where exptidx='$exptidx'");
select(undef, undef, undef, 0.02);
}
$query_result = DBQueryFatal("select exptidx from experiment_stats ".
"where eid_uuid=''");
while (my ($exptidx) = $query_result->fetchrow_array()) {
my $uuid = NewUUID();
if (!defined($uuid)) {
die("*** $0:\n".
" Could not generate a UUID for exptidx: $exptidx\n");
}
DBQueryFatal("update experiment_stats set eid_uuid='$uuid' ".
"where exptidx='$exptidx'");
select(undef, undef, undef, 0.02);
}
DBQueryFatal("unlock tables");
# images
DBQueryFatal("lock tables images write");
if (! TableChanged("images", "uuid")) {
DBQueryFatal("alter table images ".
"add `uuid` varchar(40) NOT NULL default '' after imageid, ".
"add KEY uuid (`uuid`)");
}
$query_result = DBQueryFatal("select imageid from images where uuid=''");
while (my ($imageid) = $query_result->fetchrow_array()) {
my $uuid = NewUUID();
if (!defined($uuid)) {
die("*** $0:\n".
" Could not generate a UUID for imageid: $imageid\n");
}
DBQueryFatal("update images set uuid='$uuid' ".
"where imageid='$imageid'");
select(undef, undef, undef, 0.02);
}
DBQueryFatal("unlock tables");
# os_info
DBQueryFatal("lock tables os_info write");
if (! TableChanged("os_info", "uuid")) {
DBQueryFatal("alter table os_info ".
"add `uuid` varchar(40) NOT NULL default '' after osid, ".
"add KEY uuid (`uuid`)");
}
$query_result = DBQueryFatal("select osid from os_info where uuid=''");
while (my ($osid) = $query_result->fetchrow_array()) {
my $uuid = NewUUID();
if (!defined($uuid)) {
die("*** $0:\n".
" Could not generate a UUID for osid: $osid\n");
}
DBQueryFatal("update os_info set uuid='$uuid' ".
"where osid='$osid'");
select(undef, undef, undef, 0.02);
}
DBQueryFatal("unlock tables");
...@@ -39,6 +39,8 @@ my $batchmode = 0; ...@@ -39,6 +39,8 @@ my $batchmode = 0;
my $pid_idx = 1; # Initial IDX for protoproj. my $pid_idx = 1; # Initial IDX for protoproj.
my $trust = "project_root"; my $trust = "project_root";
my $binshell = "/bin/nologin"; my $binshell = "/bin/nologin";
my $uid_uuid;
my $gid_uuid;
my $password; my $password;
my $encpass; my $encpass;
my %opts; my %opts;
...@@ -177,20 +179,25 @@ if ($CONTROL ne $BOSSNODE) { ...@@ -177,20 +179,25 @@ if ($CONTROL ne $BOSSNODE) {
} }
} }
# These users do not really need a uuid, but give them one anyway.
$uid_uuid = NewUUID();
# Initialize the index value; # Initialize the index value;
DBQueryFatal("replace into emulab_indicies set name='next_uid',idx=$uid+1"); DBQueryFatal("replace into emulab_indicies set name='next_uid',idx=$uid+1");
print "Creating user in database...\n"; print "Creating user in database...\n";
DBQueryFatal("insert into users set uid='$protouser', usr_created=now(), " . DBQueryFatal("insert into users set uid='$protouser', usr_created=now(), " .
"usr_name='$protouser_name', ". "usr_name='$protouser_name', uid_uuid='$uid_uuid', ".
"usr_addr='DO NOT DELETE THIS ACCOUNT', ". "usr_addr='DO NOT DELETE THIS ACCOUNT', ".
"usr_pswd='$encpass', unix_uid=$uid, notes='$protouser_notes', ". "usr_pswd='$encpass', unix_uid=$uid, notes='$protouser_notes', ".
"usr_modified=now(), admin=1, webonly=0, status='active',". "usr_modified=now(), admin=1, webonly=0, status='active',".
"usr_shell='$protouser_shell', usr_email='$protouser_email', ". "usr_shell='$protouser_shell', usr_email='$protouser_email', ".
"mailman_password='$mailman_password',uid_idx=$uid"); "mailman_password='$mailman_password',uid_idx=$uid");
DBQueryFatal("insert into user_stats set uid='$protouser',uid_idx=$uid"); DBQueryFatal("insert into user_stats set ".
" uid='$protouser', uid_idx=$uid, uid_uuid='$uid_uuid'");
if (!defined($opts{u})) { if (!defined($opts{u})) {
$gid_uuid = NewUUID();
print "Creating project in database...\n"; print "Creating project in database...\n";
DBQueryFatal("insert into projects set pid='$protoproj', created=now(), " . DBQueryFatal("insert into projects set pid='$protoproj', created=now(), " .
...@@ -204,9 +211,10 @@ if (!defined($opts{u})) { ...@@ -204,9 +211,10 @@ if (!defined($opts{u})) {
"leader='$protouser', leader_idx=$uid, created=now(), ". "leader='$protouser', leader_idx=$uid, created=now(), ".
"description='Default Group', " . "description='Default Group', " .
"unix_gid=$gid, gid_idx=