done prettifying
[bootmanager.git] / source / steps / UpdateBootStateWithPLC.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
13
14 def Run(vars, log):
15     """
16     Change this nodes boot state at PLC.
17
18     The only valid transition is from reinstall to boot.  All other changes to
19     the boot state of a node should be performed by the Admin, Tech or PI
20     through the API or Web interface.
21
22     The current value of the BOOT_STATE key in vars is used.
23     Optionally, notify the contacts of the boot state change.
24     If this is the case, the following keys/values
25     should be set in vars before calling this step:
26     STATE_CHANGE_NOTIFY = 1
27     STATE_CHANGE_NOTIFY_MESSAGE = "<notify message>"
28     The second value is a message to send the users from notify_messages.py
29
30     Return 1 if succesfull, a BootManagerException otherwise.
31     """
32
33     log.write("\n\nStep: Updating node boot state at PLC.\n")
34
35     update_vals = {}
36     update_vals['boot_state'] = vars['BOOT_STATE']
37     try:
38         BootAPI.call_api_function(vars, "BootUpdateNode", (update_vals,))
39         log.write("Successfully updated boot state for this node at PLC\n")
40     except BootManagerException as e:
41         log.write("Unable to update boot state for this node at PLC: {}.\n".format(e))
42
43     notify = vars.get("STATE_CHANGE_NOTIFY",0)
44
45     if notify:
46         message = vars['STATE_CHANGE_NOTIFY_MESSAGE']
47         include_pis = 0
48         include_techs = 1
49         include_support = 0
50
51         sent = 0
52         try:
53             sent = BootAPI.call_api_function(vars, "BootNotifyOwners",
54                                              (message,
55                                               include_pis,
56                                               include_techs,
57                                               include_support))
58         except BootManagerException as e:
59             log.write("Call to BootNotifyOwners failed: {}.\n".format(e))
60
61         if sent == 0:
62             log.write("Unable to notify site contacts of state change.\n")
63
64     return 1