RSS .92| RSS 2.0| ATOM 0.3
  • Home
  •  

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

    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:

    
    get-ntnxdisk
    
    

    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 "$hardware.id" to the array"
       $array += $hardware.id
    }
    

    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

    Container

    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 $newStoragePool.id -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 "$hardware.id" to the array"
       $array += $hardware.id
    }
    
    write-host "Creating a new storage: $storagePool"
    new-NTNXStoragePool -name $storagePool -disks $array
    $newStoragePool=get-NTNXStoragePool
    
    write-host "Creating container: $containerName"
    new-NTNXContainer -storagepoolid $newStoragePool.id -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.

    Leave a Reply

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