Commit dedc6495 authored by Leigh Stoller's avatar Leigh Stoller

Checkpoint new geni-lib param code, working on making it selectable

via emulab features, for testing.
parent 749a51b9
#
# Copyright (c) 2000-2018 University of Utah and the Flux Group.
# Copyright (c) 2000-2019 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -163,6 +163,9 @@ APTCSSFILES = $(wildcard $(SRCDIR)/aptui/css/*.css)
APTFONTS = $(wildcard $(SRCDIR)/aptui/fonts/*)
APTIMAGES = $(wildcard $(SRCDIR)/aptui/images/*)
APTNEWJSFILES = $(wildcard $(SRCDIR)/aptui/js/new/*.js)
APTNEWTEMPLATES = $(wildcard $(SRCDIR)/aptui/template/new/*.html)
# need to make it *.gz; with simply "*",
# we end up sucking over "CVS"
DOWNLOADFILES = $(wildcard $(SRCDIR)/downloads/*.gz)
......@@ -228,6 +231,9 @@ ALLAPTCSS = $(notdir $(APTCSSFILES))
ALLAPTFONTS = $(notdir $(APTFONTS))
ALLAPTIMAGES = $(notdir $(APTIMAGES))
ALLAPTNEWJS = $(notdir $(APTNEWJSFILES))
ALLAPTNEWTEMPLATES = $(notdir $(APTNEWTEMPLATES))
INSTALLFILES = $(addprefix $(INSTALL_SBINDIR)/, htmlinstall) \
$(addprefix $(INSTALL_WWWDIR)/, $(ALLFILES)) \
$(addprefix $(INSTALL_WWWDIR)/floormap/, $(ALLFLOORMAPS)) \
......@@ -276,7 +282,9 @@ apt-install: $(addprefix $(INSTALL_WWWDIR)/apt/, $(ALLAPTUI)) \
$(addprefix $(INSTALL_WWWDIR)/apt/template/, $(ALLAPTTEMPLATES)) \
$(addprefix $(INSTALL_WWWDIR)/apt/css/, $(ALLAPTCSS)) \
$(addprefix $(INSTALL_WWWDIR)/apt/fonts/, $(ALLAPTFONTS)) \
$(addprefix $(INSTALL_WWWDIR)/apt/images/, $(ALLAPTIMAGES))
$(addprefix $(INSTALL_WWWDIR)/apt/images/, $(ALLAPTIMAGES)) \
$(addprefix $(INSTALL_WWWDIR)/apt/js/new/, $(ALLAPTNEWJS)) \
$(addprefix $(INSTALL_WWWDIR)/apt/template/new/, $(ALLAPTNEWTEMPLATES))
cd $(INSTALL_WWWDIR) && \
rm -f portal; \
ln -s apt portal;
......
......@@ -127,7 +127,8 @@ function Do_GetParameters()
}
list ($formfrag, $defaults) = $profile->GenerateFormFragment($paramdefs);
SPITAJAX_RESPONSE(array("formfrag" => htmlentities($formfrag),
"defaults" => $defaults));
"defaults" => $defaults,
"paramdefs"=> json_decode($paramdefs)));
}
#
......
......@@ -561,7 +561,8 @@ $(function ()
ppdivname : "pp-container",
registered : registered,
isadmin : isadmin,
callback : ConfigureDone,
config_callback : ConfigureDone,
modified_callback : function () { ppchanged = true; },
rspec : null,
multisite : multisite,
jacksGraphCallback: updateJacksGraph
......
This diff is collapsed.
......@@ -6,7 +6,10 @@ $(function () {
{
'use strict';
var templates = APT_OPTIONS.fetchTemplateList(['ppform-wizard', 'ppform-wizard-body', 'choose-am', 'image-picker-modal']);
var templates = APT_OPTIONS.fetchTemplateList(['ppform-wizard',
'ppform-wizard-body',
'choose-am',
'image-picker-modal']);
var ppmodalString = templates['ppform-wizard'];
var ppbodyString = templates['ppform-wizard-body'];
var chooserString = templates['choose-am'];
......@@ -22,6 +25,7 @@ $(function () {
var multisite = 0;
var RSPEC = null;
var configuredone_callback = null;
var modified_callback = null;
var warningsfatal = 1;
var imagePicker = null;
......@@ -727,7 +731,8 @@ $(function () {
// Caller might already have an editor instance.
//editor = new JacksEditor($('#inline_jacks'), true, true,
// true, true, !multisite);
configuredone_callback = args.callback;
configuredone_callback = args.config_callback;
modified_callback = args.modified_callback;
/*
* Need to ask for the profile parameter form fragment and
......
<?php
#
# Copyright (c) 2000-2018 University of Utah and the Flux Group.
# Copyright (c) 2000-2019 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -808,7 +808,7 @@ function Do_CheckScript()
#
# Run geni-lib script, with given parameters, to generate an rspec.
# This is called frm instantiate.ajax. Looks there to see $profile magic.
# This is called from instantiate.ajax. Looks there to see $profile magic.
#
function Do_BindParameters()
{
......@@ -817,6 +817,9 @@ function Do_BindParameters()
global $DEFAULT_AGGREGATE;
global $suexec_output, $suexec_output_array;
# Allow for new code path.
$newparams = isset($ajax_args["newparams"]) && $ajax_args["newparams"];
# Allow for form precheck only. So JS code knows it will be fast.
$checkonly = isset($ajax_args["checkonly"]) && $ajax_args["checkonly"];
......@@ -871,11 +874,20 @@ function Do_BindParameters()
unset($formfields["script"]);
unset($formfields["paramdefs"]);
if ($newparams) {
if (Do_CheckFormNew($formfields, $paramdefs, $rval)) {
# Special return value for JS code.
SPITAJAX_ERROR(2, $rval);
return;
}
}
else {
if (Do_CheckForm($formfields, $paramdefs, $rval)) {
# Special return value for JS code.
SPITAJAX_ERROR(2, $rval);
return;
}
}
if ($checkonly) {
SPITAJAX_RESPONSE(0);
return;
......@@ -894,7 +906,12 @@ function Do_BindParameters()
fwrite($fp, $script);
fclose($fp);
$fp = fopen($parmfname, "w");
if ($newparams) {
fwrite($fp, json_encode($formfields));
}
else {
fwrite($fp, json_encode($rval));
}
fwrite($fp, "\n");
fclose($fp);
chmod($infname, 0666);
......@@ -907,7 +924,7 @@ function Do_BindParameters()
$retval = SUEXEC($this_uid, "nobody",
"webrungenilib $warningsfatal -b $parmfname ".
" -o $outfname $infname",
SUEXEC_ACTION_IGNORE);
SUEXEC_ACTION_CONTINUE);
if ($retval != 0) {
if ($retval < 0) {
......@@ -943,6 +960,135 @@ function Do_BindParameters()
SPITAJAX_RESPONSE($blob);
}
#
# Check the form arguments.
#
function CheckBindingType($value, $type, &$error)
{
$rval = 0;
if ($type == "boolean") {
if ($value != true && $value != false) {
$error = "Invalid value; must be a boolean";
$rval = 1;
}
}
elseif ($type == "integer" || $type == "size") {
if (!is_numeric($value)) {
$error = "Invalid value; must be an integer";
$rval = 1;
}
}
elseif ($type == "bandwidth" || $type == "latency" || $type == "lossrate") {
if (!is_numeric($value)) {
$error = "Invalid value; must be an integer/float";
$rval = 1;
}
}
elseif ($type == "string" || $type == "image" || $type == "aggregate" ||
$type == "nodetype") {
if (!TBcheck_dbslot($value, "default", "html_fulltext",
TBDB_CHECKDBSLOT_WARN|TBDB_CHECKDBSLOT_ERROR)) {
$error = "Invalid value: " . TBFieldErrorString();
$rval = 1;
}
}
else {
$error = "Invalid value; do not know how to handle $type";
$rval = 1;
}
return $rval;
}
function CheckBinding($definition, &$binding, &$errors)
{
$type = $definition["type"];
$mvalue = $definition["multiValue"];
$error = null;
$count = count($errors);
#
# Most of these make no sense to be multivalue.
#
if ($mvalue) {
foreach ($binding["value"] as &$B) {
if (CheckBindingType($B["value"], $type, $error)) {
$errors["$count"] = array("message" => $error);
$B["errors"] = array($count);
$count++;
}
}
}
else {
if (CheckBindingType($binding["value"], $type, $error)) {
$errors["$count"] = array("message" => $error);
$binding["errors"] = array($count);
$count++;
}
}
}
function Do_CheckFormNew($formfields, $paramdefs, &$rval)
{
global $this_user;
global $ajax_args;
$count = 0;
$errors = array();
$fields = json_decode($paramdefs, true);
foreach ($formfields["bindings"] as $name => &$binding) {
# Let unknown stuff pass through. Maybe not a good idea?
if (!array_key_exists($name, $fields)) {
continue;
}
$def = $fields[$name];
$type = $def["type"];
$mvalue = $def["multiValue"];
$error = null;
if ($type == "pubkey") {
if (isset($_SESSION["pubkey"]) || GenGenilibKey() == 0) {
$binding["value"] = $_SESSION["pubkey"];
}
else {
$errors["$count"] = array("message" => "Pubkey error");
$binding["errors"] = array($count);
$count++;
}
}
elseif ($type == "struct") {
if ($mvalue) {
// Array of dicts.
foreach ($binding["value"] as &$B) {
foreach ($B["value"] as $paramname => &$BB) {
$definition = $def["parameters"][$paramname];
CheckBinding($definition, $BB, $errors);
}
}
}
else {
// A single dict.
foreach ($binding["value"] as $paramname => &$B) {
$definition = $def["parameters"][$paramname];
CheckBinding($definition, $B, $errors);
}
}
}
else {
CheckBinding($def, $binding, $errors);
}
}
if (count($errors)) {
$formfields["errors"] = $errors;
$rval = $formfields;
return -1;
}
return 0;
}
#
# Check the form arguments.
#
......
<style>
.tooltip-inner {
text-align: left;
}
.panel-heading-list {
padding: 2px;
}
.panel-body-dashboard {
padding: 2px;
}
.group-row {
border: 1px solid grey;
}
.group-row,
.group-row .panel {
//background-color: #ebf2fa !important;
margin-bottom: -1px;
}
.structset {
border: 1px solid grey;
margin-bottom: -1px;
}
.struct-row,
.struct-row .panel {
//background-color: #ebf2fa !important;
}
.resgraph-size {
max-height:300px;
height:300px;
......
<div>
<form id='pp_form'
class='form-horizontal' role='form' method='post'>
<div class='row'>
<div class='col-sm-12'>
</div>
</div>
</form>
<div id="image-picker-body"></div>
</div>
<div>
<div class='panel panel-default'>
<div class='panel-heading'>
This profile is parameterized; please make your selections below,
and then click to continue.
</div>
<div class='panel-body' style="padding-bottom: 0px;">
<div id='ppmodal-body'>
</div>
</div>
</div>
</div>
This diff is collapsed.
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