WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Uncategorized / Exploring the vCloud Networking & Security API Using Ruby

Exploring the vCloud Networking & Security API Using Ruby

02.25.2013 by William Lam // 2 Comments

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:

  • ruby (I used the latest release which is 1.9.3)
  • ruby gem
  • httparty
  • libxml
  • yaml

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:

  • http://blogs.vmware.com/security/2011/11/using-the-vshield-api.html

More from my site

  • Exploring the vCloud API Using Ruby
  • How To Quickly Get Started With The New VMware Puppet Modules
  • Using the New vCloud Networking and Security to Load Balance Multiple vSphere Web Client Servers
  • Is there a vSphere REST API for ...
  • Getting Started with the Application Transformer for VMware Tanzu REST API

Categories // Uncategorized Tags // httparty, REST API, ruby, vcns, vshield

Comments

  1. *protectedUnknown says

    10/10/2013 at 7:30 pm

    Hi William,Thx for sharing but Both .rb files can't be found on http://sourceforge.net/p/vghetto/code/HEAD/tree/
    Regards,
    Tomasa

    Reply
    • *protectedWilliam Lam says

      10/10/2013 at 7:43 pm

      Links fixed, looks like sourceforge updated their URLs

      Reply

Thanks for the comment!Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025
  • vCenter Identity Federation with Authelia 04/16/2025
  • vCenter Server Identity Federation with Kanidm 04/10/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025