I actually figured one way to solve my problem and I'm happy to share python code that I am using in particular. Some of you might find it useful I am relying on pan.xapi (pan-python) library but you can use normal requests for this as well and do everything manually Let's say this is your problem: You have a security policy internet-access-1 that's build with source zone trust+dmz and destination zone untrust. You want to rename source zone trust to be internal (so the policy is from zone: internal, dmz -> to zone: untrust). Here's the solution that I came up with: # Using the following python libraries
import pan.xapi
import xmltodict
# Create pan.xapi object
xapi = pan.xapi.PanXapi(hostname=panorama, api_username=user, api_key=key)
# Set the correct xpath to grab the FROM as we are changing source zone.
# We would use "to" if we wanted to change destination zone # As I am using panorama, I am changing the security rulebase on the device-group that my panorama is managing
xpath = "/config/devices/entry[@name='localhost.localdomain']/device-group/entry[@name='firewalls1']/pre-rulebase/security/rules/entry[@name='internet-access-1']/from"
# element_xml needs to be <from><member>internal</member><member>dmz</member></from>
# I am using xmltodict.unparse to help with this because it is flexible and very useful if you have multiple objects that you want to auto generate XML for. xmltodict is a fantastic library
element_xml = xmltodict.unparse({"from": {"member": ["internal", "dmz"] }} )
# Do the edit
xapi.edit(xpath=xpath, element=element_xml) # Check the result (to show success or fail) print(xapi.xml_document) I hope you will find this useful Cheers, Milos
... View more