Merge branch 'master' of ssh://git.onelab.eu/git/sfa
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 6 Dec 2011 08:13:45 +0000 (09:13 +0100)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 6 Dec 2011 08:13:45 +0000 (09:13 +0100)
sfa/client/sfi.py
sfa/rspecs/elements/versions/pgv2SliverType.py
sfa/rspecs/elements/versions/sfav1Sliver.py
sfa/rspecs/versions/sfav1.py
sfa/util/xml.py

index b4aac4f..3b610c7 100755 (executable)
@@ -1000,15 +1000,16 @@ class Sfi:
         slice_urn = hrn_to_urn(slice_hrn, 'slice')
         user_cred = self.get_user_cred()
         slice_cred = self.get_slice_cred(slice_hrn).save_to_string(save_parents=True)
-
-        if hasattr(opts, 'aggregate') and opts.aggregate:
-            delegated_cred = None
-        else:
-            # delegate the cred to the callers root authority
-            delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority)+'.slicemanager')
-            #delegated_cred = self.delegate_cred(slice_cred, get_authority(slice_hrn))
-            #creds.append(delegated_cred)
-
+        delegated_cred = None
+        if server_version.get('interface') == 'slicemgr':
+            # delegate our cred to the slice manager
+            # do not delegate cred to slicemgr...not working at the moment
+            pass
+            #if server_version.get('hrn'):
+            #    delegated_cred = self.delegate_cred(slice_cred, server_version['hrn'])
+            #elif server_version.get('urn'):
+            #    delegated_cred = self.delegate_cred(slice_cred, urn_to_hrn(server_version['urn']))
+                 
         rspec_file = self.get_rspec_file(args[1])
         rspec = open(rspec_file).read()
 
index 7bbe31b..94a9f63 100644 (file)
@@ -36,6 +36,8 @@ class PGv2SliverType:
             sliver = Sliver(sliver_elem.attrib,sliver_elem)
             if 'component_id' in xml.attrib:     
                 sliver['component_id'] = xml.attrib['component_id']
+            if 'name' in sliver_elem.attrib:
+                sliver['type'] = sliver_elem.attrib['name']
             slivers.append(sliver)
         return slivers
 
index 8a113f3..f037533 100644 (file)
@@ -34,7 +34,7 @@ class SFAv1Sliver:
         for elem in xml.iterchildren():
             if elem.tag not in Sliver.fields:
                 xml_element = XmlElement(elem, xml.namespaces)
-                instance = Element(xml_element)
+                instance = Element(fields=xml_element, element=elem)
                 instance['name'] = elem.tag
                 instance['value'] = elem.text
                 attribs.append(instance)
index affab84..8f172bd 100644 (file)
@@ -104,17 +104,20 @@ class SFAv1(BaseVersion):
         return attributes
 
 
-    def add_sliver_attribute(self, hostname, name, value, network=None):
-        nodes = self.get_nodes({'component_id': '*%s*' % hostname})
-        if not nodes:
+    def add_sliver_attribute(self, component_id, name, value, network=None):
+        nodes = self.get_nodes({'component_id': '*%s*' % component_id})
+        if nodes is not None and isinstance(nodes, list) and len(nodes) > 0:
             node = nodes[0]
             slivers = SFAv1Sliver.get_slivers(node)
             if slivers:
                 sliver = slivers[0]
-                SFAv1Sliver.add_attribute(sliver, name, value)
+                SFAv1Sliver.add_sliver_attribute(sliver, name, value)
+        else:
+            # should this be an assert / raise an exception?
+            print "WARNING: failed to find component_id", component_id
 
-    def get_sliver_attributes(self, hostname, network=None):
-        nodes = self.get_nodes({'component_id': '*%s*' %hostname})
+    def get_sliver_attributes(self, component_id, network=None):
+        nodes = self.get_nodes({'component_id': '*%s*' % component_id})
         attribs = []
         if nodes is not None and isinstance(nodes, list) and len(nodes) > 0:
             node = nodes[0]
@@ -124,11 +127,13 @@ class SFAv1(BaseVersion):
                 attribs = SFAv1Sliver.get_sliver_attributes(sliver.element)
         return attribs
 
-    def remove_sliver_attribute(self, hostname, name, value, network=None):
-        attribs = self.get_sliver_attributes(hostname)
+    def remove_sliver_attribute(self, component_id, name, value, network=None):
+        attribs = self.get_sliver_attributes(component_id)
         for attrib in attribs:
             if attrib['name'] == name and attrib['value'] == value:
-                attrib.element.delete()
+                #attrib.element.delete()
+                parent = attrib.element.getparent()
+                parent.remove(attrib.element)
 
     def add_default_sliver_attribute(self, name, value, network=None):
         if network:
@@ -153,14 +158,12 @@ class SFAv1(BaseVersion):
         return SFAv1Sliver.get_sliver_attributes(defaults[0])
     
     def remove_default_sliver_attribute(self, name, value, network=None):
-        if network:
-            defaults = self.xml.xpath("//network[@name='%s']/sliver_defaults" % network)
-        else:
-            defaults = self.xml.xpath("//sliver_defaults" % network)
-        attribs = SFAv1Sliver.get_sliver_attributes(defaults)
+        attribs = self.get_default_sliver_attributes(network)
         for attrib in attribs:
             if attrib['name'] == name and attrib['value'] == value:
-                attrib.element.delete()    
+                #attrib.element.delete()
+                parent = attrib.element.getparent()
+                parent.remove(attrib.element)
 
     # Links
 
index 1a7f2f3..90693f2 100755 (executable)
@@ -195,7 +195,7 @@ class XML:
             self.namespaces['default'] = 'default' 
 
         self.root = XmlElement(root, self.namespaces)
-        # set schema 
+        # set schema
         for key in self.root.attrib.keys():
             if key.endswith('schemaLocation'):
                 # schema location should be at the end of the list
@@ -208,7 +208,7 @@ class XML:
         if element is None: 
             if self.root is None:
                 self.parse_xml('<%s/>' % root_tag_name)
-            element = self.root
+            element = self.root.element
 
         if 'text' in d:
             text = d.pop('text')
@@ -224,9 +224,9 @@ class XML:
                         self.parse_dict(val, key, child_element)
                     elif isinstance(val, basestring):
                         child_element = etree.SubElement(element, key).text = val
-                        
+
             elif isinstance(value, int):
-                d[key] = unicode(d[key])  
+                d[key] = unicode(d[key])
             elif value is None:
                 d.pop(key)