2 # Registry is a GeniServer that implements the Registry interface
13 from sfa.util.geniserver import GeniServer
14 from sfa.util.genitable import GeniTable
15 from sfa.util.faults import *
16 from sfa.util.storage import *
17 import sfa.util.xmlrpcprotocol as xmlrpcprotocol
18 import sfa.util.soapprotocol as soapprotocol
20 # GeniLight client support is optional
22 from egeni.geniLight_client import *
24 GeniClientLight = None
27 # Registry is a GeniServer that serves registry and slice operations at PLC.
29 class Registry(GeniServer):
31 # Create a new registry object.
33 # @param ip the ip address to listen on
34 # @param port the port to listen on
35 # @param key_file private key filename of registry
36 # @param cert_file certificate filename containing public key (could be a GID file)
38 def __init__(self, ip, port, key_file, cert_file):
39 GeniServer.__init__(self, ip, port, key_file, cert_file)
40 self.server.interface = 'registry'
44 # Registries is a dictionary of geniclient registry connections keyed on the registry
47 class Registries(dict):
49 required_fields = ['hrn', 'addr', 'port']
51 def __init__(self, api, file = "/etc/sfa/registries.xml"):
52 dict.__init__(self, {})
56 # create default connection dict
58 for field in self.required_fields:
59 connection_dict[field] = ''
60 registries_dict = {'registries': {'registry': [connection_dict]}}
62 # get possible config file locations
64 path = os.path.dirname(os.path.abspath(__file__))
65 filename = file.split(os.sep)[-1]
66 alt_file = path + os.sep + filename
67 files = [file, alt_file]
72 self.registry_info = XmlStorage(f, registries_dict)
76 # if file is missing, just recreate it in the right place
78 self.registry_info = XmlStorage(file, registries_dict)
79 self.registry_info.load()
80 self.connectRegistries()
82 def connectRegistries(self):
84 Get connection details for the trusted peer registries from file and
85 create an GeniClient connection to each.
87 registries = self.registry_info['registries']['registry']
88 if isinstance(registries, dict):
89 registries = [registries]
90 if isinstance(registries, list):
91 for registry in registries:
92 # make sure the required fields are present
93 if not set(self.required_fields).issubset(registry.keys()):
95 hrn, address, port = registry['hrn'], registry['addr'], registry['port']
96 if not hrn or not address or not port:
98 self.interfaces.append(registry)
99 # check which client we should use
100 # geniclient is default
101 client_type = 'geniclient'
102 if registry.has_key('client') and registry['client'] in ['geniclientlight']:
103 client_type = 'geniclientlight'
106 url = 'http://%(address)s:%(port)s' % locals()
108 # create the client connection
109 # make sure module exists before trying to instantiate it
110 if client_type in ['geniclientlight'] and GeniClientLight:
111 self[hrn] = GeniClientLight(url, self.api.key_file, self.api.cert_file)
113 self[hrn] = xmlrpcprotocol.get_server(url, self.api.key_file, self.api.cert_file)
115 # set up a connection to the local registry
116 # connect to registry using GeniClient
117 address = self.api.config.SFA_REGISTRY_HOST
118 port = self.api.config.SFA_REGISTRY_PORT
119 url = 'http://%(address)s:%(port)s' % locals()
120 local_registry = {'hrn': self.api.hrn, 'addr': address, 'port': port}
121 self.interfaces.append(local_registry)
122 self[self.api.hrn] = xmlrpcprotocol.get_server(url, self.api.key_file, self.api.cert_file)