From c0825d3b2e73ee9b9c43abc5e57405cca5174e94 Mon Sep 17 00:00:00 2001 From: Faiyaz Ahmed Date: Tue, 10 Mar 2009 21:02:55 +0000 Subject: [PATCH] Decided to make this an API call. --- GetLinkSpecs.py | 85 +++++++++++++++++++++++++++++++++++++++++++++ vinilinkspec.py | 91 ------------------------------------------------- 2 files changed, 85 insertions(+), 91 deletions(-) create mode 100755 GetLinkSpecs.py delete mode 100755 vinilinkspec.py diff --git a/GetLinkSpecs.py b/GetLinkSpecs.py new file mode 100755 index 0000000..32bddda --- /dev/null +++ b/GetLinkSpecs.py @@ -0,0 +1,85 @@ +# $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', + 'endpoint': ifspecs, + 'start_time': int(time()), + 'duration': '-1'}) + return {'LinkSpec': linkspecs} + diff --git a/vinilinkspec.py b/vinilinkspec.py deleted file mode 100755 index 1f47e26..0000000 --- a/vinilinkspec.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/python - -# $Id$ -# $URL$ - - -import sys -import optparse -from topology import links -from time import time - -# Load shell with default configuration -sys.path.append('/usr/share/plc_api') -from PLC.Shell import Shell -plc = Shell(globals()) - -parser = optparse.OptionParser() -parser.add_option('-v', '--verbose', action='store_true', dest='DEBUG', default=False, help='Run in verbose mode.') -(options, args) = parser.parse_args() - - -def ifSpecDict(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(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 linkSpecDict(): - """ - 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: - if options.DEBUG: - print "sites = (%s, %s) nodes = %s" %(i,j, GetNodes({'site_id':[i,j]}, ['node_id'])) - nodeset = GetNodes({'site_id':[i,j]}) - ifspecs = [] - for node in nodeset: - ifspecs.append(ifSpecDict(node)) - linkspecs.append({\ - 'type': 'ipv4', - 'init_params': None, - 'bw': '1Gbps', - 'min_alloc': '0', - 'bw': '1Gbps', - 'endpoint': ifspecs, - 'start_time': int(time()), - 'duration': '-1'}) - return {'LinkSpec': linkspecs} - - -def main(): - pp = pprint - print "LinkSpecs =" - pp.pprint(linkSpecDict()) - - -if __name__ == '__main__': - import pprint - main() -- 2.43.0