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