for each boot, after the vserver net configuration files ae updated,
[bootmanager.git] / source / steps / GetAndUpdateNodeDetails.py
1 import string
2
3 from Exceptions import *
4 import BootAPI
5
6
7 SKIP_MODEL_STRING= "/minhw"
8
9
10 def Run( vars, log ):
11     """
12     Contact PLC and get the attributes for this node. Also, if the node model
13     string ends in SKIP_MODEL_STRING, override the hardware requirements
14     configuration value, and skip the checks.
15
16     Also, update any node network settings at PLC, minus the ip address,
17     so, upload the mac (if node_id was in conf file), gateway, network,
18     broadcast, netmask, dns1/2, and the hostname/domainname.
19
20     Expect the following keys to be set:
21     BOOT_CD_VERSION          A tuple of the current bootcd version
22     SKIP_HARDWARE_REQUIREMENT_CHECK     Whether or not we should skip hardware
23                                         requirement checks
24                                         
25     The following keys are set/updated:
26     WAS_NODE_ID_IN_CONF      Set to 1 if the node id was in the conf file
27     WAS_NODE_KEY_IN_CONF     Set to 1 if the node key was in the conf file
28     BOOT_STATE               The current node boot state
29     NODE_MODEL               The user specified model of this node
30     NETWORK_SETTINGS         A dictionary of the values of the network settings
31     SKIP_HARDWARE_REQUIREMENT_CHECK     Whether or not we should skip hardware
32                                         requirement checks
33     NODE_SESSION             The session value returned from BootGetNodeDetails
34     
35     Return 1 if able to contact PLC and get node info.
36     Raise a BootManagerException if anything fails.
37     """
38
39     log.write( "\n\nStep: Retrieving details of node from PLC.\n" )
40
41     # make sure we have the variables we need
42     try:
43         BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
44         if BOOT_CD_VERSION == "":
45             raise ValueError, "BOOT_CD_VERSION"
46
47         SKIP_HARDWARE_REQUIREMENT_CHECK= vars["SKIP_HARDWARE_REQUIREMENT_CHECK"]
48         if SKIP_HARDWARE_REQUIREMENT_CHECK == "":
49             raise ValueError, "SKIP_HARDWARE_REQUIREMENT_CHECK"
50
51         NETWORK_SETTINGS= vars["NETWORK_SETTINGS"]
52         if NETWORK_SETTINGS == "":
53             raise ValueError, "NETWORK_SETTINGS"
54
55         WAS_NODE_ID_IN_CONF= vars["WAS_NODE_ID_IN_CONF"]
56         if WAS_NODE_ID_IN_CONF == "":
57             raise ValueError, "WAS_NODE_ID_IN_CONF"
58
59         WAS_NODE_KEY_IN_CONF= vars["WAS_NODE_KEY_IN_CONF"]
60         if WAS_NODE_KEY_IN_CONF == "":
61             raise ValueError, "WAS_NODE_KEY_IN_CONF"
62
63     except KeyError, var:
64         raise BootManagerException, "Missing variable in vars: %s\n" % var
65     except ValueError, var:
66         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
67
68
69     details= BootAPI.call_api_function( vars, "BootGetNodeDetails", () )
70
71     vars['BOOT_STATE']= details['boot_state']
72     vars['NODE_MODEL']= string.strip(details['model'])
73     vars['NODE_SESSION']= details['session']
74     
75     log.write( "Successfully retrieved node record.\n" )
76     log.write( "Current boot state: %s\n" % vars['BOOT_STATE'] )
77     log.write( "Node make/model: %s\n" % vars['NODE_MODEL'] )
78     
79     # if the end of NODE_MODEL string ends in SKIP_MODEL_STRING, skip hardware
80     # requirement checks (overrides configuration)
81     model= vars['NODE_MODEL']
82     len_skip_str= len(SKIP_MODEL_STRING)
83     if model[-len_skip_str:] == SKIP_MODEL_STRING:
84         vars['SKIP_HARDWARE_REQUIREMENT_CHECK']= 1
85         log.write( "node model indicates override to hardware requirements.\n" )
86         
87
88     # this contains all the node networks, for now, we are only concerned
89     # in the primary network
90     node_networks= details['networks']
91     got_primary= 0
92     for network in node_networks:
93         if network['is_primary'] == 1:
94             got_primary= 1
95             break
96
97     if not got_primary:
98         raise BootManagerException, "Node did not have a primary network."
99     
100     log.write( "Primary network as returned from PLC: %s\n" % str(network) )
101
102     # if we got this far, the ip on the floppy and the ip in plc match,
103     # make the rest of the PLC information match whats on the floppy
104     network['method']= NETWORK_SETTINGS['method']
105
106     # only nodes that have the node_id specified directly in the configuration
107     # file can change their mac address
108     if WAS_NODE_ID_IN_CONF == 1:
109         network['mac']= NETWORK_SETTINGS['mac']
110         
111     network['gateway']= NETWORK_SETTINGS['gateway']
112     network['network']= NETWORK_SETTINGS['network']
113     network['broadcast']= NETWORK_SETTINGS['broadcast']
114     network['netmask']= NETWORK_SETTINGS['netmask']
115     network['dns1']= NETWORK_SETTINGS['dns1']
116     network['dns2']= NETWORK_SETTINGS['dns2']
117     
118     log.write( "Updating network settings at PLC to match floppy " \
119                "(except for node ip).\n" )
120     update_vals= {}
121     update_vals['primary_network']= network
122     BootAPI.call_api_function( vars, "BootUpdateNode", (update_vals,) )
123     
124     return 1