Commit 105f431a authored by Leigh Stoller's avatar Leigh Stoller

Add some unfinished code to handle finding the correct project for

an image.
parent a3d10a00
#!/usr/bin/perl -w
#
# Copyright (c) 2000-2016 University of Utah and the Flux Group.
# Copyright (c) 2000-2017 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -137,15 +137,15 @@ else {
my $this_user = User->ThisUser();
if (! defined($this_user)) {
Fatal("You ($UID) do not exist!");
fatal("You ($UID) do not exist!");
}
if (defined($pid)) {
my $project = Project->Lookup($pid);
if (!defined($project)) {
Fatal("No such project");
fatal("No such project");
}
if (! ($this_user->IsAdmin() || defined($project->LookupUser($this_user)))) {
Fatal("No a member of project $pid");
fatal("Not a member of project $pid");
}
}
......@@ -247,7 +247,9 @@ if ($debug) {
# The next thing is to feed the IR output of the NS parser into
# our geni-lib converter which produces the rspec.
#
open ERR, "$NSGENILIB $irfile 2>&1 > $xmlfile |";
my $opts = ($anonmode ? "" : "-p $pid");
open ERR, "$NSGENILIB $opts $irfile 2>&1 > $xmlfile |";
$errs = "";
while (<ERR>) {
......
......@@ -36,6 +36,12 @@ import HTMLParser
TB = "@prefix@";
OURDOMAIN = "@OURDOMAIN@";
TBPATH = os.path.join(TB, "lib")
if TBPATH not in sys.path:
sys.path.append(TBPATH)
pass
import libdb
# Testbed specific stuff
if False:
sys.path.append(TB + "/opsdir/lib/geni-lib")
......@@ -70,11 +76,34 @@ def Usage():
sys.exit(-1);
pass
#
# Helper function to find find osname.
#
def LookupImage(osname):
res = libdb.DBQueryFatal(
"select i.imagename from images as i "
"where i.pid=%s and i.imagename=%s",
(PID, osname))
if len(res) == 0:
return "emulab-ops" + "//" + osname
return PID + "//" + osname
pass
if len(sys.argv) < 2:
Usage();
pass
NSfile = sys.argv[1];
#
# Check for PID flag.
#
if len(sys.argv) > 2 and sys.argv[1] == "-p":
PID = sys.argv[2]
NSfile = sys.argv[3]
else:
PID = None
NSfile = sys.argv[1]
try:
tree = etree.parse(NSfile);
......@@ -133,10 +162,14 @@ for child in tree.getroot():
if element.tag == "osname" and element.text:
#
# Convert NS project/osname to rspec project//osname.
# But if no project, add emulab-ops (clearly wrong).
#
osname = element.text
if osname.find("/") < 0:
osname = "emulab-ops//" + osname
if PID == None:
osname = "emulab-ops//" + osname
else:
osname = LookupImage(osname);
pass
elif osname.find("//") < 0:
osname = osname.replace("/", "//");
pass
......
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