SFA object constructor now requires a argument
[plcapi.git] / PLC / Methods / DeleteNode.py
index 9555317..e62f23c 100644 (file)
@@ -1,8 +1,11 @@
+# $Id$
+# $URL$
 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
+from PLC.SFA import SFA
 
 class DeleteNode(Method):
     """
@@ -17,7 +20,7 @@ class DeleteNode(Method):
     roles = ['admin', 'pi', 'tech']
 
     accepts = [
-        PasswordAuth(),
+        Auth(),
         Mixed(Node.fields['node_id'],
               Node.fields['hostname'])
         ]
@@ -29,8 +32,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.
@@ -41,6 +46,16 @@ class DeleteNode(Method):
             if node['site_id'] not in self.caller['site_ids']:
                 raise PLCPermissionDenied, "Not allowed to delete nodes from specified site"
 
+        node_id=node['node_id']
+        site_id=node['site_id']
         node.delete()
 
+        # Logging variables
+        # it's not much use to attach to the node as it's going to vanish...
+        self.event_objects = {'Node': [node_id], 'Site': [site_id] }
+        self.message = "Node %d deleted" % node['node_id']
+
+        sfa = SFA(self.api)
+        sfa.delete_record(node, 'node')       
+
         return 1