- include PLC.Site, PLC.Sites
[plcapi.git] / PLC / Methods / DeleteNode.py
index 9555317..bc92718 100644 (file)
@@ -1,7 +1,7 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
-from PLC.Auth import PasswordAuth
+from PLC.Auth import Auth
 from PLC.Nodes import Node, Nodes
 
 class DeleteNode(Method):
@@ -17,7 +17,7 @@ class DeleteNode(Method):
     roles = ['admin', 'pi', 'tech']
 
     accepts = [
-        PasswordAuth(),
+        Auth(),
         Mixed(Node.fields['node_id'],
               Node.fields['hostname'])
         ]
@@ -29,8 +29,10 @@ class DeleteNode(Method):
         nodes = Nodes(self.api, [node_id_or_hostname])
         if not nodes:
             raise PLCInvalidArgument, "No such node"
+        node = nodes[0]
 
-        node = nodes.values()[0]
+        if node['peer_id'] is not None:
+            raise PLCInvalidArgument, "Not a local node"
 
         # If we are not an admin, make sure that the caller is a
         # member of the site at which the node is located.
@@ -43,4 +45,8 @@ class DeleteNode(Method):
 
         node.delete()
 
+       # Logging variables
+       self.event_objects = {'Node': [node['node_id']]}
+       self.message = "Node %d deleted" % node['node_id']
+
         return 1