通过iControl PowerShell管理单元

时间:2016-10-21 16:22:53

标签: powershell f5 icontrol

我们通过PowerShell iControl管理单元自动更改备用F5 LTM主机。

我们希望在自动化进行任何更改之前,以编程方式检查待机和实时F5主机之间是否有待更改。

有没有办法通过iControl管理单元或API检查挂起的更改?

1 个答案:

答案 0 :(得分:0)

我在iControl wiki中找到了答案。 get_sync_status_overview()方法“获取当前设备在其所属的所有设备组中的状态”

Wiki参考: https://devcentral.f5.com/wiki/iControl.Management__DeviceGroup__SyncStatus.ashx

我在PowerShell中编写了以下函数,其他人在尝试相同类型的操作时可能会觉得有用。 如果设备是独立的或与其组中的设备同步,它将返回true,如果F5主机上的更改需要同步到组并在所有其他情况下抛出错误,它将返回false:

function Is-DeviceInSync
{
    <#
    .SYNOPSIS
    Gets the sync status of F5 devices within the device group
    #>

    $syncStatus = (Get-F5.iControl).ManagementDeviceGroup.get_sync_status_overview()

    if ($syncStatus.member_state -eq "MEMBER_STATE_STANDALONE")
    {
        write-host "This F5 device is standalone, no sync is required"
        return $true
    }
    elseif ($syncStatus.member_state -eq "MEMBER_STATE_IN_SYNC")
    {
        write-host "This F5 device is in sync with members of its device group, no sync is required"
        return $true
    }
    elseif ($syncStatus.member_state -eq "MEMBER_STATE_NEED_MANUAL_SYNC")
    {
        write-host "This F5 device is not standalone and changes have been made to this device that have not been synced to the device group"
        return $false
    }
    elseif ($syncStatus.member_state -eq "MEMBER_STATE_SYNCING")
    {
        write-host "This F5 device is currently synching with devices in it's group, waiting 10 seconds before checking again..."
        Start-Sleep -Seconds 10
        Is-DeviceInSync
    }
    else
    {
        throw "This F5 device is not in a stable sync state with devices in it's group, please manually verify the sync state of this device before running this script again"
    }
}

注意:此函数假定Initialize-F5.iControl函数已运行且用户已经过F5主机验证