artofrf.com

Ali's Technology Blog

Menu
  • Home
  • Important Links
  • About Me
  • Tools and Scripts
Menu

Mist – Importing Site Switch Config Template

Posted on January 5, 2024January 5, 2024 by mali

Before I get to the main topic, I want to discuss the Switch Template/Configuration hierarchy. Mist Wired Assurance configuration hierarchy is as follows:

Mist Wired Assurance – Switch Templates

Org: Switch Template:

As the name suggest, these templates get created at an Organization level and can be applied to all the sites.

Mist Wired Assurance

Site: Switch Template:

Site: Switch Template, can inherit all the settings from the Org: Switch Template, but they do not have to. Additionally, even if they are inheriting configuration from an Org: Switch Template there are override options to customize the configuration for a site. For example, Site: Switch Template inherits NTP, DNS, RADIUS settings from the Org: Switch Template but customized site specific VLANs.

Mist Wired Assurance – Site Switch Template

Device: Switch Configuration:

Device: Switch Configuration happens at a device level. Generally, a device will inherit configuration from Org: Switch Template and/or Site: Switch Template. However, configuration can be customized for a specific device. For example, if two devices are inheriting “ge-0/0/0 – ge-0/0/9” in VLAN30, but you want “ge-0/0/0” and “ge-0/0/1” to be in VLAN20 in one of the switches, you can customize that at a device level.

Mist Wired Assurance – Device Configurations

What happens if you need to create multiple templates? I’m not a fan of creating everything from scratch every time, takes to much time and if you are working with a large project/org and multiple templates, it will end up consuming plenty of time. Luckily, Mist allows few different options:

  • Export an existing Org: Switch Template (as a json file), make adjustments to it and import it back.
  • Clone an existing Org: Switch Template and then make adjustments to it.
  • Use APIs to download it as a json file (NOTE: this process can be automated in different ways)
    • Convert it to YAML and push it back to the cloud. Everytime you need to make changes you can make changes to the YAML file and push it back out.
    • Or simply edit the json file and push it back out to the cloud, or import it.
  • Use a Site: Switch Template to create another Org: Switch Template

What about the the Site: Switch Templates:

Unlike, Org: Switch Templates, Site: Switch Template does not have an option to import a template, it only allows you to create another Org: Switch Template using the Site: Switch Template settings.

Mist Wired Assurance – Site Switch Template

If I have multiple sites and I’m configuring all the VLANs (possibly adding or subtracting) and some port profile configurations at a site level and not org level. I will need to configure all that manually for each site; this process can be cumbersome. Recently I had to work with a similar scenario which lead me to creating this quick script to import settings into my Site: Switch Template.

Success Criteria (New Site):

  • Import VLANs into a Site: Switch Template
  • Import port profiles into a Site: Switch Template
  • Import any other Site Specific configuration
  • Apply Org: Switch Template if needed

Import Template:

First I exported this template named, “import_template” as a json file.

This is a snippet of the “json” file I downloaded. I removed the VLAN I did not want to import into my new site.

Here is the the new Site: Switch Template with blank configuration:

Mist Wired Assurance – Site: Switch Template

Run Script:

Two things are needed to run this script:

  • Site ID
  • Org: Switch Template ID
    • This can be retrieved either from the UI as shown below or APIs
Mist Site ID
Mist Org Switch Template ID

I have all the information now, time to push out the config to the new Site: Switch Template.

Mist Site: Switch Template Import

Now if I look at the Site: Switch Template, I can see that it has all the VLANs, Port Profiles and Org: Switch Template applied.

Mist Site: Switch Template Import

Script:

# This script can also update the site level template and can be customized for the changes
# Important thing to remember is that when doing a PUT there is no merge.  You have to send the whole config
import yaml
import json
import requests
from pprint import pprint as pp
import time
from common.auth import read_yaml_mist
arf_mist_apikey = read_yaml_mist()

site_id = input('Enter Site ID: ')

def configure_site():
    with open ('import_template.json', 'r') as f:
        data = json.load(f)
    url = f'https://api.mist.com/api/v1/sites/{site_id}/setting'
    payload = json.dumps(data)
    #pp(payload)
    headers = {
        'Content-Type': 'application/json',
        'Authorization': arf_mist_apikey
    }
    results = requests.put(url, headers=headers, data=payload)
    #site_template = results.json()
    #pp(site_template)

def apply_netw_template():
    template_question = input('Enter Y if you want to apply an Org Switch Template, otherwise N: ')
    if template_question == 'Y':
        url = f'https://api.mist.com/api/v1/sites/{site_id}'
        netw_temp_id = input('Enter Network Template ID: ')
        data = {'networktemplate_id': netw_temp_id}
        payload = json.dumps(data)
        # pp(payload)
        headers = {
            'Content-Type': 'application/json',
            'Authorization': arf_mist_apikey
        }
        results = requests.put(url, headers=headers, data=payload)
        site_template = results.json()
        pp(site_template)
    elif template_question == 'N':
         print('Script Complete')
    else:
        raise ValueError("Value must be Y or N")

if __name__ == "__main__":
    configure_site()
    apply_netw_template()

Further automation can be added to it, technically I have also pushed out a full site config using a similar method. One very important thing I found out early on was that there is no “merge” option, whatever I push out will override what is in there, I created and used this script for a brand new site with no settings configured in there yet. If there is existing configuration there will be a totally different process. Feel free to share your feedback, would love to get your thoughts if you use Mist and do something similar.

NOTE: All config/script samples are from my lab environment use them at your risk. They are provided as is without any warranty, assurance. Always test configurations, settings etc in a non production environment before using it in production.

Category: Juniper Switching, Juniper/Mist, Programming/Automation, Python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • CLI to UI – Nile Guest APIs
  • Nile Secure Guest – Configuration and Use Case
  • WLAN Pros Toolbox
  • Nile does NAC – Configuring Trust Engine
  • WLAN Validator

Tags

#MFD9 - Juniper Presents AP W318 arista Arista AGNI Arista CV-CUE Arista Hospitality AP Arista NAC Arista presents at MFD9 Arista wall plate AP Arista WIPS Arista WPA3 UPSK Aruba Central Automation CWAP 403 EAP Format MAC Addresses Hamina Network Planner Juniper Mist show cloud-native NAC Juniper SRX300 Marvis MFD8 MFD9 MistAI Mist MPSK Mist Premium Analytics Mist Wireless NaaS Networking Field Day NFD32 Nile APIs NileNav Nile Secure Nile Wi-Fi Tech Field Day Troubleshooting with Marvis Troubleshooting with Mist Troubleshooting with Mist AI Troubleshooting with Wireshark True NaaS Wireless Adjuster Wireless Adjuster Level II Wireless troubleshooting WLPC wlpc2023 Wyebot

Tech Blogs

  • CCNA Wireless
  • Cisco Full Bars
  • Packet Life
  • The ASCII Construct
  • Juniper Port Checker
  • Bad-Fi
  • Gjermund Raaen
  • Havilandweb
  • WiFiTodd
  • BadgerWiFi
  • WiFrizzy
  • Spectrum Chart

Recent Comments

  • Hiten Thakkar on PCAP I/O Graph Analyzer
  • mali on Deploying Nile Secure – My First NSB
  • Larry Farrish on Deploying Nile Secure – My First NSB
  • Courtney on Mist Access Point – CSV
  • ayoub chabrouk on Ubiquiti stealing the show at MFD11

Archives

  • August 2026
  • July 2026
  • March 2026
  • February 2026
  • December 2025
  • November 2025
  • October 2025
  • August 2025
  • May 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • September 2023
  • August 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • November 2022
  • October 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • May 2021
  • April 2021
  • March 2021
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • April 2019
  • March 2019
  • November 2018
  • October 2018
  • September 2018
  • May 2018
  • January 2018
  • December 2017
  • August 2017
  • January 2017
  • September 2014
  • December 2013
  • October 2013
  • May 2013
  • August 2012
  • July 2012

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Categories

  • AeroHive
  • Arista
  • Arista
  • Aruba
  • Aruba
  • Aruba Central
  • BYoD
  • Certifications
  • Cisco
  • Cisco
  • Cisco EEM Scripting
  • Cisco Routing
  • Cisco Security
  • Cisco VoIP
  • Cisco VPN
  • Cisco Wireless
  • Conferences and Meetings
  • Design
  • Ekahau
  • General
  • Hamina
  • IoT, IIoT, OT
  • Juniper Security
  • Juniper Switching
  • Juniper/Mist
  • Linux
  • Microsoft
  • Mist
  • Mist Wireless
  • Nile
  • Nile Secure
  • Nile Wi-Fi
  • Programming/Automation
  • Python
  • Ruckus
  • Ruckus Wireless
  • Ruckus/Brocade
  • Ruckus/Brocade Scripting
  • Ruckus/Brocade Switching
  • Secure Guest Service
  • Security
  • Switching
  • Tools
  • Troubleshooting
  • Trust Engine
  • Uncategorized
  • Windows
  • Wireless
  • Wireless
  • WLAN Tools
© 2026 artofrf.com | Powered by Minimalist Blog WordPress Theme