-#!/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()