<?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: Empty pano.predefined.refreshall_services() in Automation/API Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/empty-pano-predefined-refreshall-services/m-p/443820#M2816</link>
    <description>&lt;P&gt;The docs need to be clarified around predefined stuff..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The &lt;CODE&gt;refreshall_*&lt;/CODE&gt; functions invoked from &lt;CODE&gt;panos.predefined.Predefined&lt;/CODE&gt; do not return a list of objects like every other object works.&amp;nbsp; Instead, when you invoke one of them (in this case, &lt;CODE&gt;refreshall_services()&lt;/CODE&gt;), it updates special variables stored within the object itself.&amp;nbsp; In this case, &lt;CODE&gt;refreshall_services()&lt;/CODE&gt; updates &lt;CODE&gt;panos.predefined.Predefined.service_objects&lt;/CODE&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;In [1]: from panos.firewall import Firewall                                     

In [2]: from panos.predefined import Predefined                                 

In [3]: from panos.objects import ServiceObject                                 

In [4]: fw = Firewall(.....)                  

In [5]: fw.refresh_system_info()                                                 
Out[5]: SystemInfo(version='8.1.0', platform='PA-VM', serial='.....')

In [6]: len(fw.predefined.service_objects)                                       
Out[6]: 0

In [7]: fw.predefined.refreshall_services()                                      

In [8]: len(fw.predefined.service_objects)                                       
Out[8]: 2&lt;/LI-CODE&gt;
&lt;P class="p5"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p5"&gt;&lt;SPAN class="s6"&gt;The intent was that you could alternatively side-step this behavior and make the predefined stuff work like all the other pan-os-python objects, but I just tried it and this doesn't work:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p5"&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;from panos.firewall import Firewall
from panos.predefined import Predefined
from panos.objects import ServiceObject

