Revert create-topo-attributes.py
[nodemanager-topo.git] / vinilinkspec.py
1 #!/usr/bin/python
2
3 # $Id$
4 # $URL$
5
6
7 import sys
8 import optparse
9 from topology import links
10 from time import time
11
12 # Load shell with default configuration
13 sys.path.append('/usr/share/plc_api')
14 from PLC.Shell import Shell
15 plc = Shell(globals())
16
17 parser = optparse.OptionParser()
18 parser.add_option('-v', '--verbose', action='store_true', dest='DEBUG', default=False, help='Run in verbose mode.')
19 (options, args) = parser.parse_args()
20
21
22 def ifSpecDict(nodedict):
23     """
24     Generate ifspec dict for given node dict.
25     """
26     # ifspecattrs = ['name',
27     #            'addr',
28     #            'type', 
29     #            'init_params', 
30     #            'bw', 
31     #            'min_alloc', 
32     #            'max_alloc', 
33     #            'ip_spoof']
34     # Assume only 1 node network per node.
35     nodenetwork = GetNodeNetworks(nodedict['nodenetwork_ids'])[0]
36     ifspecs = {'name': nodenetwork['hostname'],
37                'addr': nodenetwork['ip'],
38                'type': nodenetwork['type'],
39                'init_params': None,
40                'bw': '1Gps',
41                'min_alloc': 0,
42                'max_alloc': '1Gbps',
43                'ip_spoof': False}
44     return ifspecs
45
46
47 def linkSpecDict():
48     """
49     Create dict for physical topology.
50     """
51     # list of attributes in the LinkSpec 
52     # (https://svn.planet-lab.org/svn/geniwrapper/trunk/rspec/model/planetlab.{ecore,xsd})
53     # linkspecattrs = ['type', 
54     #            'init_params', 
55     #            'bw', 
56     #            'min_alloc', 
57     #            'max_alloc', 
58     #            'endpoint', # <-- ifspec(S)?
59     #            'start_time', 
60     #            'duration']
61     # list of linkspecs.  1 per adjacency 
62     linkspecs = []
63     # links maps sites.  Get nodes in site, make linkspecs for each.
64     for (i, j) in links:
65         if options.DEBUG:
66             print "sites = (%s, %s) nodes = %s" %(i,j, GetNodes({'site_id':[i,j]}, ['node_id']))
67         nodeset = GetNodes({'site_id':[i,j]})
68         ifspecs = []
69         for node in nodeset: 
70             ifspecs.append(ifSpecDict(node))
71         linkspecs.append({\
72                 'type': 'ipv4',
73                 'init_params': None,
74                 'bw': '1Gbps',
75                 'min_alloc': '0',
76                 'bw': '1Gbps',
77                 'endpoints': ifspecs,
78                 'start_time': int(time()),
79                 'duration': '-1'})
80     return linkspecs
81
82
83 def main():
84     pp = pprint
85     print "LinkSpecs ="
86     pp.pprint(linkSpecDict())
87       
88
89 if __name__ == '__main__':
90     import pprint
91     main()