<?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 Pan-os-python with Panorama in Automation/API Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/pan-os-python-with-panorama/m-p/379565#M2527</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the following code to check and create rules on my test-palo device:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is more or less just the example from the github page and it's working fine.&lt;/P&gt;&lt;P&gt;I check the current Rules on the firewall before I start adding rules.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;fw = panos.firewall.Firewall(HOSTNAME&lt;SPAN&gt;, &lt;/SPAN&gt;USERNAME&lt;SPAN&gt;, &lt;/SPAN&gt;PASSWORD)&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;rulebase = panos.policies.Rulebase()&lt;BR /&gt;fw.add(rulebase)&lt;BR /&gt;current_security_rules = panos.policies.SecurityRule.refreshall(rulebase)&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;"Current security rule(s) ({0} found):"&lt;/SPAN&gt;.format(&lt;SPAN&gt;len&lt;/SPAN&gt;(current_security_rules)))&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;So now I need the same with panorama and a particular device group:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It have started with conneting to panorama, create a device group and add an object into it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;pano = panos.panorama.Panorama(HOSTNAME&lt;SPAN&gt;, &lt;/SPAN&gt;USERNAME&lt;SPAN&gt;, &lt;/SPAN&gt;PASSWORD )&lt;BR /&gt;pano.add(panos.panorama.DeviceGroup(&lt;SPAN&gt;"DG-VWire"&lt;/SPAN&gt;)).create()&lt;BR /&gt;&lt;SPAN&gt;pano.add(panos.objects.AddressObject("Server3", "1.2.3.4")).create()&lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I will later find out that the object is not just present on the device-group but on any groups.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here is the part I don't understand:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using only post rules on panorama and there are 6 rules in my rulebase&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;rulebase = panos.policies.PostRulebase()&lt;BR /&gt;pano.add(rulebase)&lt;BR /&gt;current_security_rules = panos.policies.SecurityRule.refreshall(rulebase)&lt;BR /&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;"Current security rule(s) ({0} found):"&lt;/SPAN&gt;.format(&lt;SPAN&gt;len&lt;/SPAN&gt;(current_security_rules)))&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But there a no rules found. Can someone please explain what I am doing wrong?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can only guess that I'm not in the expected device-group and there are no rules?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jan 2021 14:44:45 GMT</pubDate>
    <dc:creator>mseiler</dc:creator>
    <dc:date>2021-01-13T14:44:45Z</dc:date>
    <item>
      <title>Pan-os-python with Panorama</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/pan-os-python-with-panorama/m-p/379565#M2527</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the following code to check and create rules on my test-palo device:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is more or less just the example from the github page and it's working fine.&lt;/P&gt;&lt;P&gt;I check the current Rules on the firewall before I start adding rules.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;fw = panos.firewall.Firewall(HOSTNAME&lt;SPAN&gt;, &lt;/SPAN&gt;USERNAME&lt;SPAN&gt;, &lt;/SPAN&gt;PASSWORD)&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;rulebase = panos.policies.Rulebase()&lt;BR /&gt;fw.add(rulebase)&lt;BR /&gt;current_security_rules = panos.policies.SecurityRule.refreshall(rulebase)&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;"Current security rule(s) ({0} found):"&lt;/SPAN&gt;.format(&lt;SPAN&gt;len&lt;/SPAN&gt;(current_security_rules)))&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;So now I need the same with panorama and a particular device group:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It have started with conneting to panorama, create a device group and add an object into it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;pano = panos.panorama.Panorama(HOSTNAME&lt;SPAN&gt;, &lt;/SPAN&gt;USERNAME&lt;SPAN&gt;, &lt;/SPAN&gt;PASSWORD )&lt;BR /&gt;pano.add(panos.panorama.DeviceGroup(&lt;SPAN&gt;"DG-VWire"&lt;/SPAN&gt;)).create()&lt;BR /&gt;&lt;SPAN&gt;pano.add(panos.objects.AddressObject("Server3", "1.2.3.4")).create()&lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I will later find out that the object is not just present on the device-group but on any groups.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here is the part I don't understand:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using only post rules on panorama and there are 6 rules in my rulebase&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;rulebase = panos.policies.PostRulebase()&lt;BR /&gt;pano.add(rulebase)&lt;BR /&gt;current_security_rules = panos.policies.SecurityRule.refreshall(rulebase)&lt;BR /&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;"Current security rule(s) ({0} found):"&lt;/SPAN&gt;.format(&lt;SPAN&gt;len&lt;/SPAN&gt;(current_security_rules)))&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But there a no rules found. Can someone please explain what I am doing wrong?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can only guess that I'm not in the expected device-group and there are no rules?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 14:44:45 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/pan-os-python-with-panorama/m-p/379565#M2527</guid>
      <dc:creator>mseiler</dc:creator>
      <dc:date>2021-01-13T14:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: Pan-os-python with Panorama</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/pan-os-python-with-panorama/m-p/379625#M2528</link>
      <description>&lt;P&gt;pan-os-python uses an object hierarchy.&amp;nbsp; You have part of this correct, but part of it is wrong, and that's why you're not getting the results you expect.&amp;nbsp; You want your object hierarchy to look like Panorama &amp;gt; DeviceGroup &amp;gt; AddressObject, but your first chunk is actually setting up the hierarchy as a Panorama object with two children, a DeviceGroup and an AddressObject.&amp;nbsp; Invoking the create() function on the AddressObject with your hierarchy like this should put the address object in the shared scope instead of the device group.&amp;nbsp; So your code should look something like this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;from panos.panorama import Panorama, DeviceGroup
from panos.objects import AddressObject

pano = Panorama(HOSTNAME, USERNAME, PASSWORD)

dg = DeviceGroup("DG-VWire")
pano.add(dg)
dg.create()

obj = AddressObject("Server3", "1.2.3.4")
dg.add(obj)
obj.create()&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your security rules one, I'm guessing you're wanting to get the rules that are in a specific device group..?&amp;nbsp; I don't see a device group reflected in your code.&amp;nbsp; So you'd want something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;from panos.panorama import Panorama, DeviceGroup
from panos.policies import SecurityRule, PostRulebase

pano = Panorama(HOSTNAME, USERNAME, PASSWORD)

dg = DeviceGroup("my group")
pano.add(dg)

rulebase = PostRulebase()
dg.add(rulebase)

rules = SecurityRule.refreshall(rulebase)
print("Current security rules ({0} found):".format(len(rules)))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that helps!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 17:12:35 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/pan-os-python-with-panorama/m-p/379625#M2528</guid>
      <dc:creator>gfreeman</dc:creator>
      <dc:date>2021-01-13T17:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: Pan-os-python with Panorama</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/pan-os-python-with-panorama/m-p/379926#M2530</link>
      <description>&lt;P&gt;Yeah,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;that helped me a lot. I'm now able to read and create rules in the Postrulebase in that DeviceGroup.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Michael&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2021 14:48:09 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/pan-os-python-with-panorama/m-p/379926#M2530</guid>
      <dc:creator>mseiler</dc:creator>
      <dc:date>2021-01-14T14:48:09Z</dc:date>
    </item>
  </channel>
</rss>

