From 34fb4a40d65264e12875a5579483042e74ba2c74 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Fri, 7 May 2010 22:54:57 +0000 Subject: [PATCH] refactored --- sfa/managers/registry_manager_pl.py | 2 +- sfa/server/aggregate.py | 14 +++----------- sfa/server/interface.py | 10 +++------- sfa/server/registry.py | 14 +++----------- 4 files changed, 10 insertions(+), 30 deletions(-) diff --git a/sfa/managers/registry_manager_pl.py b/sfa/managers/registry_manager_pl.py index 1af2caf5..24867383 100644 --- a/sfa/managers/registry_manager_pl.py +++ b/sfa/managers/registry_manager_pl.py @@ -129,7 +129,7 @@ def list(api, xrn, origin_hrn=None): tree = prefixTree() tree.load(registry_hrns) registry_hrn = tree.best_match(hrn) - + #if there was no match then this record belongs to an unknow registry if not registry_hrn: raise MissingAuthority(xrn) diff --git a/sfa/server/aggregate.py b/sfa/server/aggregate.py index ce660488..3793a83b 100644 --- a/sfa/server/aggregate.py +++ b/sfa/server/aggregate.py @@ -31,20 +31,12 @@ class Aggregates(Interfaces): def __init__(self, api, conf_file = "/etc/sfa/aggregates.xml"): Interfaces.__init__(self, api, conf_file, 'ma') - - def get_connections(self, interfaces): - """ - Get connection details for the trusted peer aggregates from file and - create an connection to each. - """ - connections = Interfaces.get_connections(self, interfaces) - # set up a connection to the local registry address = self.api.config.SFA_AGGREGATE_HOST port = self.api.config.SFA_AGGREGATE_PORT url = 'http://%(address)s:%(port)s' % locals() local_aggregate = {'hrn': self.api.hrn, 'addr': address, 'port': port} - self.interfaces[self.api.hrn] = local_aggregate - connections[self.api.hrn] = xmlrpcprotocol.get_server(url, self.api.key_file, self.api.cert_file) - return connections + self.interfaces[self.api.hrn] = local_aggregate + # get connections + self.update(self.get_connections()) diff --git a/sfa/server/interface.py b/sfa/server/interface.py index 8e5822e9..5099e9fe 100644 --- a/sfa/server/interface.py +++ b/sfa/server/interface.py @@ -65,8 +65,6 @@ class Interfaces(dict): for interface in interfaces: self.interfaces[interface['hrn']] = interface - # get connections - self.update(self.get_connections(self.interfaces)) def sync_interfaces(self): """ @@ -100,7 +98,7 @@ class Interfaces(dict): try: # get gid from the registry interface_info = self.interfaces[new_hrn] - interface = self.get_connections(self.interfaces[new_hrn])[new_hrn] + interface = self[new_hrn] trusted_gids = interface.get_trusted_certs() if trusted_gids: # the gid we want shoudl be the first one in the list, @@ -167,16 +165,14 @@ class Interfaces(dict): record = SfaRecord(dict=record) table.insert(record) - def get_connections(self, interfaces): + def get_connections(self): """ read connection details for the trusted peer registries from file return a dictionary of connections keyed on interface hrn. """ connections = {} required_fields = self.default_fields.keys() - if not isinstance(interfaces, list): - interfaces = [interfaces] - for interface in interfaces: + for interface in self.interfaces.values(): # make sure the required fields are present and not null if not all([interface.get(key) for key in required_fields]): continue diff --git a/sfa/server/registry.py b/sfa/server/registry.py index 8c60e098..caa128d8 100644 --- a/sfa/server/registry.py +++ b/sfa/server/registry.py @@ -38,19 +38,11 @@ class Registries(Interfaces): def __init__(self, api, conf_file = "/etc/sfa/registries.xml"): Interfaces.__init__(self, api, conf_file, 'sa') - - def get_connections(self, interfaces): - """ - read connection details for the trusted peer registries from file return - a dictionary of connections keyed on interface hrn. - """ - connections = Interfaces.get_connections(self, interfaces) - - # set up a connection to the local registry 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, 'addr': address, 'port': port} self.interfaces[self.api.hrn] = local_registry - connections[self.api.hrn] = xmlrpcprotocol.get_server(url, self.api.key_file, self.api.cert_file) - return connections + + # get connections + self.update(self.get_connections()) -- 2.43.0