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