- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
01-08-2022 07:16 AM
03-23-2022 03:45 PM
@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?
08-21-2022 03:15 PM - edited 08-21-2022 03:18 PM
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())
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!