Commit 36fa2965 authored by Leigh Stoller's avatar Leigh Stoller

Add nodeuuid method to fullconfig. We use this to determine if a VM is

stale.
parent e5de349f
......@@ -23,6 +23,7 @@
#define TBDB_FLEN_SFSHOSTID 128
#define TBDB_FLEN_RPMS 4096
#define TBDB_FLEN_TINYTEXT (256 + 1)
#define TBDB_FLEN_UUID (64 + 1)
/*
* Event system stuff.
......
......@@ -23,7 +23,7 @@ use Exporter;
gettraceconfig genhostsfile getmotelogconfig calcroutes fakejailsetup
getlocalevserver genvnodesetup getgenvnodeconfig stashgenvnodeconfig
getlinkdelayconfig getloadinfo getbootwhat
forcecopy
forcecopy getnodeuuid
getmanifest fetchmanifestblobs runbootscript runhooks
build_fake_macs
......@@ -39,7 +39,7 @@ use Exporter;
CONFDIR LOGDIR TMDELAY TMBRIDGES TMJAILNAME TMSIMRC TMCC TMCCBIN
TMNICKNAME TMSTARTUPCMD FINDIF
TMROUTECONFIG TMLINKDELAY TMDELMAP TMTOPOMAP TMLTMAP TMLTPMAP
TMGATEDCONFIG TMSYNCSERVER TMKEYHASH TMNODEID TMEVENTKEY
TMGATEDCONFIG TMSYNCSERVER TMKEYHASH TMNODEID TMNODEUUID TMEVENTKEY
TMCREATOR TMSWAPPER TMFWCONFIG TMGENVNODECONFIG
INXENVM
);
......@@ -356,6 +356,7 @@ sub TMSYNCSERVER() { CONFDIR() . "/syncserver";}
sub TMKEYHASH() { CONFDIR() . "/keyhash";}
sub TMEVENTKEY() { CONFDIR() . "/eventkey";}
sub TMNODEID() { CONFDIR() . "/nodeid";}
sub TMNODEUUID() { CONFDIR() . "/nodeuuid";}
sub TMROLE() { CONFDIR() . "/role";}
sub TMSIMRC() { CONFDIR() . "/rc.simulator";}
sub TMCREATOR() { CONFDIR() . "/creator";}
......@@ -706,6 +707,9 @@ sub donodeid()
my $nodeid;
my @tmccresults;
# Do this too.
donodeuuid();
if (tmcc(TMCCCMD_NODEID, undef, \@tmccresults) < 0) {
warn("*** WARNING: Could not get nodeid from server!\n");
return -1;
......@@ -731,6 +735,39 @@ sub donodeid()
return 0;
}
#
# Get the nodeuuid
#
sub donodeuuid()
{
my $nodeuuid;
my @tmccresults;
if (tmcc(TMCCCMD_NODEUUID, undef, \@tmccresults) < 0) {
warn("*** WARNING: Could not get nodeuuid from server!\n");
return -1;
}
return 0
if (! @tmccresults);
#
# There should be just one string. Ignore anything else.
#
if ($tmccresults[0] =~ /([-\w]*)/) {
$nodeuuid = $1;
}
else {
warn "*** WARNING: Bad nodeuuid line: $tmccresults[0]";
return -1;
}
system("echo '$nodeuuid' > ". TMNODEUUID);
if ($?) {
warn "*** WARNING: Could not write nodeuuid to " . TMNODEUUID() . "\n";
}
return 0;
}
#
# Get the boot script manifest -- whether scripts are enabled, or hooked, and
# how and when they or their hooks run!
......@@ -3050,6 +3087,20 @@ sub whatsmynickname()
return "$vname.$eid.$pid";
}
#
# Return uuid for node.
#
sub getnodeuuid()
{
my $uuidfile = TMNODEUUID();
my $nodeuuid = `cat $uuidfile`;
return undef
if ($?);
chomp($nodeuuid);
return $nodeuuid;
}
#
# Return the hostname or IP to use for a local event server.
# Defaults to "localhost" for most nodes or the physical host IP for Xen VMs.
......
......@@ -35,6 +35,7 @@ use Exporter;
TMCCCMD_MOTELOG TMCCCMD_BOOTWHAT TMCCCMD_ROOTPSWD
TMCCCMD_LTMAP TMCCCMD_LTPMAP TMCCCMD_TOPOMAP TMCCCMD_LOADINFO
TMCCCMD_TPMBLOB TMCCCMD_TPMPUB TMCCCMD_DHCPDCONF TMCCCMD_MANIFEST
TMCCCMD_NODEUUID
);
# Must come after package declaration!
......@@ -195,6 +196,7 @@ my %commandset =
"loadinfo" => {TAG => "loadinfo"},
"dhcpdconf" => {TAG => "dhcpdconf"},
"manifest" => {TAG => "manifest"},
"nodeuuid" => {TAG => "nodeuuid"},
);
#
......@@ -265,6 +267,7 @@ sub TMCCCMD_TPMPUB() { $commandset{"tpmpubkey"}->{TAG}; }
sub TMCCCMD_LOADINFO() { $commandset{"loadinfo"}->{TAG}; }
sub TMCCCMD_DHCPDCONF() { $commandset{"dhcpdconf"}->{TAG}; }
sub TMCCCMD_MANIFEST() { $commandset{"manifest"}->{TAG}; }
sub TMCCCMD_NODEUUID() { $commandset{"nodeuuid"}->{TAG}; }
#
# Caller uses this routine to set configuration of this library
......
......@@ -209,6 +209,7 @@ typedef struct {
char testdb[TBDB_FLEN_TINYTEXT];
char sharing_mode[TBDB_FLEN_TINYTEXT];
char privkey[PRIVKEY_LEN+1];
char nodeuuid[TBDB_FLEN_UUID];
/* This key is a replacement for privkey, on protogeni resources */
char external_key[PRIVKEY_LEN+1];
} tmcdreq_t;
......@@ -229,6 +230,7 @@ static event_handle_t event_handle = NULL;
COMMAND_PROTOTYPE(doreboot);
COMMAND_PROTOTYPE(donodeid);
COMMAND_PROTOTYPE(donodeuuid);
COMMAND_PROTOTYPE(domanifest);
COMMAND_PROTOTYPE(dostatus);
COMMAND_PROTOTYPE(doifconfig);
......@@ -337,6 +339,7 @@ struct command {
} command_array[] = {
{ "reboot", FULLCONFIG_NONE, 0, doreboot },
{ "nodeid", FULLCONFIG_ALL, 0, donodeid },
{ "nodeuuid", FULLCONFIG_ALL, 0, donodeuuid },
{ "manifest", FULLCONFIG_ALL, 0, domanifest },
{ "status", FULLCONFIG_NONE, 0, dostatus },
{ "ifconfig", FULLCONFIG_ALL, F_ALLOCATED, doifconfig },
......@@ -1391,6 +1394,18 @@ COMMAND_PROTOTYPE(donodeid)
return 0;
}
/*
* Return emulab node uuid.
*/
COMMAND_PROTOTYPE(donodeuuid)
{
char buf[MYBUFSIZE];
OUTPUT(buf, sizeof(buf), "%s\n", reqp->nodeuuid);
client_writeback(sock, buf, strlen(buf), tcp);
return 0;
}
/*
* Return a boot manifest for the node's boot scripts.
*/
......@@ -5992,7 +6007,7 @@ iptonodeid(struct in_addr ipaddr, tmcdreq_t *reqp, char* nodekey)
" u.admin,dedicated_wa_types.attrvalue "
" AS isdedicated_wa, "
" r.genisliver_idx,r.tmcd_redirect, "
" r.sharing_mode,e.geniflags "
" r.sharing_mode,e.geniflags,n.uuid "
"FROM nodes AS n "
"LEFT JOIN reserved AS r ON "
" r.node_id=n.node_id "
......@@ -6021,7 +6036,7 @@ iptonodeid(struct in_addr ipaddr, tmcdreq_t *reqp, char* nodekey)
" (SELECT node_id FROM widearea_nodeinfo "
" WHERE privkey='%s') "
" AND notmcdinfo_types.attrvalue IS NULL",
34, nodekey);
35, nodekey);
}
else if (reqp->isvnode) {
char clause[BUFSIZ];
......@@ -6050,7 +6065,7 @@ iptonodeid(struct in_addr ipaddr, tmcdreq_t *reqp, char* nodekey)
" e.idx,e.creator_idx,e.swapper_idx, "
" u.admin,null, "
" r.genisliver_idx,r.tmcd_redirect, "
" r.sharing_mode,e.geniflags "
" r.sharing_mode,e.geniflags,nv.uuid "
"from nodes as nv "
"left join nodes as np on "
" np.node_id=nv.phys_nodeid "
......@@ -6071,7 +6086,7 @@ iptonodeid(struct in_addr ipaddr, tmcdreq_t *reqp, char* nodekey)
"left join users as u on "
" u.uid_idx=e.swapper_idx "
"where nv.node_id='%s' and (%s)",
34, reqp->vnodeid, clause);
35, reqp->vnodeid, clause);
}
else {
char clause[BUFSIZ];
......@@ -6099,7 +6114,7 @@ iptonodeid(struct in_addr ipaddr, tmcdreq_t *reqp, char* nodekey)
" u.admin,dedicated_wa_types.attrvalue "
" as isdedicated_wa, "
" r.genisliver_idx,r.tmcd_redirect, "
" r.sharing_mode,e.geniflags "
" r.sharing_mode,e.geniflags,n.uuid "
"from interfaces as i "
"left join nodes as n on n.node_id=i.node_id "
"left join reserved as r on "
......@@ -6127,7 +6142,7 @@ iptonodeid(struct in_addr ipaddr, tmcdreq_t *reqp, char* nodekey)
" on n.type=dedicated_wa_types.type "
"where (%s) "
" and notmcdinfo_types.attrvalue is NULL",
34, clause);
35, clause);
}
if (!res) {
......@@ -6153,6 +6168,7 @@ iptonodeid(struct in_addr ipaddr, tmcdreq_t *reqp, char* nodekey)
strncpy(reqp->pclass, row[14], sizeof(reqp->pclass));
strncpy(reqp->ptype, row[15], sizeof(reqp->ptype));
strncpy(reqp->nodeid, row[2], sizeof(reqp->nodeid));
strncpy(reqp->nodeuuid, row[34], sizeof(reqp->nodeuuid));
if(nodekey != NULL) {
strncpy(reqp->privkey, nodekey, PRIVKEY_LEN);
}
......
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