defaultdict in sfa.util + minor/cosmetic
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 1 Nov 2011 13:50:50 +0000 (14:50 +0100)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 1 Nov 2011 13:50:50 +0000 (14:50 +0100)
sfa/managers/aggregate_manager.py
sfa/plc/aggregate.py
sfa/plc/plccomponentapi.py
sfa/plc/plcsfaapi.py
sfa/server/sfaapi.py
sfa/util/config.py
sfa/util/defaultdict.py [new file with mode: 0644]

index 827b2d9..702fe7d 100644 (file)
@@ -192,7 +192,7 @@ def CreateSliver(api, slice_xrn, creds, rspec_string, users, call_id):
     aggregate.prepare_interfaces({'node_id': aggregate.nodes.keys()})    
     slices.verify_slice_links(slice, rspec.version.get_link_requests(), aggregate)
 
-    # hanlde MyPLC peer association.
+    # handle MyPLC peer association.
     # only used by plc and ple.
     slices.handle_peer(site, slice, persons, peer)
     
index f210705..4cbeff7 100644 (file)
@@ -1,9 +1,11 @@
 #!/usr/bin/python
 from sfa.util.xrn import hrn_to_urn, urn_to_hrn
 from sfa.util.plxrn import PlXrn, hostname_to_urn, hrn_to_pl_slicename
+
 from sfa.rspecs.rspec import RSpec
 from sfa.rspecs.elements.link import Link
 from sfa.rspecs.elements.interface import Interface
+
 from sfa.managers.vini.topology import PhysicalLinks
 from sfa.rspecs.version_manager import VersionManager
 from sfa.plc.vlink import get_tc_rate
index e09dbee..d326482 100644 (file)
@@ -12,6 +12,13 @@ from sfa.server.sfaapi import SfaApi
 
 ####################
 class PlcComponentApi(SfaApi):
+    """
+    This class is the type for the toplevel 'api' object 
+    when running the component manager inside a planetlab node.
+    As such it runs an SFA-compliant interface and thus inherits SfaApi
+    However the fact that we run inside a planetlab nodes requires 
+    some tweaks as compared with a service running in the infrastructure.
+    """
 
     def __init__ (self, encoding="utf-8", methods='sfa.methods', 
                   config = "/etc/sfa/sfa_config.py", 
index 357a210..842df31 100644 (file)
@@ -3,52 +3,13 @@ import xmlrpclib
 from sfa.util.faults import MissingSfaInfo
 from sfa.util.sfalogging import logger
 from sfa.util.table import SfaTable
+from sfa.util.defaultdict import defaultdict
 
 from sfa.util.xrn import hrn_to_urn
 from sfa.util.plxrn import slicename_to_hrn, hostname_to_hrn, hrn_to_pl_slicename, hrn_to_pl_login_base
 
 from sfa.server.sfaapi import SfaApi
 
-#################### xxx should move into util/defaultdict
-try:
-    from collections import defaultdict
-except:
-    class defaultdict(dict):
-        def __init__(self, default_factory=None, *a, **kw):
-            if (default_factory is not None and
-                not hasattr(default_factory, '__call__')):
-                raise TypeError('first argument must be callable')
-            dict.__init__(self, *a, **kw)
-            self.default_factory = default_factory
-        def __getitem__(self, key):
-            try:
-                return dict.__getitem__(self, key)
-            except KeyError:
-                return self.__missing__(key)
-        def __missing__(self, key):
-            if self.default_factory is None:
-                raise KeyError(key)
-            self[key] = value = self.default_factory()
-            return value
-        def __reduce__(self):
-            if self.default_factory is None:
-                args = tuple()
-            else:
-                args = self.default_factory,
-            return type(self), args, None, None, self.items()
-        def copy(self):
-            return self.__copy__()
-        def __copy__(self):
-            return type(self)(self.default_factory, self)
-        def __deepcopy__(self, memo):
-            import copy
-            return type(self)(self.default_factory,
-                              copy.deepcopy(self.items()))
-        def __repr__(self):
-            return 'defaultdict(%s, %s)' % (self.default_factory,
-                                            dict.__repr__(self))
-## end of http://code.activestate.com/recipes/523034/ }}}
-
 def list_to_dict(recs, key):
     """
     convert a list of dictionaries into a dictionary keyed on the 
index 242979c..9d22e7f 100644 (file)
@@ -20,12 +20,18 @@ class SfaApi (XmlrpcApi):
     """
     An SfaApi instance is a basic xmlrcp service
     augmented with the local cryptographic material and hrn
-    It also has the notion of neighbour sfa services 
-    as defined in /etc/sfa/{aggregates,registries}.xml
+
+    It also has the notion of its own interface (a string describing
+    whether we run a registry, aggregate or slicemgr) and has 
+    the notion of neighbour sfa services as defined 
+    in /etc/sfa/{aggregates,registries}.xml
+
     Finally it contains a cache instance
+
     It gets augmented by the generic layer with 
     (*) an instance of manager (actually a manager module for now)
     (*) which in turn holds an instance of a testbed driver
+    For convenience api.manager.driver == api.driver
     """
 
     def __init__ (self, encoding="utf-8", methods='sfa.methods', 
index cf2cca9..1466916 100644 (file)
@@ -76,7 +76,7 @@ class Config:
                 except: pass
              
         except IOError, e:
-            raise IOError, "Could not find the configuration file: %s" % config_file
+            raise IOError, "Could not find or load the configuration file: %s" % config_file
 
     def get_trustedroots_dir(self):
         return self.config_path + os.sep + 'trusted_roots'
diff --git a/sfa/util/defaultdict.py b/sfa/util/defaultdict.py
new file mode 100644 (file)
index 0000000..e0dd145
--- /dev/null
@@ -0,0 +1,38 @@
+# from http://code.activestate.com/recipes/523034/
+try:
+    from collections import defaultdict
+except:
+    class defaultdict(dict):
+        def __init__(self, default_factory=None, *a, **kw):
+            if (default_factory is not None and
+                not hasattr(default_factory, '__call__')):
+                raise TypeError('first argument must be callable')
+            dict.__init__(self, *a, **kw)
+            self.default_factory = default_factory
+        def __getitem__(self, key):
+            try:
+                return dict.__getitem__(self, key)
+            except KeyError:
+                return self.__missing__(key)
+        def __missing__(self, key):
+            if self.default_factory is None:
+                raise KeyError(key)
+            self[key] = value = self.default_factory()
+            return value
+        def __reduce__(self):
+            if self.default_factory is None:
+                args = tuple()
+            else:
+                args = self.default_factory,
+            return type(self), args, None, None, self.items()
+        def copy(self):
+            return self.__copy__()
+        def __copy__(self):
+            return type(self)(self.default_factory, self)
+        def __deepcopy__(self, memo):
+            import copy
+            return type(self)(self.default_factory,
+                              copy.deepcopy(self.items()))
+        def __repr__(self):
+            return 'defaultdict(%s, %s)' % (self.default_factory,
+                                            dict.__repr__(self))