# $Id$ # $URL$ import sys from topology import links from time import time from topology import links from PLC.Faults import * from PLC.Method import Method from PLC.Methods.GetNodeNetworks import GetNodeNetworks from PLC.Methods.GetNodes import GetNodes from PLC.Auth import Auth class GetLinkSpecs(GetNodeNetworks, GetNodes): """ Return LinkSpecs for topology. """ returns = dict roles = ['admin', 'pi', 'user'] accepts = [ Auth() ] def ifSpecDict(self, auth, nodedict): """ Generate ifspec dict for given node dict. """ # ifspecattrs = ['name', # 'addr', # 'type', # 'init_params', # 'bw', # 'min_alloc', # 'max_alloc', # 'ip_spoof'] # Assume only 1 node network per node. nodenetwork = GetNodeNetworks.call(self, auth, nodedict['nodenetwork_ids'])[0] ifspec = {'name': nodenetwork['hostname'], 'addr': nodenetwork['ip'], 'type': nodenetwork['type'], 'init_params': None, 'bw': '1Gps', 'min_alloc': 0, 'max_alloc': '1Gbps', 'ip_spoof': False} return {'IfSpec': ifspec} def call(self, auth): """ Create dict for physical topology. """ # list of attributes in the LinkSpec # (https://svn.planet-lab.org/svn/geniwrapper/trunk/rspec/model/planetlab.{ecore,xsd}) # linkspecattrs = ['type', # 'init_params', # 'bw', # 'min_alloc', # 'max_alloc', # 'endpoint', # <-- ifspec(S)? # 'start_time', # 'duration'] # list of linkspecs. 1 per adjacency linkspecs = [] # links maps sites. Get nodes in site, make linkspecs for each. for (i, j) in links: nodeset = GetNodes.call(self, auth, {'site_id':[i,j]}) ifspecs = [] for node in nodeset: ifspecs.append(self.ifSpecDict(auth, node)) linkspecs.append({\ 'type': 'ipv4', 'init_params': None, 'bw': '1Gbps', 'min_alloc': '0', 'bw': '1Gbps', 'max_alloc': '1Gbps', 'endpoint': ifspecs, 'start_time': int(time()), 'duration': '-1'}) return linkspecs