REST API knowledge exchange
Post Reply
matteu
Veeam Legend
Posts: 1070
Liked: 176 times
Joined: May 11, 2018 8:42 am
Contact:

Nutanix Get Worker configuration Rest API

Post by matteu »

Hello,

I would like to be able to easly export the configuration of the Nutanix AHV workers.
I create this script and it works fine :

Code: Select all


$VBRServer = "10.254.250.100"


# ============================================================
# CONFIGURATION API
# ============================================================

$VBRPort = 9419

$VBRApiVersion = "1.3-rev1"

# UUID de l'extension Nutanix AHV Veeam
$NutanixExtensionId = "799a5a3e-ae1e-4eaf-86eb-8a9acc2670e2"
$AuthUrl = "https://${VBRServer}:${VBRPort}/api/oauth2/token"
$NutanixApiBase = "https://${VBRServer}/extension/$NutanixExtensionId/api/v10"

# ============================================================
# CERTIFICATS
# ============================================================

if ($IgnoreCertificate) {

    if ($PSVersionTable.PSVersion.Major -ge 7) {

        $script:InvokeRestParams = @{
            SkipCertificateCheck = $true
        }

    }
    else {
        Write-Warning "PowerShell 5.x détecté : désactivation de la validation TLS."

        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
        $script:InvokeRestParams = @{}
    }
}
else {

    $script:InvokeRestParams = @{}
}

# ============================================================
# AUTHENTICATION
# ============================================================

Write-Host ""
Write-Host "Connexion to Veeam Backup and Replication..." -ForegroundColor Cyan

$Credential = Get-Credential -Message "Veeam account"

$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credential.Password)

try {

    $Password = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($BSTR)

}
finally {
    [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR)
}

$AuthBody = @{

    grant_type = "password"
    username = $Credential.UserName
    password = $Password
}

$AuthHeaders = @{
    "x-api-version" = $VBRApiVersion
}

try {

    $TokenResponse = Invoke-RestMethod `
        @script:InvokeRestParams `
        -Uri $AuthUrl `
        -Method POST `
        -Headers $AuthHeaders `
        -Body $AuthBody `
        -ContentType "application/x-www-form-urlencoded"

}
catch {
    throw "Unable to authenticate to VBR : $($_.Exception.Message)"
}

$AccessToken = $TokenResponse.access_token

if (-not $AccessToken) {

    throw "No token received."
}

Write-Host "Authentification réussie." -ForegroundColor Green

# ============================================================
# HEADERS API NUTANIX
# ============================================================

$Headers = @{
    Authorization = "Bearer $AccessToken"
    Accept = "application/json"
}



# ============================================================
# PROCESS
# ============================================================


$Uri = "$NutanixApiBase/workers?limit=-1"
$Workers = Invoke-RestMethod -Uri $Uri -Method GET -Headers $Headers


$WorkerConfig = foreach ($Worker in $Workers.results) {

    $Config = $Worker.configuration

    foreach ($Network in $Config.networkSettings.networks) {

        [PSCustomObject]@{
            WorkerName            = $Config.name

            ClusterName           = $Config.clusterName
            StorageContainerId    = $Config.storageContainerId

            MaxConcurrentTasks    = $Config.maxConcurrentTasks
            CPU                   = $Config.cpuCount
            RAMGB                 = $Config.memoryGb

            HostAffinityEnabled   = $Config.affinitySettings.enabled
            AffinityHostId        = $Config.affinitySettings.hostId

            DNSAutomatic          = $Config.networkSettings.obtainDnsAutomatically
            DNSServers            = ($Config.networkSettings.dnsServers -join ", ")

            NetworkId             = $Network.networkId
            NetworkDescription    = $Network.description

            IPAutomatic           = $Network.obtainIpAutomatically
            IPAddress             = $Network.ipAddress
            SubnetMask            = $Network.subnetMask
            DefaultGateway        = $Network.defaultGateway

            Enabled               = $Worker.enabled
            Status                = $Worker.status
        }
    }
}

$WorkerConfig | Format-Table -AutoSize
Why the REST API show the clustername, the workername, but the StorageContainer and Host (when using host affinity) and network show only the ID ?
For some, there is a "name" property but the value is unknown like for network : (network ID: xxxxxxx-xxxxx-xxxxxx-xxxxx-xxxxxxxxxxx) where xxxx is the network ID

Thanks for your answer.

I know I can use RestAPI to retrieve the name from the ID, but I just try to understand why it's displayed correctly for some and not for others ?
It's maybe an improvment to make :)

Thanks for the answer.
david.domask
Product Manager
Posts: 3964
Liked: 962 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Nutanix Get Worker configuration Rest API

Post by david.domask »

Hi matteu,

I moved your topic to our REST API forum as it's really about the REST API endpoint.

Just to confirm, you're polling this endpoint correct? Strange because we don't document it returns ClusterName :)

I don't know off the top of my head why it is this way but agree the inconsistency is not great. Will discuss internally on this and ask look to get it more consistent.
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests