svn:keywords
[bootmanager.git] / source / steps / UpdateRunLevelWithPLC.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 run level at PLC.
20
21     Replaces the behavior of UpdateBootStateWithPLC.  Where previously, the
22     boot_state of a node would be altered by the BM, now the run_level is
23     updated, and the boot_state is preserved as a record of a User's
24     preference.
25
26     The current value of the RUN_LEVEL key in vars is used.
27     Optionally, notify the contacts of the run level change.
28     If this is the case, the following keys/values
29     should be set in vars before calling this step:
30     STATE_CHANGE_NOTIFY= 1
31     STATE_CHANGE_NOTIFY_MESSAGE= "<notify message>"
32     The second value is a message to send the users from notify_messages.py
33
34     Return 1 if succesfull, a BootManagerException otherwise.
35     """
36
37     log.write( "\n\nStep: Updating node run level at PLC.\n" )
38
39     update_vals= {}
40     # translate boot_state values to run_level value
41     if vars['RUN_LEVEL'] in ['diag', 'diagnose', 'disabled', 'disable']:
42         vars['RUN_LEVEL']='safeboot'
43     update_vals['run_level']=vars['RUN_LEVEL']
44     try:
45         BootAPI.call_api_function( vars, "ReportRunlevel", (update_vals,) )
46         log.write( "Successfully updated run level for this node at PLC\n" )
47     except BootManagerException, e:
48         log.write( "Unable to update run level for this node at PLC: %s.\n" % e )
49
50     notify = vars.get("STATE_CHANGE_NOTIFY",0)
51
52     if notify:
53         message= vars['STATE_CHANGE_NOTIFY_MESSAGE']
54         include_pis= 0
55         include_techs= 1
56         include_support= 0
57
58         sent= 0
59         try:
60             sent= BootAPI.call_api_function( vars, "BootNotifyOwners",
61                                              (message,
62                                               include_pis,
63                                               include_techs,
64                                               include_support) )
65         except BootManagerException, e:
66             log.write( "Call to BootNotifyOwners failed: %s.\n" % e )
67
68         if sent == 0:
69             log.write( "Unable to notify site contacts of state change.\n" )
70
71     return 1