Commit ce54a9ee authored by Leigh B Stoller's avatar Leigh B Stoller

Some minor code cleanup.

parent da17d2ff
#!/usr/bin/perl -w #!/usr/bin/perl -w
# #
# Copyright (c) 2000-2017 University of Utah and the Flux Group. # Copyright (c) 2000-2018 University of Utah and the Flux Group.
# #
# {{{EMULAB-LICENSE # {{{EMULAB-LICENSE
# #
...@@ -112,7 +112,7 @@ sub CanDelete($$); ...@@ -112,7 +112,7 @@ sub CanDelete($$);
sub PublishProfile($); sub PublishProfile($);
sub InsertImageRecords($); sub InsertImageRecords($);
sub ListImages(); sub ListImages();
sub HandleScript($); sub GetScriptParameters($$);
sub VerifyXML($$); sub VerifyXML($$);
sub ModifyProfileInternal($$$); sub ModifyProfileInternal($$$);
...@@ -320,9 +320,15 @@ sub CreateProfile() ...@@ -320,9 +320,15 @@ sub CreateProfile()
$new_args{'repokey'} = $repokey; $new_args{'repokey'} = $repokey;
} }
# Script parameters # Script parameters
if (defined($script) && $script ne "") { if (defined($script) && $script ne "" && $script =~ /^import/m) {
my $paramdefs = HandleScript($script); my $paramdefs;
my $retval = GetScriptParameters($script, \$paramdefs);
if ($retval) {
if ($retval < 0) {
fatal("Could not get paramdefs: $paramdefs!");
}
UserError($paramdefs);
}
$new_args{"paramdefs"} = $new_args{"paramdefs"} =
$paramdefs if (defined($paramdefs) && $paramdefs ne ""); $paramdefs if (defined($paramdefs) && $paramdefs ne "");
} }
...@@ -684,19 +690,14 @@ sub ModifyProfileInternal($$$) ...@@ -684,19 +690,14 @@ sub ModifyProfileInternal($$$)
# For a Parameterized Profile, need to generate and store the form # For a Parameterized Profile, need to generate and store the form
# data. Only python scripts of course. # data. Only python scripts of course.
# #
my ($fh, $filename) = tempfile(UNLINK => 1); my $output;
if (!defined($fh)) { my $retval = GetScriptParameters($script, \$output);
$$pmsg = "Could not open temporary file for script"; if ($retval) {
return -1; if ($retval < 0) {
} fatal("Could not get paramdefs: $output!");
print $fh $script; }
my $output = emutil::ExecQuiet("$RUNGENILIB -p $filename"); UserError($output);
if ($?) {
$$pmsg = $output;
return $? >> 8;
} }
chomp($output);
# No versioning so need to clear existing paramdefs. # No versioning so need to clear existing paramdefs.
$update_args{"paramdefs"} = ($output ne "" ? $output : undef); $update_args{"paramdefs"} = ($output ne "" ? $output : undef);
} }
...@@ -946,7 +947,7 @@ sub UpdateProfileFromRepo() ...@@ -946,7 +947,7 @@ sub UpdateProfileFromRepo()
if ($?) { if ($?) {
print STDERR $output; print STDERR $output;
$profile->Unlock(); $profile->Unlock();
print STDERR "$RUNGENILIB failed\n"; print STDERR "UpdateProfileFromRepo: $RUNGENILIB failed\n";
# Pass along the exit value. # Pass along the exit value.
exit($? >> 8); exit($? >> 8);
} }
...@@ -989,23 +990,26 @@ sub UpdateProfileFromRepo() ...@@ -989,23 +990,26 @@ sub UpdateProfileFromRepo()
# For a Parameterized Profile, need to generate and store the form # For a Parameterized Profile, need to generate and store the form
# data. Only python scripts of course. Does not return on error. # data. Only python scripts of course. Does not return on error.
# #
sub HandleScript($) sub GetScriptParameters($$)
{ {
my ($script) = @_; my ($script, $pref) = @_;
return undef
if ($script !~ /^import/m);
my ($fh, $filename) = tempfile(UNLINK => 1); my ($fh, $filename) = tempfile(UNLINK => 1);
fatal("Could not open temporary file for script") if (!defined($fh)) {
if (!defined($fh)); $$pref = "Could not open temporary file for script";
return -1;
}
print $fh $script; print $fh $script;
my $paramdefs = `$RUNGENILIB -p $filename`;
fatal("$RUNGENILIB failed") my $output = emutil::ExecQuiet("$RUNGENILIB -p $filename");
if ($?); if ($?) {
chomp($paramdefs); $$pref = $output;
return $? >> 8;
return $paramdefs; }
chomp($output);
$$pref = $output;
return 0;
} }
exit(0); exit(0);
......
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