- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
09-29-2022 09:14 AM
Hi All,
I am working to get automation script for creating address objects and binding it to address group. I was able to get the script ready and tested working for adding address objects to a firewall using API call. The script is written with pandevice in python. However, I am looking for syntax/command of pandevice to add those address objects to a address group - new/existing, has anyone used it?
Pandevice command on python to create address object:
import pandevice
fw = firewall.Firewall(<firewall_IP>, <api_Key>)
fw.add(AddressObject(<address_obj_name>,<IP_address>, <description>)).create()
I am looking for pandevice syntax to add a address object to a address group (exiting or new group). Please guide.
#api #pandevice #python #automation
10-03-2022 04:44 AM
Hi @mohan.alagar,
First I would consider moving to importing pan-os-python instead of pandevice for your Python scripts (reference here). From there you will find the docs here, including the syntax for AddressGroup here. It would be something like this as an example:
new_group = "new-address-group"
new_group_members = [new_object_one, new_object_two]
fw.add(AddressGroup(name=new_group, static_value=new_group_members)).create()
Here is a working example.
Hope that helps!
10-03-2022 04:44 AM
Hi @mohan.alagar,
First I would consider moving to importing pan-os-python instead of pandevice for your Python scripts (reference here). From there you will find the docs here, including the syntax for AddressGroup here. It would be something like this as an example:
new_group = "new-address-group"
new_group_members = [new_object_one, new_object_two]
fw.add(AddressGroup(name=new_group, static_value=new_group_members)).create()
Here is a working example.
Hope that helps!
10-04-2022 07:38 AM
@JimmyHolland Thank you very much. That worked. I actually was missing to import AddressGroup. post adding it worked for me on both version of script pan-os-python & pandevice. As suggested I upgraded to pan-os-python.
import panos
from panos.objects import AddressObject, AddressGroup
Thank you very much.
Mohan A
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!