Refactor generator - allow for multiple types of node (only 'vpp' for now) -- move the vpp overlays into a new 'type'-root; we will read common/ / and / now

This commit is contained in:
Pim van Pelt
2023-05-06 10:57:05 +00:00
parent aa0b042298
commit e9d645cba4
14 changed files with 16 additions and 10 deletions

View File

@ -145,23 +145,27 @@ def prune(output, outdir):
os.rmdir(dn)
def create_node(lab, node_id):
def create_node(lab, node_id, node_type):
v4_base, v4_plen = lab["mgmt"]["ipv4"].split("/")
v6_base, v6_plen = lab["mgmt"]["ipv6"].split("/")
lo4_base = lab["ipv4"].split("/")[0]
lo6_base = lab["ipv6"].split("/")[0]
total_nodes = 0
for node_type, ncount in lab["nodes"].items():
total_nodes += ncount
ret = {
"hostname": "vpp%d-%d" % (lab["id"], node_id),
"hostname": "%s%d-%d" % (node_type, lab["id"], node_id),
"id": node_id,
"mgmt": {
"ipv4": "%s/%s"
% (
ipaddress.IPv4Address(v4_base) + lab["nodes"] * lab["id"] + node_id,
ipaddress.IPv4Address(v4_base) + total_nodes * lab["id"] + node_id,
v4_plen,
),
"ipv6": "%s/%s"
% (
ipaddress.IPv6Address(v6_base) + lab["nodes"] * lab["id"] + node_id,
ipaddress.IPv6Address(v6_base) + total_nodes * lab["id"] + node_id,
v6_plen,
),
"gw4": lab["mgmt"]["gw4"],
@ -240,17 +244,18 @@ def main():
log.error("Overlay not defined, bailing.")
return
for node_id in range(data["lab"]["nodes"]):
log.info("Generating for node %d" % node_id)
data["node"] = create_node(data["lab"], node_id)
for node_type, ncount in data["lab"]["nodes"].items():
for node_id in range(ncount):
log.info("Generating for VPP node %d" % node_id)
data["node"] = create_node(data["lab"], node_id, node_type)
log.debug("node: %s" % data["node"])
# Assemble a dictionary of tpl=>fn
overlay = data["overlays"][args.overlay]
common_root = overlay["path"] + "common/"
type_root = overlay["path"] + node_type + "/"
hostname_root = overlay["path"] + "hostname/" + data["node"]["hostname"] + "/"
files = find([common_root, hostname_root])
files = find([common_root, type_root, hostname_root])
# Assemble a dictionary of fn=>output
build = generate(files, data, args.debug)