Commit 04340eae authored by Leigh Stoller's avatar Leigh Stoller

Add support for running in either anon mode (for checking) and in project

context for actually creating a profile from an NS script.
parent b5ce01c4
......@@ -35,13 +35,18 @@ use File::stat;
#
sub usage()
{
print STDOUT "Usage: ns2rspec [options] nsfile\n";
print STDERR "Usage: ns2rspec [-a | -p pid] [-o filename] nsfile\n";
print STDERR "Options:\n";
print STDERR " -p pid : Run in context of project (permission checks)\n";
print STDERR " -a : Run in anon mode (no project checks)\n";
print STDERR" -o file : Specify output file\n";
exit(-1);
}
my $optlist = "do:";
my $optlist = "dao:p:";
my $debug = 0;
my $anonmode = 0;
my $ofile;
my $pid;
#
# Configure variables
......@@ -53,7 +58,6 @@ my $PARSENS = "$TB/libexec/parse-ns";
my $NSGENILIB= "$TB/bin/nsgenilib.py";
# Locals
my $this_user;
my $nsfile;
# Protos
......@@ -80,6 +84,7 @@ if ($UID == 0) {
use lib "@prefix@/lib";
use libdb;
use libtestbed;
use Project;
use User;
#
......@@ -93,9 +98,15 @@ if (! getopts($optlist, \%options)) {
if (defined($options{"d"})) {
$debug = 1;
}
if (defined($options{"a"})) {
$anonmode = 1;
}
if (defined($options{"o"})) {
$ofile = $options{"o"};
}
if (defined($options{"p"})) {
$pid = $options{"p"};
}
if (@ARGV != 1) {
usage();
}
......@@ -111,6 +122,20 @@ else {
die("Bad data in argument: $nsfile.");
}
my $this_user = User->ThisUser();
if (! defined($this_user)) {
Fatal("You ($UID) do not exist!");
}
if (defined($pid)) {
my $project = Project->Lookup($pid);
if (!defined($project)) {
Fatal("No such project");
}
if (! ($this_user->IsAdmin() || defined($project->LookupUser($this_user)))) {
Fatal("No a member of project $pid");
}
}
my $tmpdir = mktemp("/tmp/ns2rspec.XXXXXX");
my $irfile = "irfile.xml";
my $xmlfile = "rspec.xml";
......@@ -123,10 +148,14 @@ if (! chdir($tmpdir)) {
}
#
# Use the NS parser in anon mode, to generate the intermediate
# representation.
# When coming in from the web interface, we run in anonmode to parse without
# a project (since the portal sets the project later). Instead, we will rerun
# the parser again when the user creates the experiment sicne then we know the
# project context.
#
open ERR, "$PARSENS -n -p -a -c $nsfile 2>&1 > $irfile |";
my $parseopts = ($anonmode ? "-n -p -a" : "-n -r $pid $pid");
open ERR, "$PARSENS -c $parseopts $nsfile 2>&1 > $irfile |";
#
# Now read in the results from stderr.
......@@ -167,6 +196,10 @@ close(XML);
system("/bin/mv $xmlfile $irfile") == 0 or
fatal("Could not rename irfile");
if ($debug) {
system("/bin/cat $irfile");
}
#
# The next thing is to feed the IR output of the NS parser into
# our geni-lib converter.
......
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