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
8 from PLC.SFA import SFA
10 class DeleteNode(Method):
12 Mark an existing node as deleted.
14 PIs and techs may only delete nodes at their own sites. ins may
15 delete nodes at any site.
17 Returns 1 if successful, faults otherwise.
20 roles = ['admin', 'pi', 'tech']
24 Mixed(Node.fields['node_id'],
25 Node.fields['hostname'])
28 returns = Parameter(int, '1 if successful')
30 def call(self, auth, node_id_or_hostname):
31 # Get account information
32 nodes = Nodes(self.api, [node_id_or_hostname])
34 raise PLCInvalidArgument, "No such node"
37 if node['peer_id'] is not None:
38 raise PLCInvalidArgument, "Not a local node"
40 # If we are not an admin, make sure that the caller is a
41 # member of the site at which the node is located.
42 if 'admin' not in self.caller['roles']:
43 # Authenticated function
44 assert self.caller is not None
46 if node['site_id'] not in self.caller['site_ids']:
47 raise PLCPermissionDenied, "Not allowed to delete nodes from specified site"
49 node_id=node['node_id']
50 site_id=node['site_id']
54 # it's not much use to attach to the node as it's going to vanish...
55 self.event_objects = {'Node': [node_id], 'Site': [site_id] }
56 self.message = "Node %d deleted" % node['node_id']
59 sfa.delete_record(node, 'node')