From d197e30051343f1a65f1884f04df5693474bf64c Mon Sep 17 00:00:00 2001 From: GVE Devnet Admin Date: Tue, 22 Aug 2023 18:46:19 +0000 Subject: [PATCH] Baselined from internal Repository last_commit:836fc84071a3e5afedc737a6a936e81a7c2cc99f --- README.md | 2 ++ app.py | 16 ++++++++++++---- templates/status.html | 6 +++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2fc0dd3..64d3bd3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # DNA Center - VLAN / Port provisioning +[![published](https://static.production.devnetcloud.com/codeexchange/assets/images/devnet-published.svg)](https://developer.cisco.com/codeexchange/github/repo/gve-sw/gve_devnet_dnac_vlan_provisioning) + This repository contains sample code for deploying interface VLAN configuration to Cisco DNA Center via a simplified web interface. This allows someone to create new VLANs & assign them to switch interfaces, without needing to access DNA center or have knowledge of the underlying device configuration. The web application walks through the following workflow: diff --git a/app.py b/app.py index 193f325..14462ce 100644 --- a/app.py +++ b/app.py @@ -23,6 +23,7 @@ from time import sleep import re from dnacentersdk import api +from dnacentersdk.exceptions import ApiError from flask_session import Session from dotenv import load_dotenv import os @@ -414,6 +415,7 @@ def getTemplateID() -> None: project = dnac.configuration_templates.get_projects( name=dnac_config["templates"]["project"] ) + template_id = None for template in project[0]["templates"]: if template["name"] == ( dnac_config["templates"]["template"] + "-" + session["author"] @@ -422,7 +424,6 @@ def getTemplateID() -> None: app.logger.info(f"Found Template ID: {template_id}") break else: - template_id = None app.logger.info("No template ID found") # Store template ID session["templateID"] = template_id @@ -567,9 +568,16 @@ def getTemplateDeployStatus() -> None: dnac = getDNACSession() # Ask DNAC for currernt status of template deployment - response = dnac.configuration_templates.get_template_deployment_status( - deployment_id=session["deploy_id"] - ) + try: + response = dnac.configuration_templates.get_template_deployment_status( + deployment_id=session["deploy_id"] + ) + except ApiError as e: + # Some times DNAC will give 500 while querying status + app.logger.info("Error checking deployment status:") + app.logger.info(e) + return + app.logger.info(f"Deployment status: {response['status']}") # Check to see if deployment was successful, failed, or still in progress if response["status"] == "SUCCESS": diff --git a/templates/status.html b/templates/status.html index ef4809b..b2bf838 100644 --- a/templates/status.html +++ b/templates/status.html @@ -35,7 +35,11 @@
+ {% if status == "success" %} + + {% else %} + {% endif %}

Step 5: Deployment

@@ -63,7 +67,7 @@

Step 5: Deployment

-