Commit 7d2bf5bf authored by Jonathon Duerig's avatar Jonathon Duerig

Added GetNodeByVirtualId, GetLinkByVirtualId, and ReplaceNode as utility...

Added GetNodeByVirtualId, GetLinkByVirtualId, and ReplaceNode as utility functions for managing rspecs.
parent 82adef9c
......@@ -12,7 +12,8 @@ use vars qw(@ISA @EXPORT);
@ISA = "Exporter";
@EXPORT = qw(Parse ParseFile IsVersion0 FindNodes FindNodesNS
FindFirst FindElement FindAttr IsLanNode IsLocalNode IsTunnel GetExpires
FindFirst FindElement FindAttr GetNodeByVirtualId GetLinkByVirtualId
IsLanNode IsLocalNode IsTunnel GetExpires
GetNodeId GetVirtualId GetInterfaceId GetInterfaceNodeId GetSliverId
GetManagerId GetColocate GetSubnodeOf
GetVirtualizationType SetVirtualizationType GetVirtualizationSubtype
......@@ -189,6 +190,35 @@ sub FindAttr($$)
return FindNodeType($path, $node, XML_ATTRIBUTE_NODE);
}
sub GetElementByVirtualId($$$)
{
my ($name, $type, $node) = @_;
my @list = FindNodes('n:'.$type.'[@virtual_id = "'.$name.'"]',
$node)->get_nodelist();
my $result = undef;
if (scalar(@list) > 0)
{
$result = $list[0];
}
if (scalar(@list) > 1)
{
cluck("WARNING: Multiple $type with virtual_id $name found");
}
return $result;
}
sub GetNodeByVirtualId($$)
{
my ($name, $node) = @_;
return GetElementByVirtualId($name, 'node', $node);
}
sub GetLinkByVirtualId($$)
{
my ($name, $node) = @_;
return GetElementByVirtualId($name, 'link', $node);
}
# Returns true if a given XML Node is an RSpec node and is of type lan
sub IsLanNode($)
{
......@@ -526,6 +556,14 @@ sub RemoveChild($$)
}
}
# Replaces a node (oldnode) with a copy of another node (newnode)
sub ReplaceNode($$)
{
my ($oldnode, $newnode) = @_;
my $copy = $newnode->cloneNode(1);
$oldnode->replaceNode($copy);
}
# checks for the existense of policy in extensions of the given
# credential.
sub PolicyExists($$)
......
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