Creating a Vsys/VR via CLI

L2 Linker

Creating a Vsys/VR via CLI

Does anyone have a script or a way to implement a new virtural firewall and virtual router via the cli? Does not have to be automatic but would like to get to that point? I have a couple dozen to implement and looking for a quicker way vs via gui.

Thank you

David

L1 Bithead

Re: Creating a Vsys/VR via CLI

@dwmaas are you still looking for this? I have been working on a script to create full tenants via vsys creation and could share that portion of the script if you're still looking

L2 Linker

Re: Creating a Vsys/VR via CLI

Hi,

Yes still looking, just dropped down in priorty on my list. But that would be fantastic if you could share what you have.

Thank you

David

L4 Transporter

Re: Creating a Vsys/VR via CLI

Why use CLI?  If you're going for automation, API is usually a much better option.  You could use any of our API libraries to do this quickly.  Here's an example using the Palo Alto Networks Device Framework:

 

from pandevice import firewall, device

fw = firewall.Firewall('10.0.1.1', 'admin', 'password', vsys=None)

fw.add(device.Vsys('vsys2', 'My New Vsys1')).create()
fw.add(device.Vsys('vsys3', 'My New Vsys2')).create()
fw.add(device.Vsys('vsys4', 'My New Vsys3')).create()
fw.add(device.Vsys('vsys5', 'My New Vsys4')).create()

fw.commit()

That creates 4 vsys on the firewall.  If you need vsys each with their own virtual router you'd do something like this:

 

from pandevice import firewall, network, device

fw = firewall.Firewall('10.0.1.1', 'admin', 'password', vsys=None)

vr2 = fw.add(network.VirtualRouter('vsys2-vr')
vsys2 = fw.add(device.Vsys('vsys2', 'My New Vsys2'), virtual_routers=[vr2])

vr2.create()
vsys2.create()

fw.commit()

That would give you a new virtual router in a new vsys.

 

More information:

https://live.paloaltonetworks.com/deviceframework
http://pandevice.readthedocs.io/en/latest/usage.html#working-with-virtual-system
http://pandevice.readthedocs.io/en/latest/module-device.html#pandevice.device.Vsys

L1 Bithead

Re: Creating a Vsys/VR via CLI

@btorresgil This is why it's nice to see others work sometimes. I had a very similar thing to part two I was going to share, but I was defining my variable, then adding it in another line and then creating it in another line. I hadn't even thought about that I could be slimming it down to one line for the add and create!

L2 Linker

Re: Creating a Vsys/VR via CLI

Thank you very much, this would work out super, we do what to automate the entire vsys/vr and bgp router configs. So it is not done manually.

 

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 Live Community as a whole!

The Live Community thanks you for your participation!