fw = Firewall(.....)
predef = Predefined()
fw.add(predef)
ServiceObject.refreshall(predef)&lt;/LI-CODE&gt;
&lt;P class="p5"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for now just use the variables stored in the namespace to access what you want.&amp;nbsp; I've opened a github issue to track when the above will be fixed:&amp;nbsp;&amp;nbsp;&lt;A href="https://github.com/PaloAltoNetworks/pan-os-python/issues/378" target="_blank"&gt;https://github.com/PaloAltoNetworks/pan-os-python/issues/378&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Oct 2021 16:12:07 GMT</pubDate>
    <dc:creator>gfreeman</dc:creator>
    <dc:date>2021-10-27T16:12:07Z</dc:date>
    <item>
      <title>Empty pano.predefined.refreshall_services()</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/empty-pano-predefined-refreshall-services/m-p/443793#M2815</link>
      <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm struggling to get a list of the predefined services and applications via the panos python SDK.&lt;/P&gt;&lt;P&gt;I'm able to get a proper answer if i'm asking a specific service, but the "refreshall_services" or "refreshall_applications" classes always answer me a None object :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works fine :&lt;/P&gt;&lt;PRE&gt;pano = connect_to_panorama()&lt;BR /&gt;dg = DeviceGroup(&lt;SPAN&gt;"shared"&lt;/SPAN&gt;)&lt;BR /&gt;pano.add(dg)&lt;BR /&gt;services = ServiceObject.refreshall(dg)&lt;BR /&gt;pre_service = pano.predefined.service(&lt;SPAN&gt;"service-https"&lt;/SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;Answer :&lt;BR /&gt;{'protocol': 'tcp', 'source_port': None, 'destination_port': '443', 'description': None, 'tag': None, 'name': 'service-https'}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This doesn't :&lt;/P&gt;&lt;PRE&gt;pano = connect_to_panorama()&lt;BR /&gt;dg = DeviceGroup(&lt;SPAN&gt;"shared"&lt;/SPAN&gt;)&lt;BR /&gt;pano.add(dg)&lt;BR /&gt;pre_services2 = pano.predefined.refreshall_services()&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for &lt;/SPAN&gt;service &lt;SPAN&gt;in &lt;/SPAN&gt;pre_services2:&lt;BR /&gt;    &lt;SPAN&gt;print&lt;/SPAN&gt;(service.about())&lt;BR /&gt;&lt;BR /&gt;Answer : &lt;BR /&gt;TypeError: 'NoneType' object is not iterable&lt;/PRE&gt;&lt;P&gt;With a debug, the value and type is indeed None&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am i doing this the wrong way ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 14:52:35 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/empty-pano-predefined-refreshall-services/m-p/443793#M2815</guid>
      <dc:creator>Klayhan</dc:creator>
      <dc:date>2021-10-27T14:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Empty pano.predefined.refreshall_services()</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/empty-pano-predefined-refreshall-services/m-p/443820#M2816</link>
      <description>&lt;P&gt;The docs need to be clarified around predefined stuff..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The &lt;CODE&gt;refreshall_*&lt;/CODE&gt; functions invoked from &lt;CODE&gt;panos.predefined.Predefined&lt;/CODE&gt; do not return a list of objects like every other object works.&amp;nbsp; Instead, when you invoke one of them (in this case, &lt;CODE&gt;refreshall_services()&lt;/CODE&gt;), it updates special variables stored within the object itself.&amp;nbsp; In this case, &lt;CODE&gt;refreshall_services()&lt;/CODE&gt; updates &lt;CODE&gt;panos.predefined.Predefined.service_objects&lt;/CODE&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;In [1]: from panos.firewall import Firewall                                     

In [2]: from panos.predefined import Predefined                                 

In [3]: from panos.objects import ServiceObject                                 

In [4]: fw = Firewall(.....)                  

In [5]: fw.refresh_system_info()                                                 
Out[5]: SystemInfo(version='8.1.0', platform='PA-VM', serial='.....')

In [6]: len(fw.predefined.service_objects)                                       
Out[6]: 0

In [7]: fw.predefined.refreshall_services()                                      

In [8]: len(fw.predefined.service_objects)                                       
Out[8]: 2&lt;/LI-CODE&gt;
&lt;P class="p5"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p5"&gt;&lt;SPAN class="s6"&gt;The intent was that you could alternatively side-step this behavior and make the predefined stuff work like all the other pan-os-python objects, but I just tried it and this doesn't work:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p5"&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;from panos.firewall import Firewall
from panos.predefined import Predefined
from panos.objects import ServiceObject

fw = Firewall(.....)
predef = Predefined()
fw.add(predef)
ServiceObject.refreshall(predef)&lt;/LI-CODE&gt;
&lt;P class="p5"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for now just use the variables stored in the namespace to access what you want.&amp;nbsp; I've opened a github issue to track when the above will be fixed:&amp;nbsp;&amp;nbsp;&lt;A href="https://github.com/PaloAltoNetworks/pan-os-python/issues/378" target="_blank"&gt;https://github.com/PaloAltoNetworks/pan-os-python/issues/378&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 16:12:07 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/empty-pano-predefined-refreshall-services/m-p/443820#M2816</guid>
      <dc:creator>gfreeman</dc:creator>
      <dc:date>2021-10-27T16:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: Empty pano.predefined.refreshall_services()</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/empty-pano-predefined-refreshall-services/m-p/445197#M2822</link>
      <description>&lt;P&gt;Hello Gfreeman&lt;/P&gt;&lt;P&gt;Thanks to your answer, I succeeded to get why i needed&lt;/P&gt;&lt;P&gt;Since&amp;nbsp;&lt;SPAN&gt;panos.predefined.Predefined.service_objects only store the name of the predefined objects, i had to ask for them specifically with panos.predefined.service()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;pano = connect_to_panorama()&lt;BR /&gt;pano.predefined.refreshall_services()&lt;BR /&gt;&lt;SPAN&gt;for &lt;/SPAN&gt;serviceName &lt;SPAN&gt;in &lt;/SPAN&gt;pano.predefined.service_objects:&lt;BR /&gt;service = pano.predefined.service(serviceName)&lt;BR /&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;(service.about())&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Answer is&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{'protocol': 'tcp', 'source_port': None, 'destination_port': '80,8080', 'description': None, 'tag': None, 'name': 'service-http'}&lt;BR /&gt;{'protocol': 'tcp', 'source_port': None, 'destination_port': '443', 'description': None, 'tag': None, 'name': 'service-https'}&lt;/PRE&gt;&lt;P&gt;Have to say I expected more lines&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help !&lt;/P&gt;</description>
      <pubDate>Wed, 03 Nov 2021 11:24:10 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/empty-pano-predefined-refreshall-services/m-p/445197#M2822</guid>
      <dc:creator>Klayhan</dc:creator>
      <dc:date>2021-11-03T11:24:10Z</dc:date>
    </item>
  </channel>
</rss>

