#!/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 os

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))
