Commit c49a1df9 authored by Jonathon Duerig's avatar Jonathon Duerig

Various fixes for AM API v3.

All incoming rspecs are now validated with rspeclint.
Multiple Create calls are now permitted.
Slivers now have URNs at allocation time.
Delete now returns a list of ex-slivers.
Advertisement now specifies an operational state machine.
Other minor fixes.
parent 9692cd53
This diff is collapsed.
......@@ -2031,6 +2031,10 @@ sub GetTicketAuxAux($$$$$$$$$)
# the virt_nodes entry since exclusive is just a desire.
#
my $exclusive = (defined($node->sharing_mode()) ? "0" : "1");
# Set sliver urns in ticket
my $sliver_idx = TBGetUniqueIndex('next_sliver', 1);
my $sliver_urn = GeniHRN::Generate( "@OURDOMAIN@", "sliver", $sliver_idx );
if (GeniXML::IsVersion0($rspec)) {
GeniXML::SetText("component_urn", $rspec,
......@@ -2039,6 +2043,7 @@ sub GetTicketAuxAux($$$$$$$$$)
GeniXML::SetText("component_uuid", $rspec, $component_id);
GeniXML::SetText("component_manager_urn", $rspec, $ENV{'MYURN'});
GeniXML::SetText("component_manager_uuid", $rspec, $ENV{'MYUUID'});
GeniXML::SetText("sliver_urn", $rspec, $sliver_urn);
} else {
GeniXML::SetText("component_id", $rspec,
GeniHRN::Generate( $OURDOMAIN, "node",
......@@ -2051,6 +2056,7 @@ sub GetTicketAuxAux($$$$$$$$$)
$GeniXML::EMULAB_NS);
}
GeniXML::SetText("name", $vnoderef, $node->node_id());
GeniXML::SetText("sliver_id", $rspec, $sliver_urn);
}
GeniXML::SetExclusive($rspec, $exclusive);
......
......@@ -176,9 +176,18 @@ sub Create($$$$$$$$)
$hrn, $nickname, $rspec) = @_;
my @insert_data = ();
# Every sliver gets a new unique index.
my $idx = TBGetUniqueIndex('next_sliver', 1);
my $urn = GeniHRN::Generate("@OURDOMAIN@", "sliver", $idx);
my $urn;
# Get sliver id from the ticket if available.
if (defined($rspec)) {
$urn = GeniXML::GetSliverId($rspec);
}
# Otherwise, generate a fresh one.
if (! defined($urn)) {
# Every sliver gets a new unique index.
my $sliver_idx = TBGetUniqueIndex('next_sliver', 1);
$urn = GeniHRN::Generate("@OURDOMAIN@", "sliver", $sliver_idx);
}
my (undef, undef, $idx) = GeniHRN::Parse($urn);
# Sanity check.
my $certificate = GeniCertificate->Lookup($urn);
......
......@@ -19,7 +19,7 @@ PSBIN_STUFF = register_resources expire_daemon gencrl postcrl \
update reregister cleanupticket listhistory \
register_sliver sa_daemon genadmincredential \
getchcredential genallow_extcred advt-merge.py \
reservevlans delgeniuser delegatecredential \
reservevlans delgeniuser delegatecredential rspeclint \
updatecert fixcerts initcerts cacontrol webcacontrol
ifeq ($(ISCLEARINGHOUSE),1)
......
#!/usr/bin/perl -w
# GENIPUBLIC-COPYRIGHT
# Copyright (c) 2011 University of Utah and the Flux Group.
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and/or hardware specification (the "Work") to
# deal in the Work without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Work, and to permit persons to whom the Work
# is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Work.
#
# THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
# IN THE WORK.
#----------------------------------------------------------------------
#use English;
use Getopt::Std;
use XML::LibXML;
use XML::LibXML::XPathContext;
use XML::LibXML::NodeList;
sub usage
{
die("Usage: rspeclint [<namespace> <schema>]+ <document>\n\n".
"Schema and document locations are either paths or URLs.\n");
}
sub addSchema($$);
sub visit($);
sub verify($);
sub report($$);
%ns2file = ();
%ns2schema = ();
#my %options;
#
#if (! getopts('', \%options)) {
# usage();
#}
while (scalar(@ARGV) > 1) {
my $ns = shift(@ARGV);
my $schema = shift(@ARGV);
addSchema($ns, $schema);
}
if (scalar(@ARGV) != 1) {
usage();
}
my $parser = XML::LibXML->new(line_numbers => 1);
my $docfile = $ARGV[0];
my $doc;
eval {
$doc = $parser->parse_file($docfile);
};
if ($@) {
die("Failed to parse XML document at location $docfile: $@\n");
}
visit($doc->documentElement());
sub addSchema($$)
{
my ($ns, $file) = @_;
if (! exists($ns2file{$ns})) {
my $schema;
eval {
$schema = XML::LibXML::Schema->new(location => $file);
};
if ($@) {
die("Failed to load schema for namespace $ns from location $file\n: $@");
}
$ns2file{$ns} = $file;
$ns2schema{$ns} = $schema;
} else {
my $exemplar = $ns2file{$ns};
if ($exemplar ne $file) {
die("Schema location mismatch on namespace $ns: Original location is $exemplar while new location is $file\n");
}
}
# print STDERR "Added Schema $ns -- $file\n";
}
sub visit($)
{
my ($node) = @_;
my $nodens = $node->namespaceURI();
if (! defined($nodens)) {
report("Element has no namespace", $node);
}
# Add any new schemaLocation pairs
my $uri = "http://www.w3.org/2001/XMLSchema-instance";
my $xc = XML::LibXML::XPathContext->new();
$xc->registerNs('xsi', $uri);
my $schemaLocation = $xc->findnodes('@xsi:schemaLocation', $node)->pop();
if (defined($schemaLocation)) {
my @schemaList = split(/\s+/, $schemaLocation->nodeValue());
while (scalar(@schemaList) > 1) {
my $ns = shift(@schemaList);
my $file = shift(@schemaList);
addSchema($ns, $file);
}
if (scalar(@schemaList) == 1) {
report("schemaLocation tag has an odd number of fields",
$schemaLocation);
}
}
# Verify the node if it changes namespaces or is the root
my $parent = $node->parentNode();
my $parentns = $parent->namespaceURI();
if (!defined($parentns) || $parentns ne $nodens) {
verify($node);
}
# Recurse
for my $child ($node->childNodes()) {
if ($child->nodeType() == XML_ELEMENT_NODE) {
visit($child);
}
}
}
sub verify($)
{
my ($node) = @_;
my $ns = $node->namespaceURI();
if (! exists($ns2schema{$ns})) {
my $nodeStr = $node->nodeName();
print STDERR "Ignoring node $nodeStr with unknown namespace $ns\n";
return;
}
my $schema = $ns2schema{$ns};
eval {
my $clone = $node->cloneNode(1);
my $clonedoc = XML::LibXML::Document->createDocument("1.0", "UTF-8");
$clonedoc->setDocumentElement($clone);
$schema->validate($clonedoc);
};
if ($@) {
report("Failed validation with root at element: $@", $node);
}
}
sub report($$)
{
my ($error, $node) = @_;
my $line = $node->line_number();
my $nodeStr = $node->nodeName();
die("Line $line: $error: $nodeStr\n");
}
......@@ -59,6 +59,7 @@ try:
response_handler=geni_am_response_handler)
if response:
print "Sliver %s has been deleted." % (SLICENAME)
print str(response)
else:
msg = "Something went wrong. Sliver %s has not been deleted."
print msg % (SLICENAME)
......
......@@ -80,7 +80,7 @@ if rval:
Fatal("Could not get ticket")
pass
ticket = response["value"]
#print str(ticket)
print str(ticket)
sys.exit(0)
#
......@@ -88,17 +88,17 @@ sys.exit(0)
# Proper to dig out the rspec from the ticket and use that, modified if
# desired.
#
print "Got the ticket, doing a update on it. "
params = {}
params["slice_urn"] = myslice["urn"]
params["ticket"] = ticket
params["credentials"] = (slicecredential,)
params["rspec"] = rspec
params["impotent"] = 0
rval,response = do_method("cm", "UpdateTicket", params, version="2.0")
if rval:
Fatal("Could not update ticket")
pass
ticket = response["value"]
print "Updated the ticket."
print str(ticket)
#print "Got the ticket, doing a update on it. "
#params = {}
#params["slice_urn"] = myslice["urn"]
#params["ticket"] = ticket
#params["credentials"] = (slicecredential,)
#params["rspec"] = rspec
#params["impotent"] = 0
#rval,response = do_method("cm", "UpdateTicket", params, version="2.0")
#if rval:
# Fatal("Could not update ticket")
# pass
#ticket = response["value"]
#print "Updated the ticket."
#print str(ticket)
......@@ -91,6 +91,52 @@ if ($PGENISUPPORT) {
$cmurn = GeniHRN::Generate($OURDOMAIN, "authority", "cm");
}
$opstate = <<'OPSTATE';
<rspec_opstate xmlns="http://www.geni.net/resources/rspec/ext/opstate/1"
aggregate_manager_id="CMURN"
start="geni_notready">
<sliver_type name="raw-pc" />
<sliver_type name="emulab-openvz" />
<state name="geni_notready">
<action name="geni_start" next="geni_configuring">
<description>Boot the node</description>
</action>
<description>Raw PCs and VMs begin powered down or inactive. They
must be explicitly booted before use.</description>
</state>
<state name="geni_configuring">
<wait type="geni_success" next="geni_ready" />
<wait type="geni_failure" next="geni_failed" />
<description>Booting takes a significant amount of time, so it
happens asynchronously while the node is in this
state.</description>
</state>
<state name="geni_ready">
<action name="geni_restart" next="geni_configuring">
<description>Reboot the node</description>
</action>
<action name="geni_stop" next="geni_stopping">
<description>Power down or stop the node.</description>
</action>
<description>The node is up and ready to use.</description>
</state>
<state name="geni_stopping">
<wait type="geni_success" next="geni_notready" />
<wait type="geni_failure" next="geni_failed" />
<description>The node is being stopped or rebooted.</description>
</state>
<state name="geni_failed">
<description>The node has failed and requires administrator
intervention before it can be used. Please contact
the administrator for assistance.</description>
</state>
</rspec_opstate>
OPSTATE
$opstate =~ s/CMURN/$cmurn/g;
my $default_long = undef;
TBGetSiteVar('general/default_longitude', \$default_long);
my $default_lat = undef;
......@@ -1846,6 +1892,7 @@ sub print_header {
}
print "</rspec_shared_vlan>\n";
}
print $opstate . "\n";
}
}
}
......@@ -1866,7 +1913,6 @@ sub print_footer {
$times[5] + 1900, $times[4] + 1, $times[3],
$times[2], $times[1], $times[0]);
print ">\n";
my $cmurn = GeniHRN::Generate($OURDOMAIN, "authority", "cm");
my $cmurl = "@PROTOGENI_URL@";
print "<aggregate id=\"$cmurn\" url=\"$cmurl/am\">\n";
print "<aggregatetype>protogeni</aggregatetype>\n".
......
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