a little nicer wrt pep8
[sfa.git] / sfa / server / registry.py
index da25b2a..edf0711 100644 (file)
@@ -1,18 +1,16 @@
 #
 # Registry is a SfaServer that implements the Registry interface
 #
-### $Id$
-### $URL$
+from sfa.server.sfaserver import SfaServer
+from sfa.server.interface import Interfaces, Interface
+from sfa.util.config import Config
+
+#
+# Registry is a SfaServer that serves registry and slice operations at PLC.
+# this truly is a server-side object
 #
 
-from sfa.util.server import SfaServer
-from sfa.util.faults import *
-from sfa.util.xrn import hrn_to_urn
-from sfa.server.interface import Interfaces
 
-##
-# Registry is a SfaServer that serves registry and slice operations at PLC.
 class Registry(SfaServer):
     ##
     # Create a new registry object.
@@ -21,29 +19,31 @@ class Registry(SfaServer):
     # @param port the port to listen on
     # @param key_file private key filename of registry
     # @param cert_file certificate filename containing public key (could be a GID file)
-    
+
     def __init__(self, ip, port, key_file, cert_file):
-        SfaServer.__init__(self, ip, port, key_file, cert_file,'registry')
+        SfaServer.__init__(self, ip, port, key_file, cert_file, 'registry')
+        sfa_config = Config()
+        if Config().SFA_REGISTRY_ENABLED:
+            from sfa.storage.alchemy import engine
+            from sfa.storage.dbschema import DBSchema
+            DBSchema().init_or_upgrade()
+
+#
+# Registries is a dictionary of registry connections keyed on the registry hrn
+# as such it's more of a client-side thing for registry servers to reach their peers
+#
 
-##
-# Registries is a dictionary of registry connections keyed on the registry
-# hrn
 
 class Registries(Interfaces):
-    
+
     default_dict = {'registries': {'registry': [Interfaces.default_fields]}}
 
-    def __init__(self, api, conf_file = "/etc/sfa/registries.xml"):
-        Interfaces.__init__(self, api, conf_file) 
-        address = self.api.config.SFA_REGISTRY_HOST
-        port = self.api.config.SFA_REGISTRY_PORT
-        url = 'http://%(address)s:%(port)s' % locals()
-        local_registry = {'hrn': self.api.hrn,
-                           'urn': hrn_to_urn(self.api.hrn, 'authority'),
-                           'addr': address,
-                           'port': port,
-                           'url': url}
-        self.interfaces[self.api.hrn] = local_registry
-       
-        # get connections
-        self.update(self.get_connections()) 
+    def __init__(self, conf_file="/etc/sfa/registries.xml"):
+        Interfaces.__init__(self, conf_file)
+        sfa_config = Config()
+        if sfa_config.SFA_REGISTRY_ENABLED:
+            addr = sfa_config.SFA_REGISTRY_HOST
+            port = sfa_config.SFA_REGISTRY_PORT
+            hrn = sfa_config.SFA_INTERFACE_HRN
+            interface = Interface(hrn, addr, port)
+            self[hrn] = interface