1 # Connect a Node with a Dummynet box, using Accessors
3 # Marta Carbone - unipi
7 from PLC.Faults import *
8 from PLC.Method import Method
9 from PLC.Parameter import Parameter, Mixed
10 from PLC.Nodes import Node, Nodes
11 from PLC.NodeGroups import NodeGroup, NodeGroups
12 from PLC.Sites import Site, Sites
13 from PLC.Auth import Auth
14 from PLC.Accessors.Accessors_dummynetbox import * # import dummynet accessors
16 class UpdateEmulationLink(Method):
18 Connect a Node with a Dummynet box.
19 Takes as input two node_id, the first should be a regular node,
20 the second a dummynet box.
22 This operation is restricted to PIs and techs owner of the site
23 on which the Dummynet box and the Node are located.
24 Admins may create emulation links for any site, but the Dummynet
25 and the Node must belong to the same site.
27 XXX Dummynet accessors should not be called directly, since they can
28 be used to create connection whitout checks.
30 Returns 1 if successful, faults otherwise.
33 roles = ['admin', 'pi', 'tech']
37 Parameter(int, 'node_id'), # a node
38 Mixed(Parameter(int, 'node_id'), # a dummynet box, or None to delete the entry
42 returns = Parameter(int, '1 is successful, fault otherwise')
44 # Before to create the link we do the following checks:
46 # - dummnet box existence,
47 # - right roles (admin, pi, tech),
48 # - node and dummynet box site should match.
50 def call(self, auth, node_id, dummynet_id):
52 assert self.caller is not None
54 # check for node existence
55 # Retrieve nodes from database
56 # We do not fetch both node and dummynet
57 # since we need to preserve the order of returned objects
58 nodes= Nodes(self.api, {'node_id':node_id, 'node_type':'regular'})
60 raise PLCInvalidArgument, "Node %s not found" % node_id
63 # check for dummynet box existence
64 nodes = Nodes(self.api, {'node_id':dummynet_id, 'node_type':'dummynet'})
65 if (dummynet_id != None) and not nodes:
66 raise PLCInvalidArgument, "Dummynet box %s not found" % dummynet_id
68 # check for site matching when create a link
69 if (dummynet_id != None):
72 # check if the node and the dummynet_id
73 # belong to the same site
74 if (node['site_id'] != dummynet['site_id']):
75 raise PLCInvalidArgument, \
76 "The Dummynet box must belog to the same site of the Node"
78 # check for roles permission to call this method
79 if 'admin' not in self.caller['roles']:
80 if site not in self.caller['site_ids']:
81 raise PLCPermissionDenied, "Not allowed to manage on this link"
84 emulation_link = SetNodeDummynetBox(self.api)
85 emulation_link.call(auth, node_id, dummynet_id)