svn:keywords
[bootmanager.git] / source / steps / UpdateBootStateWithPLC.py
1 #!/usr/bin/python
2 #
3 # $Id$
4 # $URL$
5 #
6 # Copyright (c) 2003 Intel Corporation
7 # All rights reserved.
8 #
9 # Copyright (c) 2004-2006 The Trustees of Princeton University
10 # All rights reserved.
11
12 from Exceptions import *
13 import BootAPI
14 import notify_messages
15
16
17 def Run( vars, log ):
18     """
19     Change this nodes boot state at PLC.
20
21     The only valid transition is from reinstall to boot.  All other changes to
22     the boot state of a node should be performed by the Admin, Tech or PI
23     through the API or Web interface.
24
25     The current value of the BOOT_STATE key in vars is used.
26     Optionally, notify the contacts of the boot state change.
27     If this is the case, the following keys/values
28     should be set in vars before calling this step:
29     STATE_CHANGE_NOTIFY= 1
30     STATE_CHANGE_NOTIFY_MESSAGE= "<notify message>"
31     The second value is a message to send the users from notify_messages.py
32
33     Return 1 if succesfull, a BootManagerException otherwise.
34     """
35
36     log.write( "\n\nStep: Updating node boot state at PLC.\n" )
37
38     update_vals= {}
39     update_vals['boot_state']= vars['BOOT_STATE']
40     try:
41         BootAPI.call_api_function( vars, "BootUpdateNode", (update_vals,) )
42         log.write( "Successfully updated boot state for this node at PLC\n" )
43     except BootManagerException, e:
44         log.write( "Unable to update boot state for this node at PLC: %s.\n" % e )
45
46     notify = vars.get("STATE_CHANGE_NOTIFY",0)
47
48     if notify:
49         message= vars['STATE_CHANGE_NOTIFY_MESSAGE']
50         include_pis= 0
51         include_techs= 1
52         include_support= 0
53
54         sent= 0
55         try:
56             sent= BootAPI.call_api_function( vars, "BootNotifyOwners",
57                                              (message,
58                                               include_pis,
59                                               include_techs,
60                                               include_support) )
61         except BootManagerException, e:
62             log.write( "Call to BootNotifyOwners failed: %s.\n" % e )
63
64         if sent == 0:
65             log.write( "Unable to notify site contacts of state change.\n" )
66
67     return 1