<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Rename zone in security policy through xml api in Automation/API Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rename-zone-in-security-policy-through-xml-api/m-p/197753#M1562</link>
    <description>&lt;P&gt;Ahhh, that works.&amp;nbsp; No worries.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit will replace everything at that element/tag with whatever you input.&amp;nbsp; So if you have multiple zones in the Source Zone and do an edit, it will nuke everything and drop your new zone in leaving you with an odd configuration.&amp;nbsp; If you've only got single zones in your rule, this shouldn't be too much of an issue, but it is something akin to using a chainsaw to perform leg surgery.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rename is to do just that, rename an object.&amp;nbsp; Instead of objectA you want to name it ObjectA, you would use rename to get it done.&amp;nbsp; You wouldn't be renaming an object, unless you simply wanted to take ZoneA and rename it to ZoneA_old.&amp;nbsp; In that case, you would be on track with the rename action.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Otherwise the Add/Remove process is what you are going to be looking for, it'll allow you to carve out and readd what you are looking for in process.&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jan 2018 02:11:55 GMT</pubDate>
    <dc:creator>tschlottog</dc:creator>
    <dc:date>2018-01-31T02:11:55Z</dc:date>
    <item>
      <title>Rename zone in security policy through xml api</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rename-zone-in-security-policy-through-xml-api/m-p/197546#M1551</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to programatically rename security zone via xml api.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a scenario:&lt;/P&gt;&lt;P&gt;1. Device currently has 5 zones: trust, untrust, dmz, lvl1, lvl2&lt;/P&gt;&lt;P&gt;2. There are 500+ policies where &amp;lt;&amp;lt;trust&amp;gt;&amp;gt; appears as source zone member or destination zone member (there can be multiple src or dst zone members as well, e.g: from: trust, lvl2, to: dmz, lvl1, trust, and so on)&lt;/P&gt;&lt;P&gt;3. We want to rename zone trust into trust_old. We will keep zone trust for now, but what we need to do is to ensure each security rule that had zone "trust" now has renamed zone "trust_old". So the idea is to introduce a new zone, rename all security policies that use that zone and then remove zone at the end.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to figure out how to achieve this with xml api.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This would be an example of my rule as it sits on panorama. We need to do everything directly on panorama because we manage all config on panorama directly:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;xpath="/config/devices/entry[@name='localhost.localdomain']/device-group/entry[@name='Firewall Lab']/pre-rulebase/security/rules/entry[@name='test-block-milos1']"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(python requests module, querytype_show =&amp;nbsp;'?type=config&amp;amp;action=show&amp;amp;'&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; result = s.get(panorama + querytype_show + urlencode({"xpath": xpath}) + key, verify=False)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;u'&amp;lt;response status="success"&amp;gt;&amp;lt;result&amp;gt;&amp;lt;entry name="test-block-milos1"&amp;gt;\n &amp;lt;target&amp;gt;\n &amp;lt;negate&amp;gt;no&amp;lt;/negate&amp;gt;\n &amp;lt;/target&amp;gt;\n &amp;lt;to&amp;gt;\n &amp;lt;member&amp;gt;untrust&amp;lt;/member&amp;gt;\n &amp;lt;/to&amp;gt;\n &amp;lt;from&amp;gt;\n &amp;lt;member&amp;gt;trust&amp;lt;/member&amp;gt;\n &amp;lt;/from&amp;gt;\n &amp;lt;source&amp;gt;\n &amp;lt;member&amp;gt;milos-test1&amp;lt;/member&amp;gt;\n &amp;lt;/source&amp;gt;\n &amp;lt;destination&amp;gt;\n &amp;lt;member&amp;gt;milos-test2&amp;lt;/member&amp;gt;\n &amp;lt;/destination&amp;gt;\n &amp;lt;source-user&amp;gt;\n &amp;lt;member&amp;gt;any&amp;lt;/member&amp;gt;\n &amp;lt;/source-user&amp;gt;\n &amp;lt;category&amp;gt;\n &amp;lt;member&amp;gt;any&amp;lt;/member&amp;gt;\n &amp;lt;/category&amp;gt;\n &amp;lt;application&amp;gt;\n &amp;lt;member&amp;gt;icmp&amp;lt;/member&amp;gt;\n &amp;lt;member&amp;gt;oracle&amp;lt;/member&amp;gt;\n &amp;lt;/application&amp;gt;\n &amp;lt;service&amp;gt;\n &amp;lt;member&amp;gt;application-default&amp;lt;/member&amp;gt;\n &amp;lt;/service&amp;gt;\n &amp;lt;hip-profiles&amp;gt;\n &amp;lt;member&amp;gt;any&amp;lt;/member&amp;gt;\n &amp;lt;/hip-profiles&amp;gt;\n &amp;lt;action&amp;gt;deny&amp;lt;/action&amp;gt;\n &amp;lt;log-setting&amp;gt;LOG&amp;lt;/log-setting&amp;gt;\n &amp;lt;description&amp;gt;rule 42479&amp;lt;/description&amp;gt;\n&amp;lt;/entry&amp;gt;\n&amp;lt;/result&amp;gt;&amp;lt;/response&amp;gt;'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I select this rule and rename "from trust" to "from trust_old" ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any tips provided&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Milos&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 04:55:49 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/rename-zone-in-security-policy-through-xml-api/m-p/197546#M1551</guid>
      <dc:creator>KostiM</dc:creator>
      <dc:date>2018-01-30T04:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Rename zone in security policy through xml api</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rename-zone-in-security-policy-through-xml-api/m-p/197672#M1556</link>
      <description>&lt;P&gt;Milos, you are going to need to alter your action from 'action=show' to 'action=set' to get it to add in the new zone and then an 'action=delete' in order to remove the old zone.&amp;nbsp; You should be able to do this programatically through some offbox scripting as well.&amp;nbsp; I've automated changes like this before and broke them down in 3 discrete stages.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; Discovery - Pull down the configuration from Panorama then roll through the XML using something like Element Tree in order to find all the rules that match the source zone or whatever XML tag I am looking for and create a list to be used.&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; Addition - With the created list, sequentially roll through the rules creating targeted additions to the rules with the 'action=set' as part of the URI.&amp;nbsp; Monitor for any errors at this stage, if you catch anything other than HTTP 200 responses, stop the entire process and take a look at what is going on.&lt;/P&gt;&lt;P&gt;3.&amp;nbsp; Clean Up - With the same list we used in Addition, go through and with an 'action=delete' removing your old source zone or tag.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At this point you have a candidate configuration and will need to commit it in order to complete your change.&amp;nbsp; This is a good time to run a config diff between your candidate and running configuration to make sure that you are visually seeing the changes that you want to see.&amp;nbsp; If you are good with it, go ahead with the commit.&amp;nbsp; Once you are comfortable with the actions in your script, you can automate the commit process as well, but it is something I typically leave for the end game of the development process given the potential for issues while creating this process.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 18:43:47 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/rename-zone-in-security-policy-through-xml-api/m-p/197672#M1556</guid>
      <dc:creator>tschlottog</dc:creator>
      <dc:date>2018-01-30T18:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: Rename zone in security policy through xml api</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rename-zone-in-security-policy-through-xml-api/m-p/197751#M1561</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks for your reply. I was using action show to just show example of a single rule.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do I have to do set + delete or is there any way to use action=rename or action=edit? I was kind of hoping that I can just do a simple rename or edit, not to have to set and delete.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use Python quite a lot and automated bunch of things so far to pull panorama config to discover rules for various purposes so this is not going to be a problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am just trying to figure out if Addition + Cleanup is absolutely necessary as per your suggestion or if we can do immediate edit or rename&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Milos&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 01:49:03 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/rename-zone-in-security-policy-through-xml-api/m-p/197751#M1561</guid>
      <dc:creator>KostiM</dc:creator>
      <dc:date>2018-01-31T01:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: Rename zone in security policy through xml api</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rename-zone-in-security-policy-through-xml-api/m-p/197753#M1562</link>
      <description>&lt;P&gt;Ahhh, that works.&amp;nbsp; No worries.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit will replace everything at that element/tag with whatever you input.&amp;nbsp; So if you have multiple zones in the Source Zone and do an edit, it will nuke everything and drop your new zone in leaving you with an odd configuration.&amp;nbsp; If you've only got single zones in your rule, this shouldn't be too much of an issue, but it is something akin to using a chainsaw to perform leg surgery.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rename is to do just that, rename an object.&amp;nbsp; Instead of objectA you want to name it ObjectA, you would use rename to get it done.&amp;nbsp; You wouldn't be renaming an object, unless you simply wanted to take ZoneA and rename it to ZoneA_old.&amp;nbsp; In that case, you would be on track with the rename action.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Otherwise the Add/Remove process is what you are going to be looking for, it'll allow you to carve out and readd what you are looking for in process.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 02:11:55 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/rename-zone-in-security-policy-through-xml-api/m-p/197753#M1562</guid>
      <dc:creator>tschlottog</dc:creator>
      <dc:date>2018-01-31T02:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: Rename zone in security policy through xml api</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rename-zone-in-security-policy-through-xml-api/m-p/197754#M1563</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So that's exactly where I am stuck at the moment. Example on how to use action=edit and action=rename on zone object. I tried but I am constantly failing. I think i am not doing a correct xpath to select the object before I rename it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And this is exactly why I came to this forum to ask if someone has a working example on how to edit or rename "FROM" and "TO" fields in the security policy on&amp;nbsp;Panorama that would effectively change security zone on my security policy on device group that Panorama is currently managing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help on this is greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Milos&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 02:34:32 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/rename-zone-in-security-policy-through-xml-api/m-p/197754#M1563</guid>
      <dc:creator>KostiM</dc:creator>
      <dc:date>2018-01-31T02:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Rename zone in security policy through xml api</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rename-zone-in-security-policy-through-xml-api/m-p/199693#M1585</link>
      <description>&lt;P&gt;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&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am relying on pan.xapi (pan-python) library but you can use normal requests for this as well and do everything manually&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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 -&amp;gt; to zone: untrust).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the solution that I came up with:&lt;/P&gt;&lt;PRE&gt;# 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&lt;BR /&gt;# 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 &amp;lt;from&amp;gt;&amp;lt;member&amp;gt;internal&amp;lt;/member&amp;gt;&amp;lt;member&amp;gt;dmz&amp;lt;/member&amp;gt;&amp;lt;/from&amp;gt;
# 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)&lt;BR /&gt;&lt;BR /&gt;# Check the result (to show success or fail)&lt;BR /&gt;print(xapi.xml_document)&lt;/PRE&gt;&lt;P&gt;I hope you will find&amp;nbsp; this useful&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Milos&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2018 03:26:24 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/rename-zone-in-security-policy-through-xml-api/m-p/199693#M1585</guid>
      <dc:creator>KostiM</dc:creator>
      <dc:date>2018-02-09T03:26:24Z</dc:date>
    </item>
  </channel>
</rss>

