Detangled steps. No step makes calls into another step.
[bootmanager.git] / source / steps / UpdateBootStateWithPLC.py
1 #!/usr/bin/python2 -u
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 current value of the BOOT_STATE key in vars is used.
19     Optionally, notify the contacts of the boot state change.
20     If this is the case, the following keys/values
21     should be set in vars before calling this step:
22     STATE_CHANGE_NOTIFY= 1
23     STATE_CHANGE_NOTIFY_MESSAGE= "<notify message>"
24     The second value is a message to send the users from notify_messages.py
25
26     Return 1 if succesfull, a BootManagerException otherwise.
27     """
28
29     log.write( "\n\nStep: Updating node boot state at PLC.\n" )
30
31     update_vals= {}
32     update_vals['boot_state']= vars['BOOT_STATE']
33     BootAPI.call_api_function( vars, "BootUpdateNode", (update_vals,) )
34
35     log.write( "Successfully updated boot state for this node at PLC\n" )
36
37
38     notify = vars.get("STATE_CHANGE_NOTIFY",0)
39
40     if notify:
41         message= vars['STATE_CHANGE_NOTIFY_MESSAGE']
42         include_pis= 0
43         include_techs= 1
44         include_support= 0
45
46         sent= 0
47         try:
48             sent= BootAPI.call_api_function( vars, "BootNotifyOwners",
49                                              (message,
50                                               include_pis,
51                                               include_techs,
52                                               include_support) )
53         except BootManagerException, e:
54             log.write( "Call to BootNotifyOwners failed: %s.\n" % e )
55
56         if sent == 0:
57             log.write( "Unable to notify site contacts of state change.\n" )
58
59     return 1