X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FBootUpdateNode.py;h=d7c85b3f610054ddf95190f05d1ba853b739d080;hb=bd0cbf4f7f2e4cf7ceda500bfa6f98c0a700018b;hp=f89bf2729e440a17e89c7553b18b7f4e79f7f36e;hpb=f7ce7ce813d4c44502629820a3583f32a99a98f7;p=plcapi.git diff --git a/PLC/Methods/BootUpdateNode.py b/PLC/Methods/BootUpdateNode.py index f89bf27..d7c85b3 100644 --- a/PLC/Methods/BootUpdateNode.py +++ b/PLC/Methods/BootUpdateNode.py @@ -1,11 +1,12 @@ -# $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', @@ -80,8 +81,30 @@ class BootUpdateNode(Method): interface.update(interface_fields) interface.sync(commit = False) - # indicate that node has booted & contacted PLC. - node.update_last_contact() + current_time = int(time.time()) + + # ONLY UPDATE ONCE when the boot_state flag and ssh_rsa_key flag are NOT passed + if not node_fields.has_key('boot_state') and not node_fields.has_key('ssh_rsa_key'): + + # record times spent on and off line by comparing last_contact with previous value of last_boot + if node['last_boot'] and node['last_contact']: + # last_boot is when the machine last called this API function. + # last_contact is the last time NM or RLA pinged the API. + node['last_time_spent_online'] = node['last_contact'] - node['last_boot'] + node['last_time_spent_offline'] = current_time - Timestamp.cast_long(node['last_contact']) + + node.update_readonly_int('last_time_spent_online') + node.update_readonly_int('last_time_spent_offline') + changed_fields.append('last_time_spent_online') + changed_fields.append('last_time_spent_offline') + + # indicate that node has booted & contacted PLC. + node.update_last_contact() + node.update_last_boot() + + # 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)