done prettifying
[bootmanager.git] / source / steps / UpdateLastBootOnce.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2003 Intel Corporation
4 # All rights reserved.
5 #
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
7 # All rights reserved.
8
9 from Exceptions import *
10 import BootAPI
11 import notify_messages
12 import os.path
13
14
15 def Run(vars, log):
16     """
17     UpdateLastBootOnce will update the last_* values for the node only
18     once per boot.  This helps calculate last_time_spent_online and
19     last_time_spent_offline for collecting run-time metrics.
20     """
21
22     log.write("\n\nStep: Updating node last boot times at PLC.\n")
23
24     update_vals = {}
25     try:
26         if not os.path.isfile("/tmp/UPDATE_LAST_BOOT_ONCE"):
27             BootAPI.call_api_function(vars, "BootUpdateNode", (update_vals,) )
28             log.write("Successfully updated boot state for this node at PLC\n")
29             os.system("touch /tmp/UPDATE_LAST_BOOT_ONCE")
30     except BootManagerException as e:
31         log.write("Unable to update last boot times for this node at PLC: {}.\n"
32                   .format(e))
33     return 1