+#!/usr/bin/python
+
# $Id$
# $URL$
-"""
-Scan the VINI Central database and create topology "rspec" attributes for
-slices that have an EGRE key. This script to be run from a cron job.
-"""
import string
import socket
import sys
import optparse
+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('-l', '--linkspec', action='store', dest='genlinkspec', default=False, help='Generate linkspec dict.')
+parser.add_option('-l', '--linkspec', action='store_true', dest='genlinkspec', default=False, help='Generate linkspec dict.')
(options, args) = parser.parse_args()
-"""
-Links in the physical topology, gleaned from looking at the Internet2
-and NLR topology maps. Link (a, b) connects sites with IDs a and b.
-"""
+#
+# Links in the physical topology, gleaned from looking at the Internet2
+# and NLR topology maps. Link (a, b) connects sites with IDs a and b.
+#
links = [(2, 12), # I2 Princeton - New York
(4, 5), # NLR Chicago - Houston
(4, 6), # NLR Chicago - Atlanta
"""
Create a dictionary of site records keyed by site ID
"""
- tmp = []
+ tmp = {}
for site in GetSites():
- t = site['site_id'], site
- tmp.append(t)
- return dict(tmp)
+ tmp[site['site_id']] = site
+ return tmp
def get_nodes():
"""
Create a dictionary of node records keyed by node ID
"""
- tmp = []
+ tmp = {}
for node in GetNodes():
- t = node['node_id'], node
- tmp.append(t)
- return dict(tmp)
-
-
-def toDict(a,b):
- """
- Return dict with keys from [a] w/ vals from [b]
- """
- if len(a) == len(b):
- c = {}
- for i in range(0,len(a)):
- c[a[i]] = b[i]
- else:
- except Exception("Length error.")
- return c
+ tmp[node['node_id']] = node
+ return tmp
def ifSpecDict(nodedict):
"""
Generate ifspec dict for given node dict.
"""
- ifspecattrs = ['name',
- 'addr',
- 'type',
- 'init_params',
- 'bw',
- 'min_alloc',
- 'max_alloc',
- 'ip_spoof']
- ifspecs= []
- nodenetworks = GetNodeNetworks(nodedict['nodenetwork_ids'])
- # some nodes have more than 1 public interface.
- for nodenetwork in nodenetworks:
- ifspecs.append( toDict(ifspecattrs,
- [nodenetwork['hostname'],
- nodenetwork['ip'],
- nodenetwork['type'],
- None, '0', '1Gbps', False]))
+ # 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]
+ ifspecs = {'name': nodenetwork['hostname'],
+ 'addr': nodenetwork['ip'],
+ 'type': nodenetwork['type'],
+ 'init_params': None,
+ 'bw': '1Gps',
+ 'min_alloc': 0,
+ 'max_alloc': '1Gbps',
+ 'ip_spoof': False}
return ifspecs
"""
# 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']
- nodes = get_nodes
+ # 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:
- ifSpecDict(nodes[i])
+ 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',
+ 'endpoints': ifspecs,
+ 'start_time': int(time()),
+ 'duration': '-1'})
+ return linkspecs
adjacencies = gen_adjacencies(links)
def main():
-
+ """
+ Scan the VINI Central database and create topology "rspec" attributes for
+ slices that have an EGRE key. This script to be run from a cron job.
+ """
+
for slice in GetSlices():
""" Create dictionary of the slice's attributes """
attrs ={}
if __name__ == '__main__':
- if options.genlinkspec: linkspec()
- else: main()
-
-
+ if options.genlinkspec:
+ import pprint
+ pp = pprint
+ print "LinkSpecs ="
+ pp.pprint(linkSpecDict())
+ else:
+ print "Main"
+ main()