«

»

Feb 11

Automatically Deploy NSX and Connect to vCenter

Screenshot 2015-02-11 11.01.35

In playing around in my home lab I’ve been automating the deployment and configuration of each of the vCloud Suite products. This time was NSX’s turn. The deployment itself is quite simple as of the PowerCLI 5.8 r1 release that allows us to import OVA’s with a pre-populated configuration.

Once NSX is imported into vCenter it’s just a matter of Powering it on, waiting for the VM to initialize completely, then running the REST command to connect NSX Manager to vCenter. Simple enough? let’s take a look.

Script in Action

There are some properties that need to be set within the script prior to running it. (*Note: I could have made it prettier but it took care of my immediate needs. I may come back around and specify more variables and set variable placeholders in the rest of the script where I’ve hard-coded some. Don’t hate…)

You’ll need to place correct values in all of the variables here at the top, including in OVFConfig, and lastly the host on the import-vapp line. Then you’ll be good to go.

Assuming you’ve already connected your PowerCLI session to vCenter, go ahead and run the script. It will begin importing the OVA.

Screenshot 2015-02-11 10.53.40

Once NSX has been imported, it will power-on. The script waits to see that VMTools is running before it says it has booted up successfully. We still have to wait for the REST page to initialize though, so we tackle that issue next.

Screenshot 2015-02-11 10.56.39

Once we receive the StatusCode “200” we know that we can proceed. in which case we go ahead and run our REST command to connect NSX Manager to vCenter.

Screenshot 2015-02-11 11.01.35

Once we receive the “Done!” line on our script we can login to NSX Manager and see that vCenter is connected and from here we can either script more of the NSX tasks leveraging the NSX API Guide, or do it through the web client.

Screenshot 2015-02-11 11.02.40

You can find the script on my Github page HERE:

2 comments

  1. Munish

    When I am running the script in my lab. I am able to deploy NSX Manager however when registering NSX Manager with vCenter I am getting following error

    PowerCLI C:scripts> .connectvc01.ps1
    Attempting to connect NSX Manager to vCenter
    Invoke-RestMethod : The remote server returned an error: (403) Forbidden.
    At C:scriptsconnectvc01.ps1:38 char:1
    + Invoke-RestMethod -Uri $uri -Method Put -Headers $header -ContentType …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
    eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

    1. Brian Graf

      I will have to try deploying when I return home. Can you post your vCenter version, PowerShell and PowerCLI versions, and NSX version you are using?

      Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

4 + seven =