Detangled steps. No step makes calls into another step.
[bootmanager.git] / source / steps / GetAndUpdateNodeDetails.py
1 #!/usr/bin/python2
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     BOOT_CD_VERSION          A tuple of the current bootcd version
27     SKIP_HARDWARE_REQUIREMENT_CHECK     Whether or not we should skip hardware
28                                         requirement checks
29                                         
30     The following keys are set/updated:
31     WAS_NODE_ID_IN_CONF      Set to 1 if the node id was in the conf file
32     WAS_NODE_KEY_IN_CONF     Set to 1 if the node key was in the conf file
33     BOOT_STATE               The current node boot state
34     NODE_MODEL               The user specified model of this node
35     NODE_MODEL_OPTIONS       The options extracted from the user specified
36                              model of this node 
37     NETWORK_SETTINGS         A dictionary of the values of the network settings
38     SKIP_HARDWARE_REQUIREMENT_CHECK     Whether or not we should skip hardware
39                                         requirement checks
40     NODE_SESSION             The session value returned from BootGetNodeDetails
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         BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
51         if BOOT_CD_VERSION == "":
52             raise ValueError, "BOOT_CD_VERSION"
53
54         SKIP_HARDWARE_REQUIREMENT_CHECK= vars["SKIP_HARDWARE_REQUIREMENT_CHECK"]
55         if SKIP_HARDWARE_REQUIREMENT_CHECK == "":
56             raise ValueError, "SKIP_HARDWARE_REQUIREMENT_CHECK"
57
58         NETWORK_SETTINGS= vars["NETWORK_SETTINGS"]
59         if NETWORK_SETTINGS == "":
60             raise ValueError, "NETWORK_SETTINGS"
61
62         WAS_NODE_ID_IN_CONF= vars["WAS_NODE_ID_IN_CONF"]
63         if WAS_NODE_ID_IN_CONF == "":
64             raise ValueError, "WAS_NODE_ID_IN_CONF"
65
66         WAS_NODE_KEY_IN_CONF= vars["WAS_NODE_KEY_IN_CONF"]
67         if WAS_NODE_KEY_IN_CONF == "":
68             raise ValueError, "WAS_NODE_KEY_IN_CONF"
69
70     except KeyError, var:
71         raise BootManagerException, "Missing variable in vars: %s\n" % var
72     except ValueError, var:
73         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
74
75     details= BootAPI.call_api_function( vars, "BootGetNodeDetails", () )
76
77     vars['BOOT_STATE']= details['boot_state']
78     vars['NODE_MODEL']= string.strip(details['model'])
79     vars['NODE_SESSION']= details['session']
80     
81     log.write( "Successfully retrieved node record.\n" )
82     log.write( "Current boot state: %s\n" % vars['BOOT_STATE'] )
83     log.write( "Node make/model: %s\n" % vars['NODE_MODEL'] )
84     
85     # parse in the model options from the node_model string
86     model= vars['NODE_MODEL']
87     options= ModelOptions.Get(model)
88     vars['NODE_MODEL_OPTIONS']=options
89
90     # Check if we should skip hardware requirement check
91     if options & ModelOptions.MINHW:
92         vars['SKIP_HARDWARE_REQUIREMENT_CHECK']=1
93         log.write( "node model indicates override to hardware requirements.\n" )
94
95     # this contains all the node networks, for now, we are only concerned
96     # in the primary network
97     node_networks= details['networks']
98     got_primary= 0
99     for network in node_networks:
100         if network['is_primary'] == 1:
101             got_primary= 1
102             break
103
104     if not got_primary:
105         raise BootManagerException, "Node did not have a primary network."
106     
107     log.write( "Primary network as returned from PLC: %s\n" % str(network) )
108
109     # if we got this far, the ip on the floppy and the ip in plc match,
110     # make the rest of the PLC information match whats on the floppy
111     network['method']= NETWORK_SETTINGS['method']
112
113     # only nodes that have the node_id specified directly in the configuration
114     # file can change their mac address
115     if WAS_NODE_ID_IN_CONF == 1:
116         network['mac']= NETWORK_SETTINGS['mac']
117         
118     network['gateway']= NETWORK_SETTINGS['gateway']
119     network['network']= NETWORK_SETTINGS['network']
120     network['broadcast']= NETWORK_SETTINGS['broadcast']
121     network['netmask']= NETWORK_SETTINGS['netmask']
122     network['dns1']= NETWORK_SETTINGS['dns1']
123     network['dns2']= NETWORK_SETTINGS['dns2']
124     
125     log.write( "Updating network settings at PLC to match floppy " \
126                "(except for node ip).\n" )
127     update_vals= {}
128     update_vals['primary_network']= network
129     BootAPI.call_api_function( vars, "BootUpdateNode", (update_vals,) )
130     
131     return 1