1 ##############################################################################
2 # Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5 # not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
8 # http://www.apache.org/licenses/LICENSE-2.0 #
10 # Unless required by applicable law or agreed to in writing, software #
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT #
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13 # See the License for the specific language governing permissions and #
14 # limitations under the License. #
15 ##############################################################################
23 def create_node_rcfile(nodes, defaults, j2template, rcfile_suffix):
24 env = jinja2.Environment()
25 env.trim_blocks = True
26 env.lstrip_blocks = True
28 with open(j2template) as fd:
29 template = env.from_string(fd.read())
31 if type(nodes) is list:
33 newnode = dict( defaults.items() + node.items() )
34 data = template.render(yaml=newnode)
35 rcfile = "server-config/"+newnode['name']+rcfile_suffix
37 if os.path.exists(rcfile):
38 print 'warning: rc file {} exists. maynot be new node. overwriting file'.format(rcfile)
40 if not os.path.exists(os.path.dirname(rcfile)):
41 os.makedirs(os.path.dirname(rcfile),0600)
42 fd2 = open(rcfile,'w')
46 print '{0} -> {1}'.format(j2template, rcfile)
48 if newnode['vendor'] == "DELL":
49 command = '/opt/akraino/redfish/apply_dellxml.sh --rc {0} --template {1} --no-confirm'.format(rcfile, newnode["bios_template"])
50 if newnode['vendor'] == "HP" or newnode['vendor'] == "HPE":
51 command = '/opt/akraino/redfish/apply_hpejson.sh --rc {0} --template {1} --no-confirm'.format(rcfile, newnode["bios_template"])
53 print 'command: {0}'.format(command)
57 if len(sys.argv) != 2:
58 print 'usage: update_bios_settings.py <yaml>'
61 with open(sys.argv[1]) as f:
62 siteyaml = yaml.safe_load(f)
64 # create set of defaults based on top level ipmi_admin and hardware key/value pairs
65 defaults = dict( siteyaml["ipmi_admin"].items() + siteyaml["hardware"].items() )
67 # add keys for backward compatibility
68 defaults = dict( [('oob_user',siteyaml['ipmi_admin']['username'])] + defaults.items())
69 defaults = dict( [('oob_password',siteyaml['ipmi_admin']['password'])] + defaults.items())
70 defaults = dict( [('oem',siteyaml['hardware']['vendor'])] + defaults.items())
72 print 'Using defaults:'
73 for line in yaml.dump(defaults,default_flow_style=False).split('\n'):
74 print ' {}'.format(line)
76 if 'masters' in siteyaml:
77 create_node_rcfile(siteyaml["masters"], defaults, "tools/j2/serverrc_raid.j2", "rc.raid")
79 if 'workers' in siteyaml:
80 create_node_rcfile(siteyaml["workers"], defaults, "tools/j2/serverrc_raid.j2", "rc.raid")