try fixing: BootUpdateNode: Invalid argument: Timestamp None - unsupported type ...
[plcapi.git] / PLC / Methods / BootUpdateNode.py
index d69f162..4e81845 100644 (file)
@@ -1,11 +1,14 @@
 # $Id$
 # $URL$
+import time
+
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.Auth import Auth, BootAuth, SessionAuth
 from PLC.Nodes import Node, Nodes
 from PLC.Interfaces import Interface, Interfaces
+from PLC.Timestamp import *
 
 can_update = lambda (field, value): field in \
              ['method', 'mac', 'gateway', 'network',
@@ -59,7 +62,7 @@ class BootUpdateNode(Method):
 
         # Update primary interface state
         if node_fields.has_key('primary_network'):
-            primary_network = node_fields['primary_network'] 
+            primary_network = node_fields['primary_network']
 
             if 'interface_id' not in primary_network:
                 raise PLCInvalidArgument, "Interface not specified"
@@ -82,6 +85,12 @@ class BootUpdateNode(Method):
 
         # indicate that node has booted & contacted PLC.
         node.update_last_contact()
+        node.update_last_boot()
+
+        current_time = int(time.time())
+        # if last_pcu_reboot is within 20 minutes of current_time, accept that the PCU is responsible
+        if node['last_pcu_reboot'] and Timestamp.cast_long(node['last_pcu_reboot']) >= current_time - 60*20:
+            node.update_last_pcu_confirmation(commit=False)
 
         node.sync(commit = True)