7 from types import StringTypes, ListType
8 from geni.util.geniserver import GeniServer
9 from geni.util.geniclient import GeniClient
10 from geni.util.storage import *
11 from geni.util.excep import *
13 class Aggregate(GeniServer):
16 # Create a new aggregate object.
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)
23 def __init__(self, ip, port, key_file, cert_file, config = "/usr/share/geniwrapper/geni/util/geni_config"):
24 GeniServer.__init__(self, ip, port, key_file, cert_file)
25 self.server.interface = 'aggregate'
28 # Aggregates is a dictionary of geniclient aggregate connections keyed on the aggregate hrn
30 class Aggregates(dict):
32 def __init__(self, api):
33 dict.__init__(self, {})
35 aggregates_file = self.api.server_basedir + os.sep + 'aggregates.xml'
36 connection_dict = {'hrn': '', 'addr': '', 'port': ''}
37 self.aggregate_info = XmlStorage(aggregates_file, {'aggregates': {'aggregate': [connection_dict]}})
38 self.aggregate_info.load()
39 self.connectAggregates()
42 def connectAggregates(self):
44 Get connection details for the trusted peer aggregates from file and
45 create an GeniClient connection to each.
47 required_fields = ['hrn', 'addr', 'port']
48 aggregates = self.aggregate_info['aggregates']['aggregate']
49 if isinstance(aggregates, dict):
50 aggregates = [aggregates]
51 if isinstance(aggregates, list):
52 for aggregate in aggregates:
53 # create xmlrpc connection using GeniClient
54 if not set(required_fields).issubset(aggregate.keys()):
56 hrn, address, port = aggregate['hrn'], aggregate['addr'], aggregate['port']
57 if not hrn or not address or not port:
59 url = 'http://%(address)s:%(port)s' % locals()
60 self[hrn] = GeniClient(url, self.api.key_file, self.api.cert_file)
62 # set up a connection to the local registry
63 # connect to registry using GeniClient
64 address = self.api.config.GENI_AGGREGATE_HOSTNAME
65 port = self.api.config.GENI_AGGREGATE_PORT
66 url = 'http://%(address)s:%(port)s' % locals()
67 self[self.api.hrn] = GeniClient(url, self.api.key_file, self.api.cert_file)