Empty pano.predefined.refreshall_services()

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Empty pano.predefined.refreshall_services()

L0 Member

Hello everyone, 

I'm struggling to get a list of the predefined services and applications via the panos python SDK.

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 :

 

This works fine :

pano = connect_to_panorama()
dg = DeviceGroup("shared")
pano.add(dg)
services = ServiceObject.refreshall(dg)
pre_service = pano.predefined.service("service-https")

Answer :
{'protocol': 'tcp', 'source_port': None, 'destination_port': '443', 'description': None, 'tag': None, 'name': 'service-https'}

 

This doesn't :

pano = connect_to_panorama()
dg = DeviceGroup("shared")
pano.add(dg)
pre_services2 = pano.predefined.refreshall_services()

for service in pre_services2:
print(service.about())

Answer :
TypeError: 'NoneType' object is not iterable

With a debug, the value and type is indeed None

 

Am i doing this the wrong way ?

 

Thanks

1 accepted solution

Accepted Solutions

L5 Sessionator

The docs need to be clarified around predefined stuff..

 

The refreshall_* functions invoked from panos.predefined.Predefined do not return a list of objects like every other object works.  Instead, when you invoke one of them (in this case, refreshall_services()), it updates special variables stored within the object itself.  In this case, refreshall_services() updates panos.predefined.Predefined.service_objects:

 

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

 

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:

 

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)

 

So for now just use the variables stored in the namespace to access what you want.  I've opened a github issue to track when the above will be fixed:  https://github.com/PaloAltoNetworks/pan-os-python/issues/378

View solution in original post

2 REPLIES 2

L5 Sessionator

The docs need to be clarified around predefined stuff..

 

The refreshall_* functions invoked from panos.predefined.Predefined do not return a list of objects like every other object works.  Instead, when you invoke one of them (in this case, refreshall_services()), it updates special variables stored within the object itself.  In this case, refreshall_services() updates panos.predefined.Predefined.service_objects:

 

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

 

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:

 

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)

 

So for now just use the variables stored in the namespace to access what you want.  I've opened a github issue to track when the above will be fixed:  https://github.com/PaloAltoNetworks/pan-os-python/issues/378

L0 Member

Hello Gfreeman

Thanks to your answer, I succeeded to get why i needed

Since panos.predefined.Predefined.service_objects only store the name of the predefined objects, i had to ask for them specifically with panos.predefined.service()

 

pano = connect_to_panorama()
pano.predefined.refreshall_services()
for serviceName in pano.predefined.service_objects:
service = pano.predefined.service(serviceName)
print(service.about())

 

Answer is 

{'protocol': 'tcp', 'source_port': None, 'destination_port': '80,8080', 'description': None, 'tag': None, 'name': 'service-http'}
{'protocol': 'tcp', 'source_port': None, 'destination_port': '443', 'description': None, 'tag': None, 'name': 'service-https'}

Have to say I expected more lines 🙂

 

Thanks for your help !

  • 1 accepted solution
  • 2835 Views
  • 2 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

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!