imports from geni itself should now be fully qualified
[sfa.git] / geni / util / specdict.py
index 4b225db..5960887 100644 (file)
 # SpecDict.plc_fields defines a one to one mapping of plc attribute to rspec 
 # attribute
 
-from types import StringTypes, ListType
+### $Id$
+### $URL$
 
+from types import StringTypes, ListType
 
 class SpecDict(dict):
     """
@@ -38,7 +40,6 @@ class SpecDict(dict):
             if isinstance(expected, StringTypes):
                 if self.plc_fields.has_key(field):
                     plc_field = self.plc_fields[field]
-                    print self.type, spec_dict
                     if spec_dict.has_key(plc_field):
                         value = spec_dict[plc_field]
             elif isinstance(expected, ListType):
@@ -47,11 +48,14 @@ class SpecDict(dict):
                     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': '',
@@ -62,9 +66,29 @@ class IfSpecDict(SpecDict):
               'max_rate': '',
               'max_kbyte': '',
               'ip_spoof': ''}
-    plc_fields = {'name': 'is_primary',
+    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'
@@ -88,11 +112,13 @@ class NetSpecDict(SpecDict):
               'start_time': '',
               'duration': '',
               'nodes': [NodeSpecDict],
+              'links': [LinkSpecDict],
              }
     plc_fields = {'name': 'name',
                   'start_time': 'start_time',
                   'duration': 'duration',
-                  'nodes': 'nodes'}
+                  'nodes': 'nodes',
+                  'links': 'links'}
 
 class RspecDict(SpecDict):
     type = 'RSpec'
@@ -100,6 +126,9 @@ class RspecDict(SpecDict):
               'duration': '',
               'networks': [NetSpecDict]
              }
-    plc_fields = {'networks': 'networks'}
+    plc_fields = {'networks': 'networks',
+                  'start_time': 'start_tim',
+                  'duration': 'duration'
+                 }
 
 # vim:ts=4:expandtab