How to use the mx_l3_firewall.updateNetworkL3FirewallRules()

SOLVED
Edgar-VO
Building a reputation

How to use the mx_l3_firewall.updateNetworkL3FirewallRules()

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
 
 
 
1 ACCEPTED SOLUTION
PhilipDAth
Kind of a big deal
Kind of a big deal

It should be something more like:

 

esponse = dashboard.mx_l3_firewall.updateNetworkL3FirewallRules(def_network,rules=payload)

View solution in original post

4 REPLIES 4
PhilipDAth
Kind of a big deal
Kind of a big deal

kwargs just means you use named parameters.  For example, the updateNetworkDevice call (which also uses kwargs) might look like:

 

dashboard.devices.updateNetworkDevice(netId,serial,lat=lat,lng=long)

Edgar-VO
Building a reputation


I tried the following ;

def_rule ='{"rules": [{"comment":"Allow test","policy":"allow","protocol":"any","srcCidr":"10.13.64.0/24","srcPort":"Any","destCidr":"Any","destPort":"Any","syslogEnabled":False},{"comment":"Allow BLAH","policy":"allow","protocol":"Any","srcCidr":"10.24.10.0/16","srcPort":"Any","destCidr":"Any","destPort":"Any","syslogEnabled":False}]}'

payload = json.dumps(def_rule)

response = dashboard.mx_l3_firewall.updateNetworkL3FirewallRules(def_network,payload)

TypeError: updateNetworkL3FirewallRules() takes 2 positional arguments but 3 were given

So...... how now to use the **kwargs.....

I know... still newbie at programming....
PhilipDAth
Kind of a big deal
Kind of a big deal

It should be something more like:

 

esponse = dashboard.mx_l3_firewall.updateNetworkL3FirewallRules(def_network,rules=payload)

Edgar-VO
Building a reputation

Yup.... that worked, and i got much more information back from the API then using the REST

Anyway..... Thanks.... this also solves some other issues i had with parameter parsing with python and Meraki API


Get notified when there are additional replies to this discussion.