Futher flesh out the generator
- Create a per-host directory called overlays/$(overlay)/hostname/$(host.hostname) to have files that ought to be included only for that host. Things like /etc/vpp/config/interface.vpp go there - Rename the "templates" directory as overlays/$(overlay)/common/ - Render one after the other, so a file can exist in common and hostname, the latter taking precedence - Remove the config for 'pubkeys' and instead just make these common/root/.ssh/* and common/home/ipng/.ssh/* - Split out bootstrap.vpp so that a per-host include can be overriden for interfaces.vpp - But keep a default common/etc/vpp/config/interface.vpp as a placeholder, so that VPP will still start even if the per-hostname override isn't provided. - Generate a fresh output for 'default' on all machines
This commit is contained in:
18
generate
18
generate
@ -72,7 +72,7 @@ def tpl2fn(tpl, prefix):
|
||||
|
||||
|
||||
def find(file_or_dir_list):
|
||||
log.info("Finding templates in %s" % file_or_dir_list)
|
||||
log.info("Finding files in %s" % file_or_dir_list)
|
||||
ret = {}
|
||||
for e in file_or_dir_list:
|
||||
if e.startswith("_"):
|
||||
@ -91,9 +91,9 @@ def find(file_or_dir_list):
|
||||
return ret
|
||||
|
||||
|
||||
def generate(templates, data, debug=False):
|
||||
def generate(files, data, debug=False):
|
||||
output = {}
|
||||
for tpl, fn in templates.items():
|
||||
for tpl, fn in files.items():
|
||||
log.info("Rendering %s into %s" % (tpl, fn))
|
||||
try:
|
||||
output[fn] = render(tpl, data)
|
||||
@ -240,18 +240,20 @@ def main():
|
||||
log.error("Overlay not defined, bailing.")
|
||||
return
|
||||
|
||||
# Assemble a dictionary of tpl=>fn
|
||||
overlay = data["overlays"][args.overlay]
|
||||
template_root = overlay["path"] + "templates/"
|
||||
templates = find([template_root])
|
||||
|
||||
for node_id in range(data["lab"]["nodes"]):
|
||||
log.info("Generating for node %d" % node_id)
|
||||
data["node"] = create_node(data["lab"], node_id)
|
||||
log.debug("node: %s" % data["node"])
|
||||
|
||||
# Assemble a dictionary of tpl=>fn
|
||||
overlay = data["overlays"][args.overlay]
|
||||
common_root = overlay["path"] + "common/"
|
||||
hostname_root = overlay["path"] + "hostname/" + data["node"]["hostname"] + "/"
|
||||
files = find([common_root, hostname_root])
|
||||
|
||||
# Assemble a dictionary of fn=>output
|
||||
build = generate(templates, data, args.debug)
|
||||
build = generate(files, data, args.debug)
|
||||
if not build:
|
||||
return
|
||||
|
||||
|
Reference in New Issue
Block a user