Error in simple policy creation script
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

The Enhanced LIVEcommunity Experience is finally here! Learn all about it.

Error in simple policy creation script

L2 Linker

Hello all;

 

I have the following script:

 

#!/usr/bin/python3

import panos
from panos import base
from panos import firewall
from panos import panorama
from panos import policies
from panos import objects
from panos import network
from panos import device
from panos.policies import Rulebase, SecurityRule

fw = firewall.Firewall("192.168.122.5", "admin", "admin")
webserver = objects.AddressObject("Apache-webserver", "5.5.5.5", description="Company web server")
fw.add(webserver)
webserver.create()
fw.commit()

#Create a new rule
new_rule = panos.policies.SecurityRule("Madinah-Rule", description="Madinah")
#rule = Rulebase.add(SecurityRule("Madinah-Rule"))
Rulebase.add(new_rule)
new_rule.create()
fw.commit(Sync=True)

But when I run it using the command python3 script.py I am getting the error:

 

Traceback (most recent call last):
  File "madinah-pan-os-script.py", line 22, in <module>
    Rulebase.add(new_rule)
TypeError: add() missing 1 required positional argument: 'child'

 

Can someone please point me in the right direction. I guess it has something to do with difference in Python2 and Python3.

1 ACCEPTED SOLUTION

Accepted Solutions

L2 Linker

Hi there,

You need to create a rulebase object before you can add to it:

 

#Create a new rule
rulebase = fw.add(Rulebase())

new_rule = rulebase.add(panos.policies.SecurityRule("Madinah-Rule", description="Madinah"))

 

cheers,

Seb.

View solution in original post

1 REPLY 1

L2 Linker

Hi there,

You need to create a rulebase object before you can add to it:

 

#Create a new rule
rulebase = fw.add(Rulebase())

new_rule = rulebase.add(panos.policies.SecurityRule("Madinah-Rule", description="Madinah"))

 

cheers,

Seb.

View solution in original post

Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!