Samples/E2E-hub-devices/common/hubCommon.ps1

# ------------------------------------------------------------------
# Lenovo Copyright
#
# (C) Copyright Lenovo 2026 - present.
#
# LIMITED AND RESTRICTED RIGHTS NOTICE:
# If data or software is delivered pursuant a General Services
# Administration (GSA) contract, use, reproduction, or disclosure
# is subject to restrictions set forth in Contract No. GS-35F-05925.
# ------------------------------------------------------------------

$hubName = "hub_01"

function AddHub()
{
    [CmdletBinding()]
    param (
    [Parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    $HubIP,

    [Parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [pscredential]$HubCredential
    )

    $hubResult = Add-LXC1Manager `
                          -HubName $hubName `
                          -HubCountryCode RO `
                          -HubCredential $HubCredential `
                          -HubAddress $HubIP `
                          -HubPort 443

    if($hubResult -eq "Hub '$HubIP' added successfully.")
    {
        do {
            $managers = Get-LXC1Managers -Name $hubName
            if ($managers.Response.results.Count -eq 0)
            {
                Write-Host ("Waiting for the hub '{0}' to be available in portal ..." -f $hubName)
                Start-Sleep -Seconds 3
            }
        } while ($managers.Response.results.Count -eq 0)    
        return $true
    }
    else
    {
        return $false
    }
}

function GetHubID()
{
    $managers = Get-LXC1Managers -Name $hubName
    return ($managers.Response.results[0].id)
}

function RemoveHub()
{
    $manager = Get-LXC1Managers -Name $hubName
    $result = Remove-LXC1Manager -ManagerID $manager.Response.results[0].id
    return $result
}

# EOF