From 258cdab7de0721e0c1da5b23ae9780d18ec1e134 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Wed, 6 Jul 2011 16:31:14 -0400 Subject: [PATCH] implement get_slice_attributes --- sfa/rspecs/pg_rspec.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/sfa/rspecs/pg_rspec.py b/sfa/rspecs/pg_rspec.py index 6ee30dbd..2d48e193 100755 --- a/sfa/rspecs/pg_rspec.py +++ b/sfa/rspecs/pg_rspec.py @@ -74,7 +74,14 @@ class PGRSpec(RSpec): networks = self.xml.xpath('//rspecv2:node[@component_manager_uuid]/@component_manager_uuid', namespaces=self.namespaces) return set(networks) - def get_node_elements(self): + def get_node_element(self, hostname, network=None): + nodes = self.xml.xpath('//rspecv2:node[@component_id[contains(., "%s")]]' % hostname, namespaces=self.namespaces) + if isinstance(nodes,list) and nodes: + return nodes[0] + else: + return None + + def get_node_elements(self, network=None): nodes = self.xml.xpath('//rspecv2:node | //node', namespaces=self.namespaces) return nodes @@ -94,15 +101,37 @@ class PGRSpec(RSpec): def get_nodes_without_slivers(self, network=None): return [] + + def get_sliver_attributes(self, hostname, network=None): + node = self.get_node_element(hostname, network) + sliver = node.xpath('//rspecv2:sliver_type', namespaces=self.namespaces) + if sliver is not None and isinstance(sliver, list): + sliver = sliver[0] + return self.attributes_list(sliver) def get_slice_attributes(self, network=None): - return [] + slice_attributes = [] + nodes_with_slivers = self.get_nodes_with_slivers(network) + + # TODO: default sliver attributes in the PG rspec? + + for node in nodes_with_slivers: + sliver_attributes = self.get_sliver_attributes(node, network) + for sliver_attribute in sliver_attributes: + name=str(sliver_attribute[0]) + value=str(sliver_attribute[1]) + # we currently only suppor the and attributes + if name in ['initscript', 'info']: + attribute = {'name': name, 'value': value, 'node_id': node, 'attributes': sliver_attribute[2]} + slice_attributes.append(attribute) + + return slice_attributes def attributes_list(self, elem): opts = [] if elem is not None: for e in elem: - opts.append((e.tag, e.text)) + opts.append((e.tag, e.text, e.attrib)) return opts def get_default_sliver_attributes(self, network=None): -- 2.43.0