Commit 649a0107 authored by Jonathon Duerig's avatar Jonathon Duerig

Checkpoint. All the conversion is done, but I need to refactor the xpaths to...

Checkpoint. All the conversion is done, but I need to refactor the xpaths to account for brittleness in the xpath specification.
parent e25f7049
...@@ -17,7 +17,7 @@ LIB_SCRIPTS = GeniDB.pm GeniUser.pm \ ...@@ -17,7 +17,7 @@ LIB_SCRIPTS = GeniDB.pm GeniUser.pm \
GeniComponent.pm GeniCH.pm GeniEmulab.pm \ GeniComponent.pm GeniCH.pm GeniEmulab.pm \
GeniAuthority.pm GeniCertificate.pm GeniAggregate.pm \ GeniAuthority.pm GeniCertificate.pm GeniAggregate.pm \
GeniUtil.pm GeniRegistry.pm GeniUsage.pm GeniHRN.pm \ GeniUtil.pm GeniRegistry.pm GeniUsage.pm GeniHRN.pm \
GeniSES.pm GeniResource.pm GeniSES.pm GeniResource.pm GeniXML.pm
SBIN_SCRIPTS = plabnodewrapper plabslicewrapper SBIN_SCRIPTS = plabnodewrapper plabslicewrapper
SCRIPTS = addnode.pl genischemacheck.pl SCRIPTS = addnode.pl genischemacheck.pl
......
...@@ -26,6 +26,7 @@ use GeniRegistry; ...@@ -26,6 +26,7 @@ use GeniRegistry;
use GeniUtil; use GeniUtil;
use GeniUser; use GeniUser;
use GeniHRN; use GeniHRN;
use GeniXML;
use emutil; use emutil;
use Lan; use Lan;
use Data::Dumper; use Data::Dumper;
...@@ -646,29 +647,22 @@ sub GetManifest($$) ...@@ -646,29 +647,22 @@ sub GetManifest($$)
} }
my ($xml) = $query_result->fetchrow_array(); my ($xml) = $query_result->fetchrow_array();
my $manifest = my $manifest = GeniXML::Parse($xml);
eval { XMLin($xml, KeyAttr => [], if (!defined($manifest)) {
ForceArray => ["node", "link", "interface",
"interface_ref", "linkendpoints"]) };
if ($@) {
print STDERR "XMLin error reading manifest: $@\n";
return undef; return undef;
} }
# #
# Update the manifest ticket to reflect the current expiration time. # Update the manifest ticket to reflect the current expiration time.
# #
$manifest->{'valid_until'} = my $valid_date = POSIX::strftime("20%y-%m-%dT%H:%M:%S",
POSIX::strftime("20%y-%m-%dT%H:%M:%S", gmtime(str2time($slice->expires())));
gmtime(str2time($slice->expires()))); GeniXML::SetText("valid_until", $manifest, $valid_date);
return $manifest return $manifest
if (!$asxml); if (!$asxml);
$xml = eval { XMLout($manifest, "NoAttr" => 1, RootName => "manifest") }; $xml = $manifest->toString();
if ($@) {
print STDERR "XMLout error on manifest: $@\n";
return undef;
}
return $xml; return $xml;
} }
...@@ -1235,10 +1229,12 @@ sub Create($$$$$$) ...@@ -1235,10 +1229,12 @@ sub Create($$$$$$)
$linkrspec, $node1rspec, $node2rspec) = @_; $linkrspec, $node1rspec, $node2rspec) = @_;
my $clearinghouse; my $clearinghouse;
my $linkname = $linkrspec->{"nickname"} || $linkrspec->{"virtual_id"}; my $linkname = GeniXML::GetText("./n:nickname | ".
"./n:virtual_id", $linkrspec);
return undef return undef
if (!defined($linkname)); if (!defined($linkname));
my @interfaces = @{ $linkrspec->{'interface_ref'} }; my @interfaces = GeniXML::FindNodes("./n:interface_ref",
$linkrspec)->get_nodelist();
my $experiment = Experiment->Lookup($slice->uuid()); my $experiment = Experiment->Lookup($slice->uuid());
if (!defined($experiment)) { if (!defined($experiment)) {
...@@ -1269,8 +1265,8 @@ sub Create($$$$$$) ...@@ -1269,8 +1265,8 @@ sub Create($$$$$$)
my $iface2ref = $interfaces[1]; my $iface2ref = $interfaces[1];
# These are the ips of the tunnel. # These are the ips of the tunnel.
my $ip1 = $iface1ref->{'tunnel_ip'}; my $ip1 = GeniXML::GetText("./n:tunnel_ip", $iface1ref);
my $ip2 = $iface2ref->{'tunnel_ip'}; my $ip2 = GeniXML::GetText("./n:tunnel_ip", $iface2ref);
my $ctrlip1; my $ctrlip1;
my $ctrlip2; my $ctrlip2;
my $iface1; my $iface1;
...@@ -1295,7 +1291,8 @@ sub Create($$$$$$) ...@@ -1295,7 +1291,8 @@ sub Create($$$$$$)
} }
} }
else { else {
my $component = GeniComponent->Lookup($node1rspec->{'component_uuid'}); my $component_name = GeniXML::GetNodeId($node1rspec);
my $component = GeniComponent->Lookup($component_name);
my $blob; my $blob;
if (!defined($component)) { if (!defined($component)) {
...@@ -1304,10 +1301,10 @@ sub Create($$$$$$) ...@@ -1304,10 +1301,10 @@ sub Create($$$$$$)
# #
$clearinghouse = GeniRegistry::ClearingHouse->Create(); $clearinghouse = GeniRegistry::ClearingHouse->Create();
if ($clearinghouse->Resolve($node1rspec->{'component_uuid'}, if ($clearinghouse->Resolve($component_name,
"Component", \$blob) != 0) { "Component", \$blob) != 0) {
print STDERR "Could not lookup node at clearinghouse\n"; print STDERR "Could not lookup node at clearinghouse\n";
print STDERR Dumper($node1rspec); print STDERR $node1rspec->toString();
goto bad; goto bad;
} }
my $certificate = GeniCertificate->LoadFromString($blob->{'gid'}); my $certificate = GeniCertificate->LoadFromString($blob->{'gid'});
...@@ -1332,13 +1329,13 @@ sub Create($$$$$$) ...@@ -1332,13 +1329,13 @@ sub Create($$$$$$)
print STDERR "Could not create a registry client for $component\n"; print STDERR "Could not create a registry client for $component\n";
goto bad; goto bad;
} }
$registry->Resolve($node1rspec->{'component_uuid'}, "Node", \$blob); $registry->Resolve($component_name, "Node", \$blob);
$ctrlip1 = $blob->{'physctrl'} $ctrlip1 = $blob->{'physctrl'}
if (defined($blob) && exists($blob->{'physctrl'})); if (defined($blob) && exists($blob->{'physctrl'}));
if (!defined($ctrlip1)) { if (!defined($ctrlip1)) {
print STDERR "Could not get control IP for ". print STDERR "Could not get control IP for ".
"$node1rspec->{'component_uuid'} at $component\n"; "$component_name at $component\n";
goto bad; goto bad;
} }
} }
...@@ -1360,17 +1357,18 @@ sub Create($$$$$$) ...@@ -1360,17 +1357,18 @@ sub Create($$$$$$)
} }
else { else {
my $blob; my $blob;
my $component = GeniComponent->Lookup($node2rspec->{'component_uuid'}); my $component_name = GeniXML::GetNodeId($node2rspec);
my $component = GeniComponent->Lookup($component_name);
if (!defined($component)) { if (!defined($component)) {
# #
# Need to ask the clearinghouse where this node comes from. # Need to ask the clearinghouse where this node comes from.
# #
$clearinghouse = GeniRegistry::ClearingHouse->Create(); $clearinghouse = GeniRegistry::ClearingHouse->Create();
if ($clearinghouse->Resolve($node2rspec->{'component_uuid'}, if ($clearinghouse->Resolve($component_name,
"Component", \$blob) != 0) { "Component", \$blob) != 0) {
print STDERR "Could not lookup node at clearinghouse\n"; print STDERR "Could not lookup node at clearinghouse\n";
print STDERR Dumper($node2rspec); print STDERR $node2rspec->toString();
goto bad; goto bad;
} }
my $certificate = GeniCertificate->LoadFromString($blob->{'gid'}); my $certificate = GeniCertificate->LoadFromString($blob->{'gid'});
...@@ -1395,13 +1393,13 @@ sub Create($$$$$$) ...@@ -1395,13 +1393,13 @@ sub Create($$$$$$)
print STDERR "Could not create a registry client for $component\n"; print STDERR "Could not create a registry client for $component\n";
goto bad; goto bad;
} }
$registry->Resolve($node2rspec->{'component_uuid'}, "Node", \$blob); $registry->Resolve($component_name, "Node", \$blob);
$ctrlip2 = $blob->{'physctrl'} $ctrlip2 = $blob->{'physctrl'}
if (defined($blob) && exists($blob->{'physctrl'})); if (defined($blob) && exists($blob->{'physctrl'}));
if (!defined($ctrlip2)) { if (!defined($ctrlip2)) {
print STDERR "Could not get control IP for ". print STDERR "Could not get control IP for ".
"$node2rspec->{'component_uuid'} at $component\n"; "$component_name at $component\n";
goto bad; goto bad;
} }
} }
......
This diff is collapsed.
...@@ -19,6 +19,7 @@ use vars qw(@ISA @EXPORT); ...@@ -19,6 +19,7 @@ use vars qw(@ISA @EXPORT);
use GeniDB; use GeniDB;
use GeniCertificate; use GeniCertificate;
use GeniUtil; use GeniUtil;
use GeniXML;
use emutil qw(TBGetUniqueIndex); use emutil qw(TBGetUniqueIndex);
use English; use English;
use XML::Simple; use XML::Simple;
...@@ -122,7 +123,7 @@ sub Create($$$) ...@@ -122,7 +123,7 @@ sub Create($$$)
$self->{'owner_cert'} = $owner->GetCertificate(); $self->{'owner_cert'} = $owner->GetCertificate();
$self->{'string'} = undef; $self->{'string'} = undef;
$self->{'capabilities'} = undef; $self->{'capabilities'} = undef;
$self->{'extensions'} = undef; $self->{'extensions'} = XML::LibXML::NodeList->new();
$self->{'idx'} = undef; # Only set when stored to DB. $self->{'idx'} = undef; # Only set when stored to DB.
bless($self, $class); bless($self, $class);
...@@ -184,11 +185,8 @@ sub AddExtension($$$) ...@@ -184,11 +185,8 @@ sub AddExtension($$$)
return -1 return -1
if (!ref($self)); if (!ref($self));
my $newNode = XML::LibXML::Element->new($key);
if (!defined($self->extensions())) { $newNode->appendText($value);
$self->{'extensions'} = {};
}
$self->{'extensions'}->{$key} = $value;
return 0; return 0;
} }
...@@ -249,7 +247,7 @@ sub CreateFromSigned($$;$) ...@@ -249,7 +247,7 @@ sub CreateFromSigned($$;$)
unlink($filename); unlink($filename);
} }
# Use XML::Simple to convert to something we can mess with. # Use XML::LibXML to convert to something we can mess with.
my $parser = XML::LibXML->new; my $parser = XML::LibXML->new;
my $doc; my $doc;
eval { eval {
...@@ -259,28 +257,10 @@ sub CreateFromSigned($$;$) ...@@ -259,28 +257,10 @@ sub CreateFromSigned($$;$)
print STDERR "Failed to parse credential string: $@\n"; print STDERR "Failed to parse credential string: $@\n";
return undef; return undef;
} }
my $root = $doc->documentElement();
# Dig out the capabilities
my ($cap_node) = $doc->getElementsByTagName("privileges");
return undef
if (!defined($cap_node));
my $rawcapabilities =
eval { XMLin($cap_node->toString(),
ForceArray => [ "privilege" ] ) };
if ($@) {
print STDERR "XMLin error on capabilities: $@\n";
return undef;
}
my $capabilities = $rawcapabilities->{ "privilege" };
# Dig out the extensions # Dig out the extensions
my ($extensions_node) = $doc->getElementsByTagName("extensions"); my $extensions = GeniXML::FindNodes('//n:extensions/*', $root);
my $extensions = eval { XMLin($extensions_node->toString()) }
if (defined($extensions_node));
if ($@) {
print STDERR "XMLin error on extensions: $@\n";
return undef;
}
# UUID of the credential. # UUID of the credential.
my ($uuid_node) = $doc->getElementsByTagName("uuid"); my ($uuid_node) = $doc->getElementsByTagName("uuid");
...@@ -351,7 +331,7 @@ sub CreateFromSigned($$;$) ...@@ -351,7 +331,7 @@ sub CreateFromSigned($$;$)
} }
my $self = {}; my $self = {};
$self->{'capabilities'} = $capabilities; $self->{'capabilities'} = undef;
$self->{'extensions'} = $extensions; $self->{'extensions'} = $extensions;
$self->{'uuid'} = $this_uuid; $self->{'uuid'} = $this_uuid;
$self->{'valid_until'} = $expires; $self->{'valid_until'} = $expires;
...@@ -363,9 +343,44 @@ sub CreateFromSigned($$;$) ...@@ -363,9 +343,44 @@ sub CreateFromSigned($$;$)
$self->{'idx'} = undef; # Only set when stored to DB. $self->{'idx'} = undef; # Only set when stored to DB.
bless($self, $class); bless($self, $class);
# Dig out the capabilities
foreach my $cap (GeniXML::FindNodes('.//n:privileges/n:privilege',
$root)->get_nodelist()) {
my $name = GeniXML::FindElement('./n:name', $cap);
my $delegate = GeniXML::FindElement('./n:can_delegate', $cap);
if (defined($name) && defined($delegate)) {
$self->AddCapability($name->textContent(),
$delegate->textContent());
}
}
return $self; return $self;
} }
# 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.
#sub findnodes_n($$)
#{
# my ($path, $node) = @_;
# my $xc = XML::LibXML::XPathContext->new();
# my $ns = $node->namespaceURI();
# if (defined($ns)) {
# $xc->registerNs('ns', $node->namespaceURI());
# } else {
# $path =~ s/\bn://g;
# }
# return $xc->findnodes($path, $node);
#}
# Returns the first Node which matches a given XPath against a given
# node. Works like findnodes_n.
#sub findfirst_n($$)
#{
# my ($path, $node) = @_;
# return findnodes_n($path, $node)->pop();
#}
# #
# Might have to delete this from the DB. # Might have to delete this from the DB.
# #
...@@ -413,11 +428,10 @@ sub Sign($$) ...@@ -413,11 +428,10 @@ sub Sign($$)
} }
$cap_xml .= "</privileges>\n"; $cap_xml .= "</privileges>\n";
if (defined($self->extensions())) { if ($self->extensions()->size() > 0) {
$cap_xml .= "<extensions>\n"; $cap_xml .= "<extensions>\n";
foreach my $key (keys(%{ $self->extensions() })) { foreach my $node ($self->extensions()->get_nodelist()) {
my $value = $self->extensions()->{$key}; $cap_xml .= $node->toString();
$cap_xml .= "<$key>$value</$key>\n";
} }
$cap_xml .= "</extensions>\n"; $cap_xml .= "</extensions>\n";
} }
......
...@@ -31,6 +31,7 @@ use GeniSlice; ...@@ -31,6 +31,7 @@ use GeniSlice;
use GeniSliver; use GeniSliver;
use GeniUser; use GeniUser;
use GeniHRN; use GeniHRN;
use GeniXML;
use libtestbed; use libtestbed;
use User; use User;
use Node; use Node;
...@@ -305,20 +306,26 @@ sub CreatePhysNode($) ...@@ -305,20 +306,26 @@ sub CreatePhysNode($)
} }
} }
elsif (exists($blob->{'rspec'})) { elsif (exists($blob->{'rspec'})) {
my $rspec = XMLin($blob->{'rspec'}, KeyAttr => [], my $rspec = GeniXML::Parse($blob->{'rspec'});
ForceArray => ["interface"]); if (!defined($rspec)) {
goto bad;
foreach my $noderef (@{ $rspec->{'node'} }) { }
foreach my $noderef (GeniXML::FindNodes("./n:node",
$rspec)->get_nodelist()) {
next next
if ($noderef->{'component_uuid'} ne $node_urn); if (GeniXML::GetNodeId($noderef) ne $node_urn);
next next
if (! exists($noderef->{'interface'})); if (! defined(GeniXML::FindFirst("./n:interface", $noderef)));
my $count = 0; my $count = 0;
foreach my $ref (@{ $noderef->{'interface'} }) { foreach my $ref (GeniXML::FindNodes("./n:interface",
my $component_id = $ref->{'component_id'}; $noderef)->get_nodelist()) {
my $role = (exists($ref->{'role'}) ? $ref->{'role'} : "expt"); my $component_id = GeniXML::GetText("./n:component_id", $ref);
my $role = GeniXML::GetText("./n:role", $ref);
if (! defined($role)) {
$role = "expt";
}
my $MAC = "00000000000" . $count; my $MAC = "00000000000" . $count;
my ($auth,$id,$iface) = GeniHRN::ParseInterface($component_id); my ($auth,$id,$iface) = GeniHRN::ParseInterface($component_id);
......
...@@ -26,6 +26,7 @@ use GeniAuthority; ...@@ -26,6 +26,7 @@ use GeniAuthority;
use GeniComponent; use GeniComponent;
use GeniUser; use GeniUser;
use GeniHRN; use GeniHRN;
use GeniXML;
use emutil qw(TBGetUniqueIndex); use emutil qw(TBGetUniqueIndex);
use User; use User;
use Project; use Project;
...@@ -303,9 +304,7 @@ sub Manifest($) ...@@ -303,9 +304,7 @@ sub Manifest($)
return undef; return undef;
} }
my ($manifest_string) = $query_result->fetchrow_array(); my ($manifest_string) = $query_result->fetchrow_array();
my $manifest = XMLin($manifest_string, KeyAttr => [], my $manifest = GeniXML::Parse($manifest_string);
ForceArray => ["node", "link", "interface",
"interface_ref", "linkendpoints"]);
$self->{'MANIFEST'} = $manifest; $self->{'MANIFEST'} = $manifest;
$self->{'MANIFESTSTR'} = $manifest_string; $self->{'MANIFESTSTR'} = $manifest_string;
...@@ -321,13 +320,8 @@ sub UpdateManifest($$) ...@@ -321,13 +320,8 @@ sub UpdateManifest($$)
return -1; return -1;
} }
my $manifest_idx = $self->manifest_idx(); my $manifest_idx = $self->manifest_idx();
my $manifest_string = my $manifest_string = $manifest->toString();
eval { XMLout($manifest, "NoAttr" => 1, RootName => "manifest") };
if ($@) {
print STDERR "UpdateManifest: XMLout error: $@\n";
print STDERR Dumper($manifest);
return -1;
}
my $query_result = my $query_result =
DBQueryWarn("update geni_manifests set ". DBQueryWarn("update geni_manifests set ".
" manifest=". DBQuoteSpecial($manifest_string) . ", " . " manifest=". DBQuoteSpecial($manifest_string) . ", " .
...@@ -362,13 +356,14 @@ sub GetTicket($$$$) ...@@ -362,13 +356,14 @@ sub GetTicket($$$$)
# #
# Lets give it a reasonable default time. # Lets give it a reasonable default time.
# #
if (!exists($rspec->{'valid_until'})) { my $valid_until = GeniXML::FindFirst("./n:valid_until", $rspec);
$rspec->{'valid_until'} = if (! defined($valid_until)) {
POSIX::strftime("20%y-%m-%dT%H:%M:%S", gmtime(time() + (3600*6))); GeniXML::SetText("valid_until",
POSIX::strftime("20%y-%m-%dT%H:%M:%S",
gmtime(time() + (3600*6))));
} }
my $rspec_string = XMLout($rspec, "NoAttr" => 1); my $rspec_string = $rspec_nodes->toString();
$rspec_string =~ s/opt\>/rspec\>/g;
# #
# Load the SA cert to act as caller context. # Load the SA cert to act as caller context.
......
...@@ -22,6 +22,7 @@ use GeniCertificate; ...@@ -22,6 +22,7 @@ use GeniCertificate;
use GeniAggregate; use GeniAggregate;
use GeniUsage; use GeniUsage;
use GeniHRN; use GeniHRN;
use GeniXML;
use emutil; use emutil;
use Experiment; use Experiment;
use OSinfo; use OSinfo;
...@@ -105,12 +106,8 @@ sub Lookup($$) ...@@ -105,12 +106,8 @@ sub Lookup($$)
my $rspec_string = $self->{'SLIVER'}->{'rspec_string'}; my $rspec_string = $self->{'SLIVER'}->{'rspec_string'};
if (defined($rspec_string) && $rspec_string ne "") { if (defined($rspec_string) && $rspec_string ne "") {
my $rspec = my $rspec = GeniXML::Parse($rspec_string);
eval { XMLin($rspec_string, KeyAttr => [], if (!defined($rspec)) {
ForceArray => ["node", "link", "interface",
"interface_ref", "linkendpoints"]) };
if ($@) {
print STDERR "XMLin error reading rspec: $@\n";
return undef; return undef;
} }
$self->{'RSPEC'} = $rspec; $self->{'RSPEC'} = $rspec;
...@@ -200,7 +197,7 @@ sub Create($$$$$$$$$) ...@@ -200,7 +197,7 @@ sub Create($$$$$$$$$)
push(@insert_data, "slice_uuid='$slice_uuid'"); push(@insert_data, "slice_uuid='$slice_uuid'");
if (defined($rspec)) { if (defined($rspec)) {
my $rspec_string = XMLout($rspec, RootName => "rspec"); my $rspec_string = $rspec->toString();
my $safe_rspec = DBQuoteSpecial($rspec_string); my $safe_rspec = DBQuoteSpecial($rspec_string);
push(@insert_data, "rspec_string=$safe_rspec"); push(@insert_data, "rspec_string=$safe_rspec");
...@@ -304,12 +301,7 @@ sub GetManifest($$) ...@@ -304,12 +301,7 @@ sub GetManifest($$)
return $manifest return $manifest
if (!$asxml); if (!$asxml);
my $xml = my $xml = $self->rspec()->toString();
eval { XMLout($manifest, "NoAttr" => 1, RootName => "manifest") };
if ($@) {
print STDERR "XMLout error on manifest: $@\n";
return undef;
}
return $xml; return $xml;
} }
...@@ -594,8 +586,14 @@ sub component_urn($) ...@@ -594,8 +586,14 @@ sub component_urn($)
sub Create($$$$$$) sub Create($$$$$$)
{ {
# $rspec is a LibXML element representing a single node.
my ($class, $slice, $user, $resource_uuid, $rspec) = @_; my ($class, $slice, $user, $resource_uuid, $rspec) = @_;
my $virtualization_type = $rspec->{'virtualization_type'}; my $virt_xml = GeniXML::FindFirst("./n:virtualization_type", $rspec);
if (!defined($virt_xml)) {
print STDERR "Node does not contain a virtualization_type\n";
return undef;
}
my $virtualization_type = $virt_xml->textContent();
my $experiment = $slice->GetExperiment(); my $experiment = $slice->GetExperiment();
if (!defined($experiment)) { if (!defined($experiment)) {
...@@ -631,7 +629,12 @@ sub Create($$$$$$) ...@@ -631,7 +629,12 @@ sub Create($$$$$$)
return undef; return undef;
} }
} }
my $nickname = $rspec->{'virtual_id'}; my $virtual_id_xml = GeniXML::FindFirst("./n:virtual_id", $rspec);
if (!defined($virtual_id_xml)) {