Changes for 2.6.32 kernel
[nodemanager-topo.git] / GetLinkSpecs.py
1 # $Id$
2 # $URL$
3
4
5 import sys
6 from topology import links
7 from time import time
8 from topology import links
9
10 from PLC.Faults import *
11 from PLC.Method import Method
12 from PLC.Methods.GetNodeNetworks import GetNodeNetworks
13 from PLC.Methods.GetNodes import GetNodes
14 from PLC.Auth import Auth
15
16
17 class GetLinkSpecs(GetNodeNetworks, GetNodes):
18     """
19     Return LinkSpecs for topology.
20     """
21     returns = dict
22     roles = ['admin', 'pi', 'user']
23
24     accepts = [
25         Auth()
26         ]
27
28     def ifSpecDict(self, auth, nodedict):
29         """
30         Generate ifspec dict for given node dict.
31         """
32         # ifspecattrs = ['name',
33         #            'addr',
34         #            'type', 
35         #            'init_params', 
36         #            'bw', 
37         #            'min_alloc', 
38         #            'max_alloc', 
39         #            'ip_spoof']
40         # Assume only 1 node network per node.
41         nodenetwork = GetNodeNetworks.call(self, auth, nodedict['nodenetwork_ids'])[0]
42         ifspec = {'name': nodenetwork['hostname'],
43                    'addr': nodenetwork['ip'],
44                    'type': nodenetwork['type'],
45                    'init_params': None,
46                    'bw': '1Gps',
47                    'min_alloc': 0,
48                    'max_alloc': '1Gbps',
49                    'ip_spoof': False}
50         return {'IfSpec': ifspec}
51     
52     
53     def call(self, auth):
54         """
55         Create dict for physical topology.
56         """
57         # list of attributes in the LinkSpec 
58         # (https://svn.planet-lab.org/svn/geniwrapper/trunk/rspec/model/planetlab.{ecore,xsd})
59         # linkspecattrs = ['type', 
60         #            'init_params', 
61         #            'bw', 
62         #            'min_alloc', 
63         #            'max_alloc', 
64         #            'endpoint', # <-- ifspec(S)?
65         #            'start_time', 
66         #            'duration']
67         # list of linkspecs.  1 per adjacency 
68         linkspecs = []
69         # links maps sites.  Get nodes in site, make linkspecs for each.
70         for (i, j) in links:
71             nodeset = GetNodes.call(self, auth, {'site_id':[i,j]})
72             ifspecs = []
73             for node in nodeset: 
74                 ifspecs.append(self.ifSpecDict(auth, node))
75             linkspecs.append({\
76                     'type': 'ipv4',
77                     'init_params': None,
78                     'bw': '1Gbps',
79                     'min_alloc': '0',
80                     'bw': '1Gbps',
81                     'max_alloc': '1Gbps',
82                     'endpoint': ifspecs,
83                     'start_time': int(time()),
84                     'duration': '-1'})
85         return linkspecs
86