3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Auth import Auth
7 from PLC.Nodes import Node, Nodes
9 class DeleteNode(Method):
11 Mark an existing node as deleted.
13 PIs and techs may only delete nodes at their own sites. ins may
14 delete nodes at any site.
16 Returns 1 if successful, faults otherwise.
19 roles = ['admin', 'pi', 'tech']
23 Mixed(Node.fields['node_id'],
24 Node.fields['hostname'])
27 returns = Parameter(int, '1 if successful')
29 def call(self, auth, node_id_or_hostname):
30 # Get account information
31 nodes = Nodes(self.api, [node_id_or_hostname])
33 raise PLCInvalidArgument, "No such node"
36 if node['peer_id'] is not None:
37 raise PLCInvalidArgument, "Not a local node"
39 # If we are not an admin, make sure that the caller is a
40 # member of the site at which the node is located.
41 if 'admin' not in self.caller['roles']:
42 # Authenticated function
43 assert self.caller is not None
45 if node['site_id'] not in self.caller['site_ids']:
46 raise PLCPermissionDenied, "Not allowed to delete nodes from specified site"
48 node_id=node['node_id']
49 site_id=node['site_id']
53 # it's not much use to attach to the node as it's going to vanish...
54 self.event_objects = {'Node': [node_id], 'Site': [site_id] }
55 self.message = "Node %d deleted" % node['node_id']