Adding device to Panorama Using Python SDK

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

Adding device to Panorama Using Python SDK

L0 Member

I am trying to add a device to Panorama using Python SDK (panos). I was able to configure the device side using below code but cannot do the same Panorama side. 

Any help is greatly appreciated! 

 

from panos.panorama import Panorama
from panos.firewall import Firewall
from panos.device import SystemSettings

panorama = Panorama("192.168.254.1", "admin", "admin")
fw= Firewall("192.168.254.2", "admin", "admin")
sys_setting = SystemSettings(panorama="192.168.254.1")
pa.add(sys)
sys.create()
pa.commit()

 

 

2 REPLIES 2

L2 Linker

Hi Armen,

i hope that the script below be useful to you:

#Import Modules:
from panos import base
from panos import firewall
from panos import panorama
from panos import policies
from panos import objects
from panos import network
from panos import device
import getpass

 

#Credentials
username = input('Admin: ')
password = getpass.getpass('Type your password: ')
device_name = input('Type Panorama address or name: ')

#You need to instanciate a panorama login object:
pano = panorama.Panorama(device_name, username, password)

#You can use the bellow script to pull all Templates:
templates_pan = panorama.Template.refreshall(pano)

#You can use the bellow script to pull all DeviceGroups from Panorama:
device_grp_pan = panorama.DeviceGroup.refreshall(pano)

 

 

#You will receive a list with Templates or Devicegroup python objects:
print(templates_pan)
print(device_grp_pan)

 

#Since that the objects are an iterable object, you can do a 'for' through each object in the list:
for template in templates_pan:
    '''You can use the "about" method to verify some Template parameters'''
    print(template.about())

 

#Since that the objects are an iterable object, you can do a 'for' through each object in the list:
for dg in device_grp_pan:
    '''You can use the "about" method to verify some Device-Group parameters'''
    print(dg.about())

 

#Once you have the template/device group, you can set a template/device-group that you want to configure:
template_definition = panorama.Template('Asimov_office_template')
pano.add(template_definition)
#Once you have the template/device group, you can set a template/device-group that you want to configure:
dg_definition = panorama.DeviceGroup('Asimov_office_dg')
pano.add(dg_definition)

 

Ok, from this point you can start push configuration to Template/Device Groups defined above:
#For example, lets push a network interface configuration:
interface_to_be_created = {'tag': 999, 
                           'ip': ['172.16.0.1/24'], 
                           'comment': 'Testing-Python', 
                           'name': 'ae1.999'}

interface_obj = network.Layer3Subinterface(**interface_to_be_created)
template_definition.add(interface_obj)
interface_obj.create()

L2 Linker

Talking about your script, follow:

 

from panos.panorama import Panorama
from panos.firewall import Firewall
from panos.device import SystemSettings

fw = Firewall("fw.mylab.com", "admin", "admin")
sys_setting = SystemSettings(panorama="192.168.254.1")
fw.add(sys_setting)
sys_setting.create()
fw.commit()
  • 3028 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!