PAN-OS SDK Device Group Hierarchy

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.

PAN-OS SDK Device Group Hierarchy

L4 Transporter

Is there a way to create device under a parent or move a device group using the sdk. 

Similar to Operational command:

> request move-dg dg1 new-parent-dg dg1_parent create-dg yes

 

I am aware of the dg_hierarchy opstate, which helps finding the device group, but how can I set the parent when creating a new group? 

DeviceGroup.create() method just places the new group under shared and this fails in cases of having depended objects on the parent device group. 

 

In the fist case I need to create a new group as member of parent device group. 

In the second case I want to "clone" device group with a new name under new parent. Any help how to do that? 

1 accepted solution

Accepted Solutions

L0 Member

Hi

 

You might already have found the answer but for any future searches.

Instead of using opcommands you can use the following code 

 

        newsite = DeviceGroup(site.SiteName)
        pano.add(newsite)
        newsite.create()
        newsite.opstate.dg_hierarchy.__setattr__('parent', site.Region)
        newsite.opstate.dg_hierarchy.update()

View solution in original post

3 REPLIES 3

L5 Sessionator

Hi @batd2, you can perform lots of operational tasks like this with op(), for example:

resp = panorama.op('<request><move-dg><entry name="new-dg"><new-parent-dg>home-dg</new-parent-dg></entry></move-dg></request>', xml=True, cmd_xml=False)
print(resp)

Ref: https://pan-os-python.readthedocs.io/en/latest/getting-started.html#operational-commands and https://pan-os-python.readthedocs.io/en/latest/module-base.html#panos.base.PanDevice.op

 

Hope that helps!

Help the community: "Like" helpful comments, and click "Accept as Solution" if you found your answer 🙂

L5 Sessionator

The GUI hides that creating a device group then moving it under the specified device group instead of "Shared" is a two-step process, but it is in fact a two step process.  There is device group hierarchy opstate stuff in place, just use the opstate namespace hanging off of your instance of the panos.panorama.DeviceGroup object along with the docs:

 

https://pan-os-python.readthedocs.io/en/latest/getting-started.html#the-opstate-namespace

https://pan-os-python.readthedocs.io/en/latest/module-panorama.html#panos.panorama.DeviceGroupHierar...

 

L0 Member

Hi

 

You might already have found the answer but for any future searches.

Instead of using opcommands you can use the following code 

 

        newsite = DeviceGroup(site.SiteName)
        pano.add(newsite)
        newsite.create()
        newsite.opstate.dg_hierarchy.__setattr__('parent', site.Region)
        newsite.opstate.dg_hierarchy.update()
  • 1 accepted solution
  • 2413 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!