Merge branch 'master' of ssh://git.onelab.eu/git/sfa
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 25 Oct 2011 16:59:50 +0000 (18:59 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 25 Oct 2011 16:59:50 +0000 (18:59 +0200)
sfa/client/sfi_commands.py
sfa/rspecs/elements/link.py
sfa/rspecs/elements/versions/pgv2Link.py
sfa/rspecs/versions/pgv2.py
sfa/rspecs/versions/sfav1.py
sfa/util/xml.py

index bdcc16d..80897cd 100755 (executable)
@@ -12,6 +12,7 @@ class Commands:
         self.parser.add_option("-o", "", dest="outfile", metavar="FILE",
                                help="write output to FILE (default is stdout)")
         self.nodefile = False
+        self.linkfile = False
         self.attributes = {}
 
     def add_nodefile_option(self):
@@ -20,6 +21,12 @@ class Commands:
                                metavar="FILE",
                                help="read node list from FILE"),
 
+    def add_linkfile_option(self):
+        self.linkfile = True
+        self.parser.add_option("-l", "", dest="linkfile",
+                               metavar="FILE",
+                               help="read link list from FILE") 
+
     def add_show_attributes_option(self):
         self.parser.add_option("-s", "--show-attributes", action="store_true", 
                                dest="showatt", default=False, 
index 4722cf8..f3a857b 100644 (file)
@@ -14,6 +14,7 @@ class Link(dict):
         'latency': None,
         'packet_loss': None,
         'description': None,
+        '_element': None
     }
     
     def __init__(self, fields={}):
index 7d315b2..c1efcce 100644 (file)
@@ -15,8 +15,9 @@ class PGv2Link:
     
     @staticmethod
     def add_links(xml, links):
+        root = xml.root
         for link in links:
-            link_elem = etree.SubElement(xml, 'link')
+            link_elem = etree.SubElement(root, 'link')
             for attrib in ['component_name', 'component_id', 'client_id']:
                 if attrib in link and link[attrib]:
                     link_elem.set(attrib, link[attrib])
@@ -37,27 +38,28 @@ class PGv2Link:
                 type_elem = etree.SubElement(link_elem, 'link_type', name=link['type'])             
    
     @staticmethod 
-    def get_links(xml, namespaces=None):
+    def get_links(xml):
         links = []
-        link_elems = xml.xpath(PGv2Link.elements['link'].path, namespaces=namespaces)
+        link_elems = xml.xpath(PGv2Link.elements['link'].path, namespaces=xml.namespaces)
         for link_elem in link_elems:
             # set client_id, component_id, component_name
             link = Link(link_elem.attrib)
+            link['_element'] = link_elem
             # set component manager
-            cm = link_elem.xpath('./default:component_manager', namespaces=namespaces)
+            cm = link_elem.xpath('./default:component_manager', namespaces=xml.namespaces)
             if len(cm) >  0:
                 cm = cm[0]
                 if  'name' in cm.attrib:
                     link['component_manager'] = cm.attrib['name'] 
             # set link type
-            link_types = link_elem.xpath(PGv2Link.elements['link_type'].path, namespaces=namespaces)
+            link_types = link_elem.xpath(PGv2Link.elements['link_type'].path, namespaces=xml.namespaces)
             if len(link_types) > 0:
                 link_type = link_types[0]
                 if 'name' in link_type.attrib:
                     link['type'] = link_type.attrib['name']
           
             # get capacity, latency and packet_loss from first property  
-            props = link_elem.xpath(PGv2Link.elements['property'].path, namespaces=namespaces)
+            props = link_elem.xpath(PGv2Link.elements['property'].path, namespaces=xml.namespaces)
             if len(props) > 0:
                 prop = props[0]
                 for attrib in ['capacity', 'latency', 'packet_loss']:
@@ -65,7 +67,7 @@ class PGv2Link:
                         link[attrib] = prop.attrib[attrib]
                              
             # get interfaces 
-            if_elems = link_elem.xpath(PGv2Link.elements['interface_ref'].path, namespaces=namespaces)
+            if_elems = link_elem.xpath(PGv2Link.elements['interface_ref'].path, namespaces=xml.namespaces)
             ifs = []
             for if_elem in if_elems:
                 if_ref = Interface(if_elem.attrib)                 
@@ -76,3 +78,7 @@ class PGv2Link:
             links.append(link)
         return links 
 
+
+    def add_link_requests(xml, links_tuple):
+        available_links = PGv2Link.get_links(xml) 
+           
index 3e995ad..a332286 100644 (file)
@@ -93,11 +93,11 @@ class PGv2(BaseVersion):
         return slice_attributes
 
     def get_links(self, network=None):
-        links = PGv2Link.get_links(self.xml.root, self.namespaces)
+        links = PGv2Link.get_links(self.xml)
         return links
 
     def add_links(self, links):
-        PGv2Link.add_links(self.xml.root, links)
+        PGv2Link.add_links(self.xml, links)
 
     def attributes_list(self, elem):
         opts = []
index f1225f5..8ba0efb 100644 (file)
@@ -113,7 +113,7 @@ class SFAv1(BaseVersion):
         return nodes
 
     def get_links(self, network=None):
-        links = PGv2Link.get_links(self.xml, self.namespaces)
+        links = PGv2Link.get_links(self.xml)
         return links
 
     def get_link(self, fromnode, tonode, network=None):
@@ -242,7 +242,7 @@ class SFAv1(BaseVersion):
         pass
 
     def add_links(self, links):
-        PGv2Link.add_links(self.xml.root, links)
+        PGv2Link.add_links(self.xml, links)
 
     def add_slivers(self, slivers, network=None, sliver_urn=None, no_dupes=False, append=False):
         # add slice name to network tag
index 91a1d95..e79fd47 100755 (executable)
@@ -56,6 +56,8 @@ class XML:
         self.root = tree.getroot()
         # set namespaces map
         self.namespaces = dict(self.root.nsmap)
+        if 'default' not in self.namespaces and None in self.namespaces: 
+            self.namespaces['default'] = self.namespaces[None]
         # If the 'None' exist, then it's pointing to the default namespace. This makes 
         # it hard for us to write xpath queries for the default naemspace because lxml 
         # wont understand a None prefix. We will just associate the default namespeace 
@@ -200,7 +202,7 @@ class XML:
         return self.toxml()
 
     def toxml(self):
-        return etree.tostring(self.root, pretty_print=True)  
+        return etree.tostring(self.root, encoding='UTF-8', pretty_print=True)  
     
     def todict(self, elem=None):
         if elem is None: