How to update an address object using pan-os sdk python

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Please sign in to see details of an important advisory in our Customer Advisories area.

How to update an address object using pan-os sdk python

L0 Member

Can someone help me with some code snippets to update the name, ip , description and tag of a specific address object in panorama using pan-os python SDK Panorama 

3 REPLIES 3

L0 Member

I was able to rename the address object using rename() , but unable to change the IP, tag, description of the address object using the python sdk. Requesting some help on this

L1 Bithead

@devsrm Did you found any way to do it with python SDK?

 

I am trying to update an address group to add more objects on panorama but I am staring with this sdk 

 

Any tip?

L2 Linker

Hello, i know that this topic is old, but let me try help showing the script that i use.

Would be there a more efficient way, but this one is working fine to me:

 

1- Import tclasses:

 

from panos import firewall
from panos import objects
import getpass

 

 

2- provide the login credentials:

 

api_user = 'admin'
api_password = getpass.getpass('Type your password: ')
device = 'firewall_name_or_ip'

 

3- fw instance object:

 

fw = firewall.Firewall(device, api_username=api_user, api_password=api_password)

 

 

4- Pull the actual objects from the firewall:

 

objects.AddressObject.refreshall(fw)

 

 

5- (optional) Search and find the address object or address group that you want to replace some attribute:

Address Objects:

 

to_replace_value = fw.find('isaacasimov', objects.AddressObject)

 




If required, you can see whats the attributes are configured in the objects:

 

print(to_replace_value.about())

 

Output: 

{'value': '10.10.10.10', 'type': 'ip-netmask', 'description': 'Multivac', 'tag': None, 'name': 'isaacasimov'}

Address Groups:

 

groups = objects.AddressGroup.refreshall(fw)
to_replace_members = fw.find('Foundation', objects.AddressGroup)

 

Output: 

{'static_value': ['FOUNDATION', 'FOUNDATION_AND_EMPIRE', 'SECOND_FOUNDATION', 'RENDEZVOUSWITHRAMA'], 'dynamic_value': None, 'description': None, 'tag': None, 'name': 'Foundation'}

6- Ok the goal is replace, or edit an value, so:

- to change/replace a value in address object, it´s not required to remove the value, just choose the attribute to be changed, and include the new value:

 

to_replace_value.value = '10.40.40.0/24'

 

- to change/replace a value in address object group, i use to pull the actual members, keep in a variable:

 

members_list = to_replace_members.static_value
print(members_list)
Output: ['FOUNDATION', 'FOUNDATION_AND_EMPIRE', 'SECOND_FOUNDATION', 'RENDEZVOUSWITHRAMA']

 

If you want to remove some item from the list, you can use the list methods:

members_list.remove('RENDEZVOUSWITHRAMA') #from A. Clarke 🙂

or

 

del members_list[-1] #If you know the index of the item.

 

 

Or if you just want to include a new one address in the address group object, use the list methods to include a new item in the list:

 

members_list.append('new_item')

 



OR
if you need include more than one item:

 

new_items = ['new_item1', 'new_item2', 'new_item3']
members_list.extend(new_items)

 

 

So now, finally you set new address:

 

to_replace_members.static_value = members_list

 

 

To ensure that the static_value is changed:

 

print(to_replace_members.about())

 

 

 

  • 3191 Views
  • 3 replies
  • 1 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!