vCloud API and PowerCLI – Import/Export vShield Edge NAT rules
Post
Cancel

vCloud API and PowerCLI – Import/Export vShield Edge NAT rules

In a previous post I wrote about exporting and importing firewall rules from vShield Edges using the vCloud API and PowerCLI.  I also needed to be able to do the same with the NAT rules but for some reason I couldn’t get access to them in PowerCLI like I did with the firewall rules. I had to get it straight from the vCloud API which meant querying out the XML representation of the rules and processing that. Thankfully Powershell makes it really easy to deal with the returned XML so I could cycle through it rule by rule and export it to a CSV file.

The same caveat applies to this as it did the firewall rule script…  What follows is the result of conversations/inspiration from the VMTN forums (specifically this thread), lots of reading of the vCloud API spec and copious amount of trial and error. I’m by no means a programmer so I apologise if my code offends anyone, but it did the job for me so hopefully can help someone else. I’m by no means a programmer so I apologise if my code offends anyone, but it did the job for me so hopefully can help someone else.

Run the scripts from a PowerCLI session that is already logged onto the vCloud Director instance you want to work with (i.e. do a “Connect-CIServer -server url“)

Export Script

Run the script passing the following parameters:

  • -file or -f = The CSV file to export rules to
  • -edge or -e = The Edge Gateway Name

As an example:
./export-vse-nat-rules.ps1 -f mynatrules.csv -e “My vShield Edge”

Import Script

Usage for the import script is the same as the export script. You could easily specify a different vShield Edge to import the rules to or even connect to a different vCloud Director instance first. If you just want to import a load of rules (perhaps the vShield Edge is replacing another FW) you could quite easily make up your own CSV file in the same format and use this script to import it.

Run the script passing the following parameters:

  • -file or -f = The CSV file containing the rules to import
  • -edge or -e = The Edge Gateway Name

As an example:
./import-vse-nat-rules.ps1 -f mynatrules.csv -e “My vShield Edge”

This post is licensed under CC BY 4.0 by the author.