Slice manager converts PG advertisement RSpec to SFA RSpec
[sfa.git] / sfa / rspecs / pg_rspec_converter.py
index bc63781..aa68546 100755 (executable)
@@ -1,7 +1,5 @@
 #!/usr/bin/python 
-from __future__ import with_statement
 from lxml import etree
-from xmlbuilder import XMLBuilder
 from StringIO import StringIO
 from sfa.util.xrn import *
 from sfa.rspecs.pg_rspec import PGRSpec 
@@ -36,16 +34,12 @@ class PGRSpecConverter:
 
     @staticmethod
     def to_sfa_node(site, node, i=0):
-        cm_urn = node.get('component_manager_uuid')
-        c_name = node.get('component_name')
-        c_urn = node.get('component_uuid')
-        c_hrn, _ = urn_to_hrn(c_urn)
+        urn = node.get('component_uuid')
+        hrn, _ = urn_to_hrn(urn)
+        hostname = Xrn.urn_split(urn)[-1]
         node_tag = etree.SubElement(site, "node")
-        node_tag.set("component_manager_uuid", cm_urn)
-        node_tag.set("component_name", c_name)
-        node_tag.set("component_uuid", c_urn)
-        hostname_tag = etree.SubElement(node_tag, "hostname").text = c_hrn
-        urn_tag = etree.SubElement(node_tag, "urn").text = c_hrn
+        hostname_tag = etree.SubElement(node_tag, "hostname").text = hostname
+        urn_tag = etree.SubElement(node_tag, "urn").text = urn
         for child in node.getchildren():
             node_tag.append(transform(child).getroot())      
 
@@ -53,20 +47,17 @@ class PGRSpecConverter:
     def to_sfa_network(pg_rspec, xml): 
         network_urn = pg_rspec.get_network()
         network,  _ = urn_to_hrn(network_urn)
-        nodes = pg_rspec.get_nodes()
+        nodes = pg_rspec.get_node_elements()
         network_tag = etree.SubElement(xml, "network")
         network_tag.set("name", network)
         network_tag.set("id", network)
-        site_tag = etree.SubElement(network_tag, "Site")
-        site_tag.set("id", network)
-        name = etree.SubElement(site_tag, "name").text = network
         i = 0
         for node in nodes:
-           PGRSpecConverter.to_sfa_node(site_tag, node, i)
+           PGRSpecConverter.to_sfa_node(network_tag, node, i)
         
     @staticmethod
     def to_sfa_rspec(rspec):
-        pg_rspec = PGRSpec(rspec)
+        pg_rspec = PGRSpec(rspec=rspec)
         header = '<?xml version="1.0"?>\n'
         xml = etree.Element("RSpec", type="SFA") 
         PGRSpecConverter.to_sfa_network(pg_rspec, xml)