#!/usr/bin/python3
# This script is used to generate the ztp templates for each of the deployment
# groups, which will have their own set of resources that need to be generated
# and/or copied across to the remote nodes, depending on the resource group.
import sys
import central_dop.config
import central_dop.ztp

def main ():
    print ("Preparing ZTP resources.")

    deploy_dir = "/srv/deploy"
    config = central_dop.config.load_config_file()
    try:
        central_dop.config.validate_config(config)
    except central_dop.config.Error as err:
        print ("error loading configuration: {}".format(err.message))
        sys.exit(1)

    try:
        central_dop.ztp.generate_ztp_resources(deploy_dir, config)
    except central_dop.config.Error as err:
        print ("error generating ZTP configuration: {}".format(err.message))

    print ("Done.")

if __name__ == "__main__":
    main()
