Need help with scripting to add member to address group using pandevice command (Python)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need help with scripting to add member to address group using pandevice command (Python)

L0 Member

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

1 accepted solution

Accepted Solutions

L5 Sessionator

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!

Help the community: "Like" helpful comments, and click "Accept as Solution" if you found your answer 🙂

View solution in original post

2 REPLIES 2

L5 Sessionator

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!

Help the community: "Like" helpful comments, and click "Accept as Solution" if you found your answer 🙂

L0 Member

@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

  • 1 accepted solution
  • 2825 Views
  • 2 replies
  • 0 Likes
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!