a little nicer wrt pep8
[sfa.git] / sfa / server / registry.py
1 #
2 # Registry is a SfaServer that implements the Registry interface
3 #
4 from sfa.server.sfaserver import SfaServer
5 from sfa.server.interface import Interfaces, Interface
6 from sfa.util.config import Config
7
8 #
9 # Registry is a SfaServer that serves registry and slice operations at PLC.
10 # this truly is a server-side object
11 #
12
13
14 class Registry(SfaServer):
15     ##
16     # Create a new registry object.
17     #
18     # @param ip the ip address to listen on
19     # @param port the port to listen on
20     # @param key_file private key filename of registry
21     # @param cert_file certificate filename containing public key (could be a GID file)
22
23     def __init__(self, ip, port, key_file, cert_file):
24         SfaServer.__init__(self, ip, port, key_file, cert_file, 'registry')
25         sfa_config = Config()
26         if Config().SFA_REGISTRY_ENABLED:
27             from sfa.storage.alchemy import engine
28             from sfa.storage.dbschema import DBSchema
29             DBSchema().init_or_upgrade()
30
31 #
32 # Registries is a dictionary of registry connections keyed on the registry hrn
33 # as such it's more of a client-side thing for registry servers to reach their peers
34 #
35
36
37 class Registries(Interfaces):
38
39     default_dict = {'registries': {'registry': [Interfaces.default_fields]}}
40
41     def __init__(self, conf_file="/etc/sfa/registries.xml"):
42         Interfaces.__init__(self, conf_file)
43         sfa_config = Config()
44         if sfa_config.SFA_REGISTRY_ENABLED:
45             addr = sfa_config.SFA_REGISTRY_HOST
46             port = sfa_config.SFA_REGISTRY_PORT
47             hrn = sfa_config.SFA_INTERFACE_HRN
48             interface = Interface(hrn, addr, port)
49             self[hrn] = interface