I am new to programming in Python and the use of Meraki API. Getting information using the API calls is not a problem. Modifying that information is difficult.
I have the following code for reading the L3 firewall and putting it in an excel sheet. (as a back)
import meraki
import xlrd
import xlwt
from xlwt import Workbook
wb = Workbook()
#
# create sheet
#
# Demo Key
api_key = '89476587346587583475873875687532578875'
dashboard = meraki.DashboardAPI(api_key)
my_org = dashboard.organizations.getOrganizations()
for org in my_org:
print(f'\nAnalyzing organization {org["name"]}:')
org_id = org['id']
site_code = "SITENAME"
my_networks = dashboard.networks.getOrganizationNetworks(org_id)
for my_net in my_networks:
if site_code in my_net['name']:
sheet1 = wb.add_sheet(my_net['name'])
sheet1.write(0,0,'comment')
sheet1.write(0,1,'policy')
sheet1.write(0,2,'protocol')
sheet1.write(0,3,'srcPort')
sheet1.write(0,4,'srcCidr')
sheet1.write(0,5,'destPort')
sheet1.write(0,6,'destCidr')
sheet1.write(0,7,'syslogEnabled')
net_id=my_net["id"]
my_MX_firewall = dashboard.mx_l3_firewall.getNetworkL3FirewallRules(net_id)
row_count = 0
for my_FW_rule in my_MX_firewall:
row_count += 1
sheet1.write(row_count,0,my_FW_rule['comment'])
sheet1.write(row_count,1,my_FW_rule['policy'])
sheet1.write(row_count,2,my_FW_rule['protocol'])
sheet1.write(row_count,3,my_FW_rule['srcPort'])
sheet1.write(row_count,4,my_FW_rule['srcCidr'])
sheet1.write(row_count,5,my_FW_rule['destPort'])
sheet1.write(row_count,6,my_FW_rule['destCidr'])
sheet1.write(row_count,7,my_FW_rule['syslogEnabled'])
wb.save('firewall-bck.xls')
Now i want to use the mx_l3_firewall.updateNetworkL3FirewallRules() API call to restore / change a L3 Firewall on a site...
When i look at the documentation, i see i have to parse networkid and **kwargs to the API call.
I would like to see some code (like above) which i can use to restore the firewall rules...
I am looking for some sample code where i can use that API call. If i have this running, i can create a template and create a new site with specific Firewall rules