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:
@ -19,4 +19,5 @@ lab:
|
||||
gw6: 2001:678:d78:50b::1
|
||||
nameserver:
|
||||
search: [ "lab.ipng.ch", "net.ipng.ch", "ipng.ch" ]
|
||||
nodes: 4
|
||||
nodes:
|
||||
vpp: 4
|
||||
|
23
generate
23
generate
@ -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)
|
||||
|
Reference in New Issue
Block a user