Commit 274ecd5e authored by Jonathon Duerig's avatar Jonathon Duerig

Basic support for rspec V2.

parent e4caadb3
......@@ -678,7 +678,11 @@ sub GetManifest($$)
#
my $valid_date = POSIX::strftime("20%y-%m-%dT%H:%M:%S",
gmtime(str2time($slice->expires())));
GeniXML::SetText("valid_until", $manifest, $valid_date);
if (GeniXML::IsVersion0($manifest)) {
GeniXML::SetText("valid_until", $manifest, $valid_date);
} else {
GeniXML::SetText("expires", $manifest, $valid_date);
}
return $manifest
if (!$asxml);
......
This diff is collapsed.
......@@ -606,7 +606,7 @@ sub Create($$$$$$)
{
# $rspec is a LibXML element representing a single node.
my ($class, $slice, $user, $resource_uuid, $rspec) = @_;
my $virtualization_type = GeniXML::GetText("virtualization_type", $rspec);
my $virtualization_type = GeniXML::GetVirtualizationType($rspec);
if (!defined($virtualization_type)) {
print STDERR "Node does not contain a virtualization_type\n";
return undef;
......@@ -682,22 +682,28 @@ sub Create($$$$$$)
#
# Add this stuff to the rspec (which becomes the manifest).
#
GeniXML::SetText("hostname", $rspec, $hostname);
GeniXML::SetText("sshdport", $rspec, $sshdport) if (defined($sshdport));
# This is a version 2.0 thing.
my $services = GeniXML::AddElement("services", $rspec);
my $login = GeniXML::AddElement("login", $services);
GeniXML::SetText("authentication", $login, "ssh-keys");
GeniXML::SetText("hostname", $login, $phostname);
GeniXML::SetText("port", $login, $sshdport);
if (GeniXML::IsVersion0($rspec)) {
GeniXML::SetText("hostname", $rspec, $hostname);
GeniXML::SetText("sshdport", $rspec, $sshdport)
if (defined($sshdport));
} else {
my $services = GeniXML::AddElement("services", $rspec);
my $login = GeniXML::AddElement("login", $services);
GeniXML::SetText("authentication", $login, "ssh-keys");
GeniXML::SetText("hostname", $login, $phostname);
GeniXML::SetText("port", $login, $sshdport);
}
my $sliver = GeniSliver->Create($slice, $user, $resource_uuid, "Node",
$resource_id, $hrn, $nickname, $rspec);
return undef
if (!defined($sliver));
GeniXML::SetText("sliver_uuid", $rspec, $sliver->uuid());
if (GeniXML::IsVersion0($rspec)) {
GeniXML::SetText("sliver_uuid", $rspec, $sliver->uuid());
} else {
GeniXML::SetText("sliver_id", $rspec, $sliver->sliver_urn());
}
return $sliver;
}
......@@ -743,7 +749,7 @@ sub Provision($;$)
my $pid = $experiment->pid();
my $eid = $experiment->eid();
my $virt_type = GeniXML::GetText("virtualization_type", $self->rspec());
my $virt_type = GeniXML::GetVirtualizationType($self->rspec());
if (!$node->isremotenode() &&
defined($virt_type) &&
$virt_type eq "emulab-vnode") {
......@@ -756,8 +762,7 @@ sub Provision($;$)
# Mark
$node->ModifyReservation({"genisliver_idx" => $self->idx()});
my $subtype = GeniXML::GetText("virtualization_subtype",
$self->rspec());
my $subtype = GeniXML::GetVirtualizationSubtype($self->rspec());
if (defined($subtype)) {
if (!$pnode->sharing_mode()) {
$pnode->ModifyReservation({"genisliver_idx" => $self->idx()});
......@@ -827,8 +832,7 @@ sub UnProvision($;$)
}
}
my $virt_type = GeniXML::GetText("virtualization_type",
$self->rspec());
my $virt_type = GeniXML::GetVirtualizationType($self->rspec());
if (!$node->isremotenode() &&
defined($virt_type) &&
$virt_type eq "emulab-vnode") {
......@@ -934,7 +938,7 @@ sub ProcessManifest($$)
#
foreach my $ref (GeniXML::FindNodes("n:node",
$manifest)->get_nodelist()) {
my $sliver_urn = GeniXML::GetText("sliver_urn", $ref);
my $sliver_urn = GeniXML::GetSliverId($ref);
if (defined($sliver_urn) && $sliver_urn eq $self->sliver_urn()) {
# startup command.
my $startupcmd = GeniXML::GetText("startup_command", $ref);
......@@ -1169,15 +1173,21 @@ sub Create()
#
# Add this stuff to the rspec (which becomes the manifest).
#
GeniXML::SetText("component_urn", $rspec, $component_urn);
if (GeniXML::IsVersion0($rspec)) {
GeniXML::SetText("component_urn", $rspec, $component_urn);
} else {
GeniXML::SetText("component_id", $rspec, $component_urn);
}
my $sliver = GeniSliver->Create($slice, $user, $interface_uuid,
"Interface", $resource_id,
$hrn, $nickname, $rspec);
return undef
if (!defined($sliver));
GeniXML::SetText("sliver_uuid", $rspec, $sliver->uuid());
if (GeniXML::IsVersion0($rspec)) {
GeniXML::SetText("sliver_uuid", $rspec, $sliver->uuid());
} else {
GeniXML::SetText("sliver_id", $rspec, $sliver->sliver_urn());
}
return $sliver;
}
......
......@@ -11,7 +11,12 @@ use Exporter;
use vars qw(@ISA @EXPORT);
@ISA = "Exporter";
@EXPORT = qw(Parse ParseFile FindNodes FindNodesNS FindFirst FindElement FindAttr IsLanNode IsLocalNode GetNodeId GetVirtualId GetManagerId SetText GetText CreateDocument AddElement PolicyExists);
@EXPORT = qw(Parse ParseFile GetVersion IsVersion0 FindNodes FindNodesNS
FindFirst FindElement FindAttr IsLanNode IsLocalNode IsTunnel GetExpires
GetNodeId GetVirtualId GetSliverId GetManagerId GetColocate GetSubnodeOf
GetVirtualizationType SetVirtualizationType GetVirtualizationSubtype
GetExclusive SetExclusive GetLinkManager SetText GetText Serialize
CreateDocument AddElement RemoveChild PolicyExists);
use English;
use XML::LibXML;
......@@ -21,14 +26,19 @@ use GeniHRN;
use GeniUtil;
use Carp qw(cluck carp);
use vars qw($RSPEC_0_1 $RSPEC_2);
use vars qw($RSPEC_0_1 $RSPEC_0_2 $RSPEC_2);
$RSPEC_0_1 = "0.1";
$RSPEC_0_2 = "0.2";
$RSPEC_2 = "2";
# Configure variables
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $NS_0_1 = "http://www.protogeni.net/resources/rspec/0.1";
my $NS_0_2 = "http://www.protogeni.net/resources/rspec/0.2";
my $NS_2 = "http://www.protogeni.net/resources/rspec/2";
# Returns the document element by parsing a given string. If the
# string fails to parse, returns undefined.
sub Parse($)
......@@ -70,9 +80,11 @@ sub GetVersion($)
my $result = $RSPEC_0_1;
my $ns = $node->namespaceURI();
if (defined($ns)) {
if ($ns eq "http://protogeni.net/resources/rspec/0.1") {
if ($ns eq $NS_0_1) {
$result = $RSPEC_0_1;
} elsif ($ns eq "http://protogeni.net/resources/rspec/2") {
} elsif ($ns eq $NS_0_2) {
$result = $RSPEC_0_2;
} elsif ($ns eq $NS_2) {
$result = $RSPEC_2;
} else {
carp("Unknown rspec namespace: " . $ns);
......@@ -82,6 +94,12 @@ sub GetVersion($)
return $result;
}
sub IsVersion0($)
{
my $version = GetVersion($_[0]);
return $version eq $RSPEC_0_1 || $version eq $RSPEC_0_2;
}
# Returns a NodeList for a given XPath using a given node as
# context. 'n' is defined to be the prefix for the namespace of the
# node.
......@@ -212,6 +230,43 @@ sub IsLocalNode($)
return $result;
}
sub IsTunnel($)
{
my ($link) = @_;
my $result = 0;
if (IsVersion0($link)) {
my $link_type = GetText("link_type", $link);
$result = (defined($link_type) && $link_type eq "tunnel");
} else {
my @types = FindNodes("n:link_type", $link);
foreach my $current (@types) {
my $name = GetText("name", $current);
if ($name eq "gre-tunnel") {
$result = 1;
last;
}
}
}
return $result;
}
sub GetExpires($)
{
my ($node) = @_;
return GetText("valid_until", $node) ||
GetText("expires", $node);
}
sub SetExpires($$)
{
my ($node, $arg) = @_;
if (IsVersion0($node)) {
SetText("valid_until", $node, $arg);
} else {
SetText("expires", $node, $arg);
}
}
# Returns the uuid or urn of an RSpec node or undef if it is not a node.
sub GetNodeId($)
{
......@@ -228,15 +283,13 @@ sub GetVirtualId($)
return GetText("virtual_id", $node) ||
GetText("nickname", $node) ||
GetText("client_id", $node);
<<<<<<< Updated upstream:protogeni/lib/GeniXML.pm.in
}
sub GetSliverId($)
{
my ($node) = @_;
return GetText("sliver_urn", $node);
=======
>>>>>>> Stashed changes:protogeni/lib/GeniXML.pm.in
return GetText("sliver_urn", $node)
|| GetText("sliver_id", $node);
}
sub GetManagerId($)
......@@ -247,6 +300,104 @@ sub GetManagerId($)
GetText("component_manager_id", $node);
}
sub GetColocate($)
{
my ($node) = @_;
my $result = GetText("colocate", $node) ||
GetText("phys_nickname", $node);
return $result;
}
sub GetSubnodeOf($)
{
my ($node) = @_;
my $result = undef;
if (IsVersion0($node)) {
$result = GetText("subnode_of", $node);
} else {
my @relations = FindNodes("n:relation", $node)->get_nodelist();
foreach my $current (@relations) {
if (GetText("type", $current) == "subnode_of") {
$result = GetText("client_id", $current);
last;
}
}
}
return $result;
}
sub GetVirtualizationType($)
{
my ($node) = @_;
my $result = "emulab-vnode";
if (IsVersion0($node)) {
$result = GetText("virtualization_type", $node);
}
return $result;
}
sub SetVirtualizationType($$)
{
my ($node, $arg) = @_;
my $result = 1;
if (IsVersion0($node)) {
$result = SetText("virtualization_type", $arg);
}
return $result;
}
sub GetVirtualizationSubtype($)
{
my ($node) = @_;
my $result = undef;
if (IsVersion0($node)) {
my $result = GeniXML::GetText("virtualization_subtype", $node);
} else {
my @types = FindNodes("n:type", $node)->get_nodelist();
foreach my $current (@types) {
my $parent = GetText("implemented_by", $current);
if (defined($parent)) {
$result = GetText("name", $current);
last;
}
}
}
return $result;
}
sub GetExclusive($)
{
my ($node) = @_;
my $exclusive = GetText("exclusive", $node);
my $result = $exclusive;
if (defined($exclusive) && ! IsVersion0($node)) {
$result = ($exclusive eq "true");
}
return $result;
}
sub SetExclusive($)
{
my ($node, $arg) = @_;
my $result = 1;
if (IsVersion0($node)) {
$result = SetText("exclusive", $node, $arg);
} else {
my $textArg = "false";
if ($arg) {
$textArg = "true";
}
$result = SetText("exclusive", $node, $textArg);
}
return $result;
}
sub GetLinkManager($)
{
my ($link) = @_;
return GetText("id", $link) || GetText("name", $link);
}
# Takes an attribute/element name, *NOT AN XPATH* and a node and sets
# the text of that node to a particular value. If the node is an
# attribute, the value is set. If it is an element with just a text
......
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