svn keywords
[plcapi.git] / PLC / Methods / DeleteEmulationLink.py
1 # Delete an Emulation link
2 #
3 # Marta Carbone - unipi
4 # $Id$
5 # $URL$
6
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.Auth import Auth
12 from PLC.Method import Method
13 from PLC.NodeTags import *
14 from PLC.Accessors.Accessors_dummynetbox import * # import dummynet accessors
15
16 class DeleteEmulationLink(Method):
17     """
18     Delete a connection between a node and a dummynetbox.
19
20     Returns 1 if successful, faults otherwise.
21
22     """
23     roles = ['admin', 'pi', 'tech']
24
25     accepts = [
26         Auth(),
27         Parameter(int, 'node_id'),
28     ]
29
30     returns = Parameter(int, '1 is successful, 0 if not found, fault otherwise')
31
32     def call(self, auth, node_id):
33
34         assert self.caller is not None
35
36         # check for node existence
37         nodes= Nodes(self.api, [node_id])
38         if not nodes:
39             raise PLCInvalidArgument, "Node %s not found" % node_id
40
41         # check for roles permission to call this method
42         if 'admin' not in self.caller['roles']:
43             if site not in self.caller['site_ids']:
44                 raise PLCPermissionDenied, "Not allowed to delete this link"
45
46         # check for the right subclass
47         subclass = GetNodeSubclass(self.api)
48         node_subclass = subclass.call(auth, node_id)
49         if node_subclass != None:
50                 raise  PLCInvalidArgument, "%s is not a node, subclass is %s" % (node_id, node_subclass)
51
52         # Delete from the nodetags the entry with
53         # the given node_id and tagtype = 'dummynetbox'
54         nodetag = NodeTags(self.api, {'node_id':node_id, 'tagname':'dummynetbox_id'})
55
56         if not nodetag:
57             return 0
58
59         nodetag[0].delete()
60
61         return 1