1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Auth import Auth
5 from PLC.Nodes import Node, Nodes
7 class DeleteNode(Method):
9 Mark an existing node as deleted.
11 PIs and techs may only delete nodes at their own sites. ins may
12 delete nodes at any site.
14 Returns 1 if successful, faults otherwise.
17 roles = ['admin', 'pi', 'tech']
21 Mixed(Node.fields['node_id'],
22 Node.fields['hostname'])
25 returns = Parameter(int, '1 if successful')
28 def call(self, auth, node_id_or_hostname):
29 # Get account information
30 nodes = Nodes(self.api, [node_id_or_hostname])
32 raise PLCInvalidArgument, "No such node"
35 if node['peer_id'] is not None:
36 raise PLCInvalidArgument, "Not a local node"
38 # If we are not an admin, make sure that the caller is a
39 # member of the site at which the node is located.
40 if 'admin' not in self.caller['roles']:
41 # Authenticated function
42 assert self.caller is not None
44 if node['site_id'] not in self.caller['site_ids']:
45 raise PLCPermissionDenied, "Not allowed to delete nodes from specified site"
50 self.object_ids = [node['node_id']]
51 self.message = "Node %d deleted" % node['node_id']