Skip to content

Commit

Permalink
Baselined from internal Repository
Browse files Browse the repository at this point in the history
last_commit:836fc84071a3e5afedc737a6a936e81a7c2cc99f
  • Loading branch information
GVE Devnet Admin committed Aug 22, 2023
1 parent 4e88f37 commit d197e30
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
16 changes: 12 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand All @@ -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
Expand Down Expand Up @@ -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":
Expand Down
6 changes: 5 additions & 1 deletion templates/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
<div class="section">
<div class="panel panel--loose panel--raised base-margin-bottom">
<form action="/status" method="POST">
{% if status == "success" %}
<button class="btn btn--primary pull-right" disabled>Refresh Status</button>
{% else %}
<button class="btn btn--primary pull-right">Refresh Status</button>
{% endif %}
</form>

<h2 class="subtitle">Step 5: Deployment</h2>
Expand Down Expand Up @@ -63,7 +67,7 @@ <h2 class="subtitle">Step 5: Deployment</h2>
<div class="form-group base-margin-bottom">

<div class="form-group__text">
<textarea id="textarea-state-disabled" rows="20" disabled=""
<textarea id="textarea-state-disabled" rows="20" readonly=""
style="font: 1.3rem Inconsolata, monospace;">
{{ deployed_config }}
</textarea>
Expand Down

0 comments on commit d197e30

Please sign in to comment.