RSS .92| RSS 2.0| ATOM 0.3
  • Home

    Nutanix and Powershell – Automating Nutanix Cluster Operations

    September 3rd, 2014

    This blog post details the use of the mega awesome Nutanix Powershell cmdlets to conduct, what in essence, are one-time operations to configure a Nutanix cluster.

    We will cover operations to define DNS, NTP and SMTP servers and re-use code from a previous blog post to create a Storage Pool and Container.

    We are going to leverage the following Nutanix Powershell cmdlets:

    • get-NTNXnameServer
    • remove-NTNX-nameServer
    • add-NTNXnameServer
    • get-NTNXntpServer
    • remove-NTNXntpServer
    • add-NTNXntpServer
    • remove-NTNXsmtpServer
    • set-NTNXsmtpServer
    • get-NTNXdisk
    • new-NTNXstoragePool
    • new-NTNXcontainer
    • add-NTNXnfsDatastore
    • set-NTNXcluster

    Pretty easy really.  One option that stands out is the Nutanix Pulse verbosity level.  We can configure the following levels:

    • None
    • All
    • Basic
    • Basic-Coredump

    This defines the levels you, and Nutanix support, will receive describing platform status.

    ### [ Variable Definition ] ###
    # define DNS servers
    $nameServer1 = ""
    $nameServer2 = ""
    # define NTP servers
    $ntpServer1 = ""
    $ntpServer2 = ""
    # define SMTP settings
    $smtpServer = ""
    $smtpPort = "25"
    $smtpFromAddress = "email [at]"
    # define Storage parameters
    $storagePool = "SP1"
    $containerName = "NTNX-container001"
    # Pulse verbosity type
    $pulseLevel = "ALL"
    ### [ Main ] ###
    ## set DNS servers ##
    if( ($nameServer1.length -gt 0) -and ($nameServer2.length -gt 0) ) {
       # clean up old records
       [void](get-NTNXnameServer | remove-NTNXnameServer)
       write-host "Adding DNS servers: "$nameServer1","$nameServer2
       [void](add-NTNXnameServer -input $nameServer1)
       [void](add-NTNXnameServer -input $nameServer2)
    } else {
       write-host "Adding DNS server: "$nameServer1
       [void](add-NTNXnameServer -input $nameServer1)
    ## set NTP servers ##
    if( ($ntpServer1.length -gt 0) -and ($ntpServer2.length -gt 0) ) {
       # clean up old records
       [void](get-NTNXntpServer | remove-NTNXntpServer)
       write-host "Adding NTP servers: "$ntpServer1","$ntpServer2
       [void](add-NTNXntpServer -input $ntpServer1)
       [void](add-NTNXntpServer -input $ntpServer2)
    } else {
    write-host "Adding NTP server: "$ntpServer1
       [void](add-NTNXntpServer -input $ntpServer1)
    ## set SMTP server ##
    if( $smtpServer -gt 0) {
       #clean up old records
       write-host "Adding SMTP server: "$smtpServer
       [void](set-NTNXsmtpServer -address $smtpServer -port $smtpPort -fromEmailAddress $smtpFromAddress)
    ## create Storage ##
    $array =@()
    (get-ntnxdisk) |% {
       $hardware = $_
       write-host "Adding disk "$" to the array"
       $array += $
    write-host "Creating a new storage: $storagePool"
    new-NTNXStoragePool -name $storagePool -disks $array
    write-host "Creating container: $containerName"
    new-NTNXContainer -storagepoolid $ -name $containerName
    sleep 3
    write-host "Adding container $containerName to ESXi hosts"
    add-NTNXnfsDatastore -containerName $containerName
    ## set Pulse verbosity level ##
    write-host "Setting Pulse verbosity level to: "$pulseLevel
    [void](set-NTNXcluster -supportVerbosityType $pulseLevel)

    Nutanix+Powershell – Provision a StoragePool, Container and Mount Datastore in Seconds

    August 19th, 2014

    The Nutanix platform is consistently iterating and adding quality new features with every release.

    Nutanix has released Powershell cmdlets with NOS version 4.0+.  This post will describe using said cmdlets to create a storage pool and container(s).

    A full brain dump of the Nutanix plaform can be found at the Nutanix Bible, and the data structure section in particular.

    Storage Pool

    On the storage side of the Nutanix platform, each node consists of X SSD and Y magnetic spinning disks.  Nutanix best practice states that 1, and only 1, Storage Pool be created per Nutanix cluster.  A Storage Pool encapsulates all disks on each node of the cluster.

    That being said, let’s dig in to what is required to automagically provision a storage pool and container on top!

    A requirement to create a storage pool, as described above, is to list and capture all disks available.  To do that, we leverage the get-ntnxdisk cmdlet:


    The output will be similar to:

    id : 43
    serviceVMId : 4
    lastServiceVMId : 0
    mountPath : /home/nutanix/data/stargate-storage/disks/BTTV333505WZ400HGN
    diskSize : 179289518899
    storageTierName : SSD-SATA
    storagePoolId :
    hostName : <redacted>
    cvmIpAddress : <redacted>
    clusterUuid : <redacted>
    markedForRemoval : False
    dataMigrated : False
    online : True
    diskStatus : NORMAL
    location : 1

    There will obviously be more disks.  We are looking for the value of id, and want to add them to an array:

    $array =@()
    (get-NTNXdisk) |% {
       $hardware = $_
       write-host "Adding disk "$" to the array"
       $array += $

    We want to define a storage pool and container name:

    $storagePool = "SP1"
    $containerName = "NTNX-container001"

    Now let’s have some fun and create the storage pool:

    write-host "Creating a new storage pool: $storagePool"
    new-NTNXStoragePool -name $storagePool -disks $array
    # save the storagePool object for use with Container
    $newStoragePool = get-NTNXStoragePool

    At this point, if you browse to the Prism UI you will see our brand new storage pool called SP1.  You can also evaluate $newStoragePool


    In Nutanix land, a container is a logical segmentation of a Storage Pool, and is represented to the Hypervisor as a datastore.

    write-host "Creating container: $containerName"
    new-NTNXContainer -storagepoolid $ -name $containerName

    We just prepared an object that will be mounted as a datastore on the Hypervisors.  That quickly.  If you stop and think for a second, provisioning storage in a traditional three-tier architecture can take hours (creation of LUN, zoning, etc etc) and is fraught with errors.

    We are now going to mount the newly created container to the Hypervisors:

    write-host "Adding container $containerName to ESXi hosts"
    add-NTNXnfsDatastore -containerName $containerName

    Look at your VI Client.  The datastores are all mounted!  Bang!  That fast.  The Power of the Nutanix platform.


    To put it all together:

    $storagePool = "SP1"
    $containerName = "NTNX-container001"
    $array =@()
    (get-ntnxdisk) |% {
       $hardware = $_
       write-host "Adding disk "$" to the array"
       $array += $
    write-host "Creating a new storage: $storagePool"
    new-NTNXStoragePool -name $storagePool -disks $array
    write-host "Creating container: $containerName"
    new-NTNXContainer -storagepoolid $ -name $containerName
    sleep 3
    write-host "Adding container $containerName to ESXi hosts"
    add-NTNXnfsDatastore -containerName $containerName

    (NOTE) I added a 3 tick sleep to make sure the new-NTNXContainer command had time to complete on the back end.

    Consuming Nutanix PrismAPI with Powershell – Display information about CVM

    March 19th, 2014

    A customer recently asked how to list the IP address of the Nutanix CVM (Controller Virtual Machine).

    I have already blogged how to consume the PrismAPI with vCenter Orchestrator.  This time we will use Powershell.

    PrismAPI exposes a whole bunch of awesome data.  In particular the /hosts/ endpoint is what we need:


    It will respond with:

    “entities”: [
    “serviceVMId”: 10,
    “name”: “NTNX-<redacted>-D”,
    “serviceVMExternalIP”: “192.168.2.”,
    “hypervisorAddress”: “192.168.2.”,

    But in reality, it will be one gigantic string/array blob.

    The following code will connect to your block, query the data and respond with the serviceVMid, CVM name, CVM IP and hypervisor IP.  Note: You will need Powershell 4.0 for the invoke-restmethod.

    Be sure to enter proper data to the <FILL THIS IN> sections.  Have fun!

    add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
    public bool CheckValidationResult(
    ServicePoint srvPoint, X509Certificate certificate,
    WebRequest request, int certificateProblem) {
     return true;
    [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
    #declare an array to be used later
    $array = @()
    $Uri = "https://:9440/PrismGateway/services/rest/v1/hosts/"
    $username = ""
    $password = ""
    $Header = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+":"+$password ))}
    $results = Invoke-RestMethod -Method Get -Uri $Uri -Headers $Header
    # grab the results of the entity section
    ($results.entities) |%{
    # set the output of the foreach to the $array var
    $array = $_
    #iterate through the array
    ($array) | %{
    write-host "`nname:"$ "`n serviceID:"$array.serviceVMid "`n externalIP:"$array.serviceVMExternalIP "`n hypervisorAddress:"$array.hypervisorAddress"`n"

    Connecting to the Nutanix PrismAPI with vCenter Orchestrator

    March 3rd, 2014

    REST API are fun to consume!  JSON is fun to consume and use!  vCenter Orchestrator is fun to use, and act as a consumer of data!

    Now that I work for Nutanix let us investigate different ways to consume the platform’s API!

    Editor’s note:  This will hopefully end up being a series of posts.  The post is a bit of a homage to content produced by other people:

    • Jason Langone’s series
    • Andre Leibovici’s posts via on the Nutanix API, and using PowerCLI (multiple)
    • Josh Gray’s series of posts on about using vCO to do many cool things

    Special blog-style shout-out to Sasha Armstrong for granting me access.

    Read them all.  There is great content available.

    Editor’s note #2: This post assumes a working installation of vCenter Orchestrator with the HTTP REST plugin imported and available.  The bits can be found at your local VMware download site.


    • URL of your Nutanix PrismAPI endpoints
    • username and password
    • Most likely an open window pointing at the Rest API Explorer Live! page of your Nutanix endpoint (can be found by dropping-down next to your user name and selecting)

    Add a REST host

    First we need to add a REST host endpoint to vCO.

    1. Under the Run view, select the Workflows widget.
    2. Expand Library -> HTTP-Rest -> Configuration folders
    3. Right click on Add a REST host and select Start Workflow
    4. Enter something usable under the Name field (note this helps identify your REST endpoint if you have multiple.  So entering foo is not advised)
    5. Enter the URL, including http(s) and/or port (if non-standard) as required.  example:
    6. Click Next.
    7. Select the appropriate Bool value for Proxy settings, and enter specifics, if necessary.  Click Next.
    8. Select Basic from the Host Authentication drop-down.
    9. Use Shared session mode.
    10. Enter a username and password that has permissions to authenticate to the Nutanix PrismAPI and click Submit.

    Hopefully at that point you have a successful connection to the host.  If a failure was generated, re-run the workflow and fix the errors.

    Part 2 will cover building a workflow and consuming the bulk data output from the PrismAPI.

    Part 3 will cover consuming the data, and in this case displaying values from Nutanix Protection Domains.