Merge branch 'master' of ssh://git.onelab.eu/git/sfa
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 25 Oct 2011 14:41:40 +0000 (16:41 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 25 Oct 2011 14:41:40 +0000 (16:41 +0200)
sfa/managers/aggregate_manager.py
sfa/managers/aggregate_manager_vini.py
sfa/managers/slice_manager.py
sfa/plc/slices.py
sfa/rspecs/elements/versions/pgv2Link.py
sfa/rspecs/rspec_elements.py
sfa/rspecs/versions/sfav1.py
sfa/util/specdict.py [deleted file]

index 84dc0dd..7646dd3 100644 (file)
@@ -8,7 +8,6 @@ from types import StringTypes
 from sfa.util.faults import *
 from sfa.util.xrn import get_authority, hrn_to_urn, urn_to_hrn, Xrn, urn_to_sliver_id
 from sfa.util.plxrn import slicename_to_hrn, hrn_to_pl_slicename, hostname_to_urn
-from sfa.util.specdict import *
 from sfa.util.record import SfaRecord
 from sfa.util.policy import Policy
 from sfa.util.record import *
index bcb2729..88c4438 100644 (file)
@@ -6,7 +6,6 @@ import sys
 from types import StringTypes
 from sfa.util.xrn import urn_to_hrn, Xrn
 from sfa.util.plxrn import hrn_to_pl_slicename
-from sfa.util.specdict import *
 from sfa.util.faults import *
 from sfa.util.record import SfaRecord
 from sfa.util.policy import Policy
index 18cc6aa..d3ce06b 100644 (file)
@@ -1,4 +1,4 @@
-#
+/
 import sys
 import time,datetime
 from StringIO import StringIO
@@ -11,7 +11,6 @@ from sfa.util.sfalogging import logger
 from sfa.util.rspecHelper import merge_rspecs
 from sfa.util.xrn import Xrn, urn_to_hrn, hrn_to_urn
 from sfa.util.plxrn import hrn_to_pl_slicename
-from sfa.util.specdict import *
 from sfa.util.faults import *
 from sfa.util.record import SfaRecord
 from sfa.rspecs.rspec_converter import RSpecConverter
index 557fc37..0b26902 100644 (file)
@@ -6,7 +6,6 @@ import sys
 from types import StringTypes
 from sfa.util.xrn import Xrn, get_leaf, get_authority, hrn_to_urn, urn_to_hrn
 from sfa.util.plxrn import hrn_to_pl_slicename, hrn_to_pl_login_base
-from sfa.util.specdict import *
 from sfa.util.faults import *
 from sfa.util.record import SfaRecord
 from sfa.util.policy import Policy
index 1f19a7a..7d315b2 100644 (file)
@@ -7,7 +7,10 @@ class PGv2Link:
 
     elements = {
         'link': RSpecElement(RSpecElements.LINK, '//default:link | //link'),
-        'component_manager': RSpecElement(RSpecElements.COMPONENT_MANAGER, './default:component_manager | ./component_manager')
+        'component_manager': RSpecElement(RSpecElements.COMPONENT_MANAGER, './default:component_manager | ./component_manager'),
+        'link_type': RSpecElement(RSpecElements.LINK_TYPE, './default:link_type | ./link_type'),
+        'property': RSpecElement(RSpecElements.PROPERTY, './default:property | ./property'),
+        'interface_ref': RSpecElement(RSpecElements.INTERFACE_REF, './default:interface_ref | ./interface_ref') 
     }
     
     @staticmethod
@@ -18,25 +21,25 @@ class PGv2Link:
                 if attrib in link and link[attrib]:
                     link_elem.set(attrib, link[attrib])
             if 'component_manager' in link and link['component_manager']:
-                cm_element = etree.SubElement(xml, 'component_manager', name=link['component_manager'])
+                cm_element = etree.SubElement(link_elem, 'component_manager', name=link['component_manager'])
             for if_ref in [link['interface1'], link['interface2']]:
-                if_ref_elem = etree.SubElement(xml, 'interface_ref')
+                if_ref_elem = etree.SubElement(link_elem, 'interface_ref')
                 for attrib in Interface.fields:
                     if attrib in if_ref and if_ref[attrib]:
                         if_ref_elem.attrib[attrib] = if_ref[attrib]  
-            prop1 = etree.SubElement(xml, 'property', source_id = link['interface1']['component_id'],
+            prop1 = etree.SubElement(link_elem, 'property', source_id = link['interface1']['component_id'],
                 dest_id = link['interface2']['component_id'], capacity=link['capacity'], 
                 latency=link['latency'], packet_loss=link['packet_loss'])
-            prop2 = etree.SubElement(xml, 'property', source_id = link['interface2']['component_id'],
+            prop2 = etree.SubElement(link_elem, 'property', source_id = link['interface2']['component_id'],
                 dest_id = link['interface1']['component_id'], capacity=link['capacity'], 
                 latency=link['latency'], packet_loss=link['packet_loss'])
             if 'type' in link and link['type']:
-                type_elem = etree.SubElement(xml, 'link_type', name=link['type'])             
+                type_elem = etree.SubElement(link_elem, 'link_type', name=link['type'])             
    
     @staticmethod 
     def get_links(xml, namespaces=None):
         links = []
-        link_elems = xml.xpath('//default:link', namespaces=namespaces)
+        link_elems = xml.xpath(PGv2Link.elements['link'].path, namespaces=namespaces)
         for link_elem in link_elems:
             # set client_id, component_id, component_name
             link = Link(link_elem.attrib)
@@ -47,14 +50,14 @@ class PGv2Link:
                 if  'name' in cm.attrib:
                     link['component_manager'] = cm.attrib['name'] 
             # set link type
-            link_types = link_elem.xpath('./default:link_type', namespaces=namespaces)
+            link_types = link_elem.xpath(PGv2Link.elements['link_type'].path, namespaces=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('./default:property', namespaces=namespaces)
+            props = link_elem.xpath(PGv2Link.elements['property'].path, namespaces=namespaces)
             if len(props) > 0:
                 prop = props[0]
                 for attrib in ['capacity', 'latency', 'packet_loss']:
@@ -62,7 +65,7 @@ class PGv2Link:
                         link[attrib] = prop.attrib[attrib]
                              
             # get interfaces 
-            if_elems = link_elem.xpath('./default:interface_ref', namespaces=namespaces)
+            if_elems = link_elem.xpath(PGv2Link.elements['interface_ref'].path, namespaces=namespaces)
             ifs = []
             for if_elem in if_elems:
                 if_ref = Interface(if_elem.attrib)                 
index 4209139..3226f58 100644 (file)
@@ -4,10 +4,14 @@ from sfa.util.enumeration import Enum
 RSpecElements = Enum(NETWORK='NETWORK', 
                      COMPONENT_MANAGER='COMPONENT_MANAGER', 
                      SLIVER='SLIVER', 
+                     SLIVER_TYPE='SLIVER_TYPE', 
                      NODE='NODE', 
                      INTERFACE='INTERFACE', 
+                     INTERFACE_REF='INTERFACE_REF', 
                      LINK='LINK', 
-                     SERVICE='SERVICE'
+                     LINK_TYPE='LINK_TYPE', 
+                     SERVICE='SERVICE',
+                     PROPERTY='PROPERTY'
                 )
 
 class RSpecElement:
index 06f277a..f1225f5 100644 (file)
@@ -242,7 +242,7 @@ class SFAv1(BaseVersion):
         pass
 
     def add_links(self, links):
-        PGv2Link.add_links(self.xml, links)
+        PGv2Link.add_links(self.xml.root, links)
 
     def add_slivers(self, slivers, network=None, sliver_urn=None, no_dupes=False, append=False):
         # add slice name to network tag
diff --git a/sfa/util/specdict.py b/sfa/util/specdict.py
deleted file mode 100644 (file)
index 2138e87..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-##
-# SpecDict
-#
-# SpecDict defines a means for converting a dictionary with plc specific keys
-# to a dict with rspec specific keys. 
-#
-# SpecDict.fields dict defines all the rspec specific attribute and their 
-# expected type. 
-# 
-# SpecDict.plc_fields defines a one to one mapping of plc attribute to rspec 
-# attribute
-
-from types import StringTypes, ListType
-
-class SpecDict(dict):
-    """
-    Base class of SpecDict objects. 
-    """
-    fields = {}
-    plc_fields = {}
-    type = None
-        
-    def __init__(self, spec_dict):
-        # convert plc dict and initialize self
-        sdict = self.plcToSpec(spec_dict)
-        dict.__init__(self, sdict)
-
-
-    def plcToSpec(self, spec_dict):
-        """
-        Defines how to convert a plc dict to rspec dict
-        """
-        spec = {}
-        for field in self.fields:
-            value = ""
-            expected = self.fields[field]
-            if isinstance(expected, StringTypes):
-                if self.plc_fields.has_key(field):
-                    plc_field = self.plc_fields[field]
-                    if spec_dict.has_key(plc_field):
-                        value = spec_dict[plc_field]
-            elif isinstance(expected, ListType):
-                expected = expected[0]
-                if self.plc_fields.has_key(field):
-                    plc_field = self.plc_fields[field]
-                    if spec_dict.has_key(plc_field):
-                        value = [expected(value) for value in spec_dict[plc_field]]
-            spec[field] = value
-        return {self.type: spec}
-
-#
-# fields = { geni_field:  type.  Could be class for nested classes, otherwise prob str}
-# plc_fields = {geni_field : plc_field}
-#
-class IfSpecDict(SpecDict):
-    type = 'IfSpec'
-    fields = {'name': '',
-              'addr': '',
-              'type': '',
-              'init_params': '',
-              'min_rate': '',
-              'max_rate': '',
-              'max_kbyte': '',
-              'ip_spoof': ''}
-    plc_fields = {'name': 'is_primary', # XXX needs munging to return name instead of True or False
-                 'addr': 'ip',
-                 'type': 'type'}
-class LinkSpecDict(SpecDict):
-    type = 'LinkSpec'
-    fields = {'min_alloc': '', 
-              'max_alloc': '', 
-              'type': '', 
-              'start_time': '', 
-              'bw': '', 
-              'duration': '', 
-              'init_params': '',
-              'endpoints': [IfSpecDict]}
-    plc_fields = {'min_alloc': 'min_alloc',
-              'max_alloc': 'max_alloc', 
-              'type': 'type', 
-              'start_time': 'start_time', 
-              'bw': 'bw', 
-              'duration': 'duration', 
-              'init_params': 'init_params',
-              'endpoints': 'endpoints'}
-  
-            
-class NodeSpecDict(SpecDict):
-    type = 'NodeSpec'
-    fields = {'name': '',
-              'type': '',
-              'init_params': '',
-              'cpu_min': '',
-              'cpu_share': '',
-              'cpu_pct': '',
-              'disk_max': '',
-              'start_time': '',
-              'duration': '',
-              'net_if': [IfSpecDict]}
-
-    plc_fields = {'name': 'hostname',
-                  'net_if': 'interfaces'}  
-
-class NetSpecDict(SpecDict):
-    type = 'NetSpec'
-    fields = {'name': '',
-              'start_time': '',
-              'duration': '',
-              'nodes': [NodeSpecDict],
-              'links': [LinkSpecDict],
-             }
-    plc_fields = {'name': 'name',
-                  'start_time': 'start_time',
-                  'duration': 'duration',
-                  'nodes': 'nodes',
-                  'links': 'links'}
-
-class RSpecDict(SpecDict):
-    type = 'RSpec'
-    fields = {'start_time': '',
-              'duration': '',
-              'networks': [NetSpecDict]
-             }
-    plc_fields = {'networks': 'networks',
-                  'start_time': 'start_tim',
-                  'duration': 'duration'
-                 }
-
-# vim:ts=4:expandtab