- Change .py files to use 4-space indents and no hard tab characters.
[plcapi.git] / PLC / Methods / RebootNode.py
index 59eb688..956d342 100644 (file)
@@ -1,11 +1,13 @@
+# $Id$
+# $URL$
 import socket
 
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.Nodes import Node, Nodes
-from PLC.NodeNetworks import NodeNetwork, NodeNetworks
-from PLC.Auth import PasswordAuth
+from PLC.Interfaces import Interface, Interfaces
+from PLC.Auth import Auth
 from PLC.POD import udp_pod
 
 class RebootNode(Method):
@@ -23,7 +25,7 @@ class RebootNode(Method):
     roles = ['admin', 'pi', 'tech']
 
     accepts = [
-        PasswordAuth(),
+        Auth(),
         Mixed(Node.fields['node_id'],
               Node.fields['hostname'])
         ]
@@ -32,7 +34,7 @@ class RebootNode(Method):
 
     def call(self, auth, node_id_or_hostname):
         # Get account information
-        nodes = Nodes(self.api, [node_id_or_hostname]).values()
+        nodes = Nodes(self.api, [node_id_or_hostname])
         if not nodes:
             raise PLCInvalidArgument, "No such node"
 
@@ -55,10 +57,10 @@ class RebootNode(Method):
         # Only use the hostname as a backup, try to use the primary ID
         # address instead.
         host = node['hostname']
-        nodenetworks = NodeNetworks(self.api, node['nodenetwork_ids']).values()
-        for nodenetwork in nodenetworks:
-            if nodenetwork['is_primary'] == 1:
-                host = nodenetwork['ip']
+        interfaces = Interfaces(self.api, node['interface_ids'])
+        for interface in interfaces:
+            if interface['is_primary'] == 1:
+                host = interface['ip']
                 break
 
         try:
@@ -66,5 +68,8 @@ class RebootNode(Method):
         except socket.error, e:
             # Ignore socket errors
             pass
-        
+
+        self.event_objects = {'Node': [node['node_id']]}
+        self.message = "RebootNode called"
+
         return 1