-opyright (c) 2018 AT&T Intellectual Property. All rights reserved. #
+
+##############################################################################
+# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. #
env = jinja2.Environment()
env.trim_blocks = True
env.lstrip_blocks = True
-
+
with open(j2template) as fd:
template = env.from_string(fd.read())
-
+
if type(nodes) is list:
for node in nodes:
newnode = dict( defaults.items() + node.items() )
+ if not "bios_template" in newnode or not newnode["bios_template"]:
+ print 'Skipping host {} because of missing or empty key [bios_template]'.format(newnode['name'])
+ continue
data = template.render(yaml=newnode)
rcfile = "server-config/"+newnode['name']+rcfile_suffix
print rcfile
if newnode['vendor'] == "HP" or newnode['vendor'] == "HPE":
command = '/opt/akraino/redfish/apply_hpejson.sh --rc {0} --template {1} --no-confirm'.format(rcfile, newnode["bios_template"])
if command:
- print 'command: {0}'.format(command)
- os.system(command)
+ p=subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True, preexec_fn=os.setsid)
+ print 'process: {} command: {}'.format(p.pid, command)
+ plist.append(p)
### MAIN ###
if len(sys.argv) != 2:
with open(sys.argv[1]) as f:
siteyaml = yaml.safe_load(f)
+# list of background processes created
+plist = []
+
# create set of defaults based on top level ipmi_admin and hardware key/value pairs
defaults = dict( siteyaml["ipmi_admin"].items() + siteyaml["hardware"].items() )
# add keys for backward compatibility
defaults = dict( [('oob_user',siteyaml['ipmi_admin']['username'])] + defaults.items())
defaults = dict( [('oob_password',siteyaml['ipmi_admin']['password'])] + defaults.items())
-defaults = dict( [('oem',siteyaml['hardware']['vendor'])] + defaults.items())
print 'Using defaults:'
for line in yaml.dump(defaults,default_flow_style=False).split('\n'):
if 'workers' in siteyaml:
create_node_rcfile(siteyaml["workers"], defaults, "tools/j2/serverrc_raid.j2", "rc.raid")
+# print output from background processes
+for p in plist:
+ print "waiting for process {}".format(p.pid)
+ exitcode=p.wait()
+ print 'Process {0} ended with exit code {1}'.format(p.pid, p.returncode)
+ print p.communicate()[0]
+