417dd12b5acaa956960733322ee8a3b32daf1bf9
[bootmanager.git] / source / steps / UpdateBootStateWithPLC.py
1 from Exceptions import *
2 import BootAPI
3 import notify_messages
4
5
6 def Run( vars, log ):
7     """
8     Change this nodes boot state at PLC.
9
10     The current value of the BOOT_STATE key in vars is used.
11     Optionally, notify the contacts of the boot state change.
12     If this is the case, the following keys/values
13     should be set in vars before calling this step:
14     STATE_CHANGE_NOTIFY= 1
15     STATE_CHANGE_NOTIFY_MESSAGE= "<notify message>"
16     The second value is a message to send the users from notify_messages.py
17
18     Return 1 if succesfull, a BootManagerException otherwise.
19     """
20
21     log.write( "\n\nStep: Updating node boot state at PLC.\n" )
22
23     update_vals= {}
24     update_vals['boot_state']= vars['BOOT_STATE']
25     BootAPI.call_api_function( vars, "BootUpdateNode", (update_vals,) )
26
27     log.write( "Successfully updated boot state for this node at PLC\n" )
28
29
30     if "STATE_CHANGE_NOTIFY" in vars.keys():
31         if vars["STATE_CHANGE_NOTIFY"] == 1:
32             message= vars['STATE_CHANGE_NOTIFY_MESSAGE']
33             include_pis= 0
34             include_techs= 1
35             include_support= 0
36             
37             sent= 0
38             try:
39                 sent= BootAPI.call_api_function( vars, "BootNotifyOwners",
40                                                  (message,
41                                                   include_pis,
42                                                   include_techs,
43                                                   include_support) )
44             except BootManagerException, e:
45                 log.write( "Call to BootNotifyOwners failed: %s.\n" % e )
46                 
47             if sent == 0:
48                 log.write( "Unable to notify site contacts of state change.\n" )
49     
50     return 1