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

    Nutanix and Powershell – Automating Nutanix Cluster Operations

    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 = "192.168.1.53"
    $nameServer2 = "192.168.2.53"
    
    # define NTP servers
    $ntpServer1 = "192.168.1.123"
    $ntpServer2 = "192.168.2.123"
    
    # define SMTP settings
    $smtpServer = "192.168.1.25"
    $smtpPort = "25"
    $smtpFromAddress = "email [at] domain.com"
    
    # define Storage parameters
    $storagePool = "SP1"
    $containerName = "NTNX-container001"
    
    # Pulse verbosity type
    # Options: BASIC, BASIC-COREDUMP, ALL, NONE
    $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
       [void](remove-NTNXsmtpServer)
    
       write-host "Adding SMTP server: "$smtpServer
       [void](set-NTNXsmtpServer -address $smtpServer -port $smtpPort -fromEmailAddress $smtpFromAddress)
    }
    
    ## create Storage ##
    $array [email protected]()
    
    (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
    
    ## set Pulse verbosity level ##
    write-host "Setting Pulse verbosity level to: "$pulseLevel
    [void](set-NTNXcluster -supportVerbosityType $pulseLevel)
    
    

    Leave a Reply

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