blob: 2faf9defabe31c842463b6bc0d9b7969a2b6e807 [file] [log] [blame]
#!/usr/bin/env python3
# SPDX-FileCopyrightText: © 2021 Open Networking Foundation <support@opennetworking.org>
# SPDX-License-Identifier: Apache-2.0
# edgeconfig.py
# Given a yaml config file (same as ansible inventory for a site), create a
# YAML file consumable by ansible as variables that configures the managmeent
# node for that site
from __future__ import absolute_import
import argparse
import nbhelper
import json
import os
import pprint
from ruamel import yaml
# main function that calls other functions
if __name__ == "__main__":
# this is passed to argparse, key is option name, rest is kwargs
extra_args = {
"base_config": {
"default": os.path.join(
os.path.dirname(os.path.realpath(__file__)), "base_edgeconfig.yaml"
),
"nargs": "?",
"type": argparse.FileType("r"),
"help": "Config (optional, default: base_edgeconfig.yaml)",
},
}
args = nbhelper.initialize(extra_args)
tenant = nbhelper.NBTenant()
# use base_config for additional items
yaml_out = yaml.safe_load(args.base_config.read())
dhcpd_subnets = []
dhcpd_interfaces = []
# reverse zones aggregate across RFC1918 IP prefix
dns_reverse_zones = nbhelper.NBDNSReverseZones()
for prefix in tenant.get_prefixes().values():
nbhelper.NBDNSForwardZone.get_fwd_zone(prefix)
dns_reverse_zones.add_prefix(prefix)
dhcpd_subnet = nbhelper.NBDHCPSubnet(prefix)
dhcpd_if = dhcpd_subnet.dhcpd_interface
if dhcpd_if and dhcpd_if not in dhcpd_interfaces:
dhcpd_interfaces.append(dhcpd_if)
dhcpd_subnets.append(dhcpd_subnet)
# yaml_out["devices"] = nbhelper.NBDevice.all_devs()
yaml_out["netprep_netplan"] = tenant.generate_netplan()
yaml_out["dns_forward_zones"] = nbhelper.NBDNSForwardZone.all_fwd_zones()
yaml_out["dns_reverse_zones"] = dns_reverse_zones
yaml_out["dhcpd_subnets"] = dhcpd_subnets
yaml_out["dhcpd_interfaces"] = dhcpd_interfaces
print(yaml.safe_dump(yaml_out, indent=2))