Get Tunnel ProxyID - panos python SDK

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Please sign in to see details of an important advisory in our Customer Advisories area.

Get Tunnel ProxyID - panos python SDK

L2 Linker

 

Hi all,
i really need for some help.

I´m trying to retrieve the proxy_id configured in the firewall using SDK, it´s not working:

import getpass
from panos import network
from panos import policies
from panos import firewall
from panos import objects
from termcolor import colored
import pandas as pd
import re

user = 'admin'
password = 'admin'
firewall_name = 'fw.abc.com'
fw_device = firewall.Firewall(firewall_name, api_username=api_user, api_password=password)

network.IpsecTunnel.refreshall(fw_device)
ipsec = fw_device.add(network.IpsecTunnel)
print(ipsec.findall(fw_device, network.IpsecTunnelIpv4ProxyId))

However i´m receiving an empty list.

I´m spending days just trying to get the proxy id from Tunnels, and I don´t know if the script is correct, i tried a lot of commands combinations, and in this moment i´m trying anything... Please, can someone help me?

Thanks,
João Victor

3 REPLIES 3

L5 Sessionator

You're adding the class itself, not an instance of the class.  I'd recommend looking over the scripts in the examples directory to get a feel for how to use the SDK:

 

from panos.firewall import Firewall
from panos.network import IpsecTunnel

host = '127.0.0.1'
username = 'admin'
password = 'admin'

fw = Firewall(host, username, password)

listing = IpsecTunnel.refreshall(fw)
print('Found {0} tunnels'.format(len(listing)))

HI @gfreeman 

thanks for your response. 

 

I´m starting in this journey of Palo Alto SDK. I saw in the documentation that there is an hierarchy between the classes. My problem is not retrieve the actual vpn in use, i can do this. My problem is how can i get the PROXY ID of each vpn. This is not working, i tried a lot of scripts that make sense, however it didn´t worked.

tunnels = network.IpsecTunnel()
fw_device.add(tunnels)
proxy = network.IpsecTunnelIpv4ProxyId.refreshall(tunnels)
vpn = fw_device.find('VPN-123', network.IpsecTunnelIpv4ProxyId)
print(vpn)

[Output]: None

 

################################

tunnels = network.IpsecTunnel.refreshall(fw_device)
for tunnel in tunnels:
#fw_device.add(tunnels)
proxy = network.IpsecTunnelIpv4ProxyId.refreshall(fw_device)
vpn = fw_device.find(tunnel, network.IpsecTunnelIpv4ProxyId)
print(vpn)

** for each tunnel in tunnels, i receive None as output

 

 

 

However i have 2 proxies-ids configured for 'VPN-123'.

 

If someone knows how can i get the proxies ids, i would be very grateful.

 

Thanks,

João Victor

L2 Linker

Hello,

Good and excelent news!!! I can retrieve the proxies-ids. And also, now i learned how to retrieve static routes from specific vrouter, and l3 interface from specific aggregate interface. Bellow follow the script for the three cases. I hope no one lose half night sleep, as i did.

 

 

from panos import firewall
from panos import network

######## fw credentials ###########
api_user = 'admin'
api_password = 'admin'
firewall_ip = 'fw.abc.com'
fw_device = firewall.Firewall(firewall_ip, api_username=api_user, api_password=api_password)

######## Pull proxy-Id from a specific VPN ########################
ipsec = network.IpsecTunnel(name='VPN-123')
fw_device.add(ipsec)
proxy = network.IpsecTunnelIpv4ProxyId.refreshall(ipsec)
for p in proxy:
print(p.about())

##### Pull static routes from a specific vrouter ########
vr = network.VirtualRouter(name='vr-customer-1')
fw_device.add(vr)
static_routes = network.StaticRoute.refreshall(vr)
for route in static_routes:
print(route.about())

##### Pull l3 interfaces from an specific AGGREGATE INTERFACE #####
ae = network.AggregateInterface(name='ae2')
fw_device.add(ae)
sub = network.Layer3Subinterface.refreshall(ae)
for s in sub:
print(s.about())

##### Also you can get a list of configured vrouter/vpn/interface as bellow: #####
'''This will return a list of the VPN Tunnels configured in your firewall '''
tunnels = network.IpsecTunnel.refreshall(fw_device)

'''Once you have a list of vpn names, you can iterate over it: '''

for tunnel in tunnels:
ipsec = network.IpsecTunnel(name=tunnel)
fw_device.add(ipsec)
proxy = network.IpsecTunnelIpv4ProxyId.refreshall(ipsec)
print(f'Pulling proxy id configuration from tunnel {tunnel}')
for p in proxy:
print(p.about())
print('*' * 60)

 

  • 1811 Views
  • 3 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!