Python Script for All Networks

SOLVED
KRobert
Head in the Cloud

Python Script for All Networks

Does anyone know what they best way is to grab all of the networks in an organization and print or write them to an excel file all within a python script? 

 

I am trying to grab a list of Network Names and their Network IDs and write them to a excel file to represent a dictionary key:value pair. 

 

I can grab the Networks using the dashboard.organizations.getOrganizationNetworks(organization_id, total_pages='all') string, but I am having trouble sending this data to an excel file. 

 

Thank you,

CMNO, CCNA R+S
1 ACCEPTED SOLUTION
AutomationDude
Building a reputation

Hello good sir, I recorded a video that explains exactly how to do this for the API course I made. Here's the link:

 

https://www.youtube.com/watch?v=kfTtEUotXCI&t=125s&ab_channel=BoundlessDigital

 

View solution in original post

9 REPLIES 9
sungod
A model citizen

I use openpyxl to create excel files, instructions and tutorial are here...

https://openpyxl.readthedocs.io/en/stable/

 

AutomationDude
Building a reputation

Hello good sir, I recorded a video that explains exactly how to do this for the API course I made. Here's the link:

 

https://www.youtube.com/watch?v=kfTtEUotXCI&t=125s&ab_channel=BoundlessDigital

 

Hey @AutomationDude That was what I was looking for! Thank you. Now any idea on what script I can write to read the file? I am trying to create a program that allows you to input a Network Name and correlate the network name to it's Network ID in a dictionary Key:Value pair. Once the program has the Network ID, it can start making changes to the network. In the csv that was created, I need the program to understand that a user input (Key) should equal Column C (Name) and the program should print the Network ID as the value, Column A. 

CMNO, CCNA R+S
AutomationDude
Building a reputation

Hey @KRobert, you're welcome!

 

I've never written anything for exactly what you described but did have this video that creates new networks from a csv file:

 

https://www.youtube.com/watch?v=Jbb3sxcxQ0A&t=312s&ab_channel=BoundlessDigital

 

I'm guessing you were having some trouble working with variables that were read from the csv so this should hopefully give you some insights that move you in the right direction. Best of luck!

@AutomationDude we are getting closer! With the following, I am able to print the "name" and "id" field of the network list csv. This narrows the data to just those two fields, which I need for the script. 

with open('networks.csv', 'w') as new_file:
    csv_writer = csv.DictWriter(new_file, Networks[0].keys())
    csv_writer.writeheader()
    csv_writer.writerows(Networks)


with open('networks.csv', 'r') as read_file:
    csv_reader = csv.DictReader(read_file)
    for line in csv_reader:
        print(line['name'],line['id'])

Now I need to find a way to correlate the data so that when a user input types 'name', it prints 'id'.

Any ideas on how to do that? 

 

CMNO, CCNA R+S
AutomationDude
Building a reputation

Hmm, not sure what you're missing here since you've got all the data. Could you try rephrasing the use case or the issue?

A user is supposed to input data. When the user inputs a network name, let's just say "Test123" the program then takes the name "Test 123" and checks the list of network names in the csv. If it finds "Test123" in the csv, it prints the corresponding network id for Test123. My goal is to rather than print the network id, save it as a variable to use later in the script 

CMNO, CCNA R+S
KRobert
Head in the Cloud

@AutomationDude I published a clean version to my GitHub. It is a framework, but I am trying to replace the Dictionary Steps with the CSV setup you helped me with. 

 

https://github.com/routercuriosity/MerakiNetworkUpdater

 

 

CMNO, CCNA R+S
NesAlba
Here to help

@KRobert Try this script 

https://github.com/NesAlba21/Meraki_Tshoot

 I think this is what you are looking for

Get notified when there are additional replies to this discussion.
Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.