svn:keywords
[bootmanager.git] / source / steps / GetAndUpdateNodeDetails.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 import string
13
14 from Exceptions import *
15 import BootAPI
16 import ModelOptions
17
18 def Run( vars, log ):
19     """
20
21     Contact PLC and get the attributes for this node. Also, parse in
22     options from the node model strong.
23
24     Also, update any node network settings at PLC, minus the ip address,
25     so, upload the mac (if node_id was in conf file), gateway, network,
26     broadcast, netmask, dns1/2, and the hostname/domainname.
27
28     Expect the following keys to be set:
29     SKIP_HARDWARE_REQUIREMENT_CHECK     Whether or not we should skip hardware
30                                         requirement checks
31                                         
32     The following keys are set/updated:
33     WAS_NODE_ID_IN_CONF                 Set to 1 if the node id was in the conf file
34     WAS_NODE_KEY_IN_CONF                Set to 1 if the node key was in the conf file
35     BOOT_STATE                          The current node boot state
36     NODE_MODEL                          The user specified model of this node
37     NODE_MODEL_OPTIONS                  The options extracted from the user specified
38                                                 model of this node 
39     SKIP_HARDWARE_REQUIREMENT_CHECK     Whether or not we should skip hardware
40                                                 requirement checks
41     NODE_SESSION                        The session value returned from BootGetNodeDetails
42     INTERFACES                          The network interfaces associated with this node
43     INTERFACE_SETTINGS                  A dictionary of the values of the interface settings
44     
45     Return 1 if able to contact PLC and get node info.
46     Raise a BootManagerException if anything fails.
47     """
48
49     log.write( "\n\nStep: Retrieving details of node from PLC.\n" )
50
51     # make sure we have the variables we need
52     try:
53         SKIP_HARDWARE_REQUIREMENT_CHECK= vars["SKIP_HARDWARE_REQUIREMENT_CHECK"]
54         if SKIP_HARDWARE_REQUIREMENT_CHECK == "":
55             raise ValueError, "SKIP_HARDWARE_REQUIREMENT_CHECK"
56
57         INTERFACE_SETTINGS= vars["INTERFACE_SETTINGS"]
58         if INTERFACE_SETTINGS == "":
59             raise ValueError, "INTERFACE_SETTINGS"
60
61         WAS_NODE_ID_IN_CONF= vars["WAS_NODE_ID_IN_CONF"]
62         if WAS_NODE_ID_IN_CONF == "":
63             raise ValueError, "WAS_NODE_ID_IN_CONF"
64
65         WAS_NODE_KEY_IN_CONF= vars["WAS_NODE_KEY_IN_CONF"]
66         if WAS_NODE_KEY_IN_CONF == "":
67             raise ValueError, "WAS_NODE_KEY_IN_CONF"
68
69     except KeyError, var:
70         raise BootManagerException, "Missing variable in vars: %s\n" % var
71     except ValueError, var:
72         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
73
74     node_details= BootAPI.call_api_function( vars, "GetNodes", 
75                                              (vars['NODE_ID'], 
76                                               ['boot_state', 'nodegroup_ids', 'interface_ids', 'model', 'site_id']))[0]
77
78     vars['BOOT_STATE']= node_details['boot_state']
79     vars['RUN_LEVEL']= node_details['boot_state']
80     vars['NODE_MODEL']= string.strip(node_details['model'])
81     vars['SITE_ID'] = node_details['site_id'] 
82     log.write( "Successfully retrieved node record.\n" )
83     log.write( "Current boot state: %s\n" % vars['BOOT_STATE'] )
84     log.write( "Node make/model: %s\n" % vars['NODE_MODEL'] )
85     
86     # parse in the model options from the node_model string
87     model= vars['NODE_MODEL']
88     options= ModelOptions.Get(model)
89     vars['NODE_MODEL_OPTIONS']=options
90
91     # Check if we should skip hardware requirement check
92     if options & ModelOptions.MINHW:
93         vars['SKIP_HARDWARE_REQUIREMENT_CHECK']=1
94         log.write( "node model indicates override to hardware requirements.\n" )
95
96     # this contains all the node networks, for now, we are only concerned
97     # in the primary network
98     interfaces= BootAPI.call_api_function( vars, "GetInterfaces", (node_details['interface_ids'],))
99     got_primary= 0
100     for network in interfaces:
101         if network['is_primary'] == 1:
102             log.write( "Primary network as returned from PLC: %s\n" % str(network) )
103             got_primary= 1
104             break
105
106     if not got_primary:
107         raise BootManagerException, "Node did not have a primary network."
108
109     vars['INTERFACES']= interfaces
110     
111     return 1