In my previous article I demonstrated how you can easily use Ruby and the HTTParty Gem to access the vCloud API. As mentioned at the end of the article I also performed a similar exercise for the vCloud Networking and Security API and here is the sample Ruby script I reated called vcns.rb.
Before getting started, you will need to have the following installed on your system:
You will also need to access to a vCloud Networking and Security 5.x environment to use this script. To begin, create a file called config-vcns.yml which contains the credentials to your vCNS system and will be used to login. Here is what the file should look like the following:
:username: admin
:password: default
:site: https://vcns.primp-industries.com
The script provides the following output:
- vCNS Configuration
- vCNS Edge Gateway(s) Details
- Syslog Service Details
- HA Service Details
- Firewall Service Details
- DNS Service Details
- SSL-VPN Service Details
- IPSec Service Details
- DHCP Service Details
- NAT Service Details
- Load Balancer Service Details
Here is a screenshot of running the vcns.rb script:
As you can see, you can easily implement any of the features provide from the vCloud Networking and Security API, with some basic knowledge of how the API works (of course the documentation examples help too!). To further demonstrate this, I thought for kicks and giggles, I would take a part of the script and apply it to another language, this time using PowerShell (yep, you heard right!).
Luckily, it turns out my colleague Alan Renouf already wrote an awesome little PowerShell module for vShield (vCNS) awhile back. With some knowledge of the vCNS API, it was trivial to add a new command called get-vShieldEdge which Alan did not have that would list all the vCNS Edge Gateways that have been deployed.
Here is what the the code looks like in Ruby:
Here is what the code looks like for PowerShell:
Minus the language syntax, it looks pretty similar right? Both Ruby and PowerShell are accessing the same vCNS API. As long as you know how the API works, it is pretty easy to switch between programming/scripting languages.
To show the above code works, here is screenshot using the new get-vShieldEdge command:
If you are interested in further automation of vCNS, I would highly recommend you take a look at the vCloud Networking and Security API Programming Guide.
Useful Resources:
Unknown says
Hi William,Thx for sharing but Both .rb files can't be found on http://sourceforge.net/p/vghetto/code/HEAD/tree/
Regards,
Tomasa
William Lam says
Links fixed, looks like sourceforge updated their URLs