7 from types import StringTypes, ListType
8 from geni.util.geniserver import GeniServer
9 from geni.util.geniclient import GeniClient
10 from geni.util.excep import *
12 class Aggregate(GeniServer):
15 # Create a new aggregate object.
17 # @param ip the ip address to listen on
18 # @param port the port to listen on
19 # @param key_file private key filename of registry
20 # @param cert_file certificate filename containing public key (could be a GID file)
22 def __init__(self, ip, port, key_file, cert_file, config = "/usr/share/geniwrapper/geni/util/geni_config"):
23 GeniServer.__init__(self, ip, port, key_file, cert_file)
24 self.server.interface = 'aggregate'
27 # Aggregates is a dictionary of geniclient aggregate connections keyed on the aggregate hrn
29 class Aggregates(dict):
31 def __init__(self, api):
32 dict.__init__(self, {})
34 aggregates_file = self.api.server_basedir + os.sep + 'aggregates.xml'
35 connection_dict = {'hrn': '', 'addr': '', 'port': ''}
36 self.aggregate_info = XmlStorage(aggregates_file, {'aggregates': {'aggregate': [connection_dict]}})
37 self.aggregate_info.load()
38 self.connectAggregates()
41 def connectAggregates(self):
43 Get connection details for the trusted peer aggregates from file and
44 create an GeniClient connection to each.
46 required_fields = ['hrn', 'addr', 'port']
47 aggregates = self.aggregate_info['aggregates']['aggregate']
48 if isinstance(aggregates, dict):
49 aggregates = [aggregates]
50 if isinstance(aggregates, list):
51 for aggregate in aggregates:
52 # create xmlrpc connection using GeniClient
53 if not set(required_fields).issubset(aggregate.keys()):
55 hrn, address, port = aggregate['hrn'], aggregate['addr'], aggregate['port']
56 if not hrn or not address or not port:
58 url = 'http://%(address)s:%(port)s' % locals()
59 self[hrn] = GeniClient(url, self.api.key_file, self.api.cert_file)
61 # set up a connection to the local registry
62 # connect to registry using GeniClient
63 address = self.api.config.GENI_AGGREGATE_HOSTNAME
64 port = self.api.config.GENI_AGGREGATE_PORT
65 url = 'http://%(address)s:%(port)s' % locals()
66 self[self.api.hrn] = GeniClient(url, self.api.key_file, self.api.cert_file)