Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions generate_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys

DEVICEMAP_PATH = pathlib.Path("./") / "devicemaps.json"
TEMPLATE_SKU_PATH = pathlib.Path("./") / "template-skus.txt"
TEMPLATE_DIR = pathlib.Path("./templates")
IMG_DIR = pathlib.Path("./img")
LTE_HELP_TIP = "LTE is available on your platform."
Expand Down Expand Up @@ -205,26 +206,31 @@


def main():
template_skus = TEMPLATE_SKU_PATH.read_text().splitlines()

interfacemap = json.loads(DEVICEMAP_PATH.read_text())

models = set()

for template_sku in template_skus:
vendor, sku = template_sku.split(maxsplit=1)
devicemap = interfacemap["interfaceMap"][vendor][sku]
actual_devicemap = resolve_alias(devicemap, interfacemap)

for vendor, skus in interfacemap["interfaceMap"].items():
models = set()
for sku, devicemap in skus.items():
actual_devicemap = resolve_alias(devicemap, interfacemap)
if not actual_devicemap:
continue
if not actual_devicemap:
continue

model = devicemap.get("displayModel", sku)
model = devicemap.get("displayModel", sku)

# make sure models are unique per vendor
if model in models:
print(f"Vendor {vendor} has duplicate model {model}")
sys.exit(1)
# make sure models are unique per vendor
if model in models:
print(f"Vendor {vendor} has duplicate model {model}")
sys.exit(1)

models.add(model)
models.add(model)

template = generate_template(vendor, model, actual_devicemap)
write_template(vendor, model, template)
template = generate_template(vendor, model, actual_devicemap)
write_template(vendor, model, template)

def generate_template(vendor, model, devicemap):
description_suffix = ""
Expand All @@ -239,12 +245,12 @@ def generate_template(vendor, model, devicemap):
"builtin": True,
"mode": "advanced",
"help": format_help_msg(vendor, model, bool(devicemap.get("lte"))),
"body": f"{{% editgroup %}}\n\n{json.dumps(generate_body(devicemap), indent=2)}",
"body": f"{{% editgroup %}}\n\n{json.dumps(generate_body(devicemap, model), indent=2)}",
"schema": generate_schema(vendor, model, devicemap)
}


def generate_body(devicemap):
def generate_body(devicemap, model):
device_interfaces = []
for index, lte_interface in enumerate(devicemap.get("lte", [])):
device_interfaces.append(
Expand Down Expand Up @@ -275,7 +281,11 @@ def generate_body(devicemap):
for index, dev_intf in enumerate(devicemap["ethernet"]):
if dev_intf["type"] in ["MGMT", "SWITCH_PARENT"]:
continue
if dev_intf["type"] == "HASync" and "macIndex" in dev_intf:
continue
intf = {"pciAddress": dev_intf["pciAddress"]} if dev_intf.get("pciAddress") else {}
if dev_intf.get("parent"):
intf["interfaceName"] = dev_intf["name"]
intf.update({
"description": dev_intf["description"],
"enabled": "true",
Expand All @@ -285,7 +295,7 @@ def generate_body(devicemap):
if dev_intf["type"] == "WAN":
intf["networkInterface"] = [
{
"name": dev_intf.get("bcpNetwork", {}).get("standaloneBranch", {}).get("name", f"{dev_intf['name']} Network Interface"),
"name": dev_intf.get("bcpNetwork", {}).get("standaloneBranch", {}).get("name", f"{dev_intf['name']}"),
"description": dev_intf.get("bcpNetwork", {}).get("standaloneBranch", {}).get("description", ""),
"sourceNat": "true",
"dhcp": "v4",
Expand All @@ -302,7 +312,7 @@ def generate_body(devicemap):
else:
intf["networkInterface"] = [
{
"name": dev_intf.get("bcpNetwork", {}).get("standaloneBranch", {}).get("name", f"{dev_intf['name']} Network Interface"),
"name": dev_intf.get("bcpNetwork", {}).get("standaloneBranch", {}).get("name", f"{dev_intf['name']}"),
"description": dev_intf.get("bcpNetwork", {}).get("standaloneBranch", {}).get("description", ""),
"address": [
{
Expand Down Expand Up @@ -347,6 +357,9 @@ def generate_body(devicemap):

body["authority"]["router"][0]["_value"]["node"][0]["deviceInterface"] = device_interfaces

if devicemap.get("platformCapabilities"):
body["authority"]["router"][0]["_value"]["node"][0]["platformType"] = model

return body


Expand Down Expand Up @@ -396,6 +409,8 @@ def generate_schema(vendor, model, devicemap):
def generate_port_schema(devicemap):
properties = {}
for port in devicemap["ethernet"] + devicemap.get("lte", []):
if port["type"] in ["SWITCH_PARENT"]:
continue
if port["type"] in ["MGMT", "WAN", "LTE"]:
simplified_type = port["type"]
else:
Expand Down
18 changes: 18 additions & 0 deletions template-skus.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flag at the top level for a sku for which to skip? Rather than maintaining two lists

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this. Didn't do it because these templates aren't used by anything in the hwb or devicemap

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Juniper SSR120
Juniper SSR120-AE
Juniper SSR130
Juniper SSR130-AE
Juniper SSR1200
Juniper SSR1300
Juniper SSR1400
Juniper SSR1500
Juniper SSR400
Juniper SSR400-C
Juniper SSR440
Juniper SSR440-C
Lanner NCA-1515
Lenovo 7Z73CTO1WW
Silicom 90500-0151-
Silicom 90500-0151-G11
Silicom 90500-0151-G53
Silicom 90500-0151-G71
7 changes: 1 addition & 6 deletions templates/Juniper-SSR400-C-template.json

Large diffs are not rendered by default.

169 changes: 0 additions & 169 deletions templates/Juniper-SSR400-CW-US-template.json

This file was deleted.

234 changes: 0 additions & 234 deletions templates/Juniper-SSR400-W-US-template.json

This file was deleted.

7 changes: 1 addition & 6 deletions templates/Juniper-SSR400-template.json

Large diffs are not rendered by default.