简体   繁体   English

使用 Azure Cli 或 Azure REST Azure 禁用 AFD 后端池的后端主机

[英]Disable AFD Backend Pool's Backend Host with Azure Cli or Azure REST API

Im trying to update an existing backend host of a AFD backend pool to have its status from Enabled to Disabled .我正在尝试更新 AFD 后端池的现有后端主机,使其状态从Enabled变为Disabled

Is there a way to update existing backend host of Front Door backend pools?有没有办法更新 Front Door 后端池的现有后端主机?

currently, i can only see add , list and remove in the following azure front door cli docs :目前,我只能在以下azure 前门 cli 文档中看到addlistremove

  • az network front-door backend-pool backend add
  • az network front-door backend-pool backend list
  • az network front-door backend-pool backend remove

Is there one for update ?update的吗?

I've also looked into the Azure REST API docs and have not found an endpoint to update a backend host of AFD backend pools.我还查看了Azure REST API 文档,并没有找到更新 AFD 后端池后端主机的端点。

天蓝色前门更新后端

I was able to resolve my issue, the below script requires using azure cli with a logged in service principle.我能够解决我的问题,以下脚本需要使用 azure cli 和登录服务原则。

Param(
  [string]$desiredState, #"Enabled" or "Disabled"
  [string]$frontDoorName,
  [string]$resourceGroupName,
  [string]$targetBackendPool,
  [string]$targetBackendHost
)

# Get Access Token
$token = az account get-access-token | ConvertFrom-Json
$accessToken = $token.accessToken
$subscriptionId = $token.subscription
$tenantId = $token.tenant

$uri = "https://management.azure.com/subscriptions/$($subscriptionId)/resourceGroups/$($resourceGroupName)/providers/Microsoft.Network/frontDoors/$($frontDoorName)?api-version=2019-05-01"
$headers = @{ "Authorization" = "Bearer $accessToken" }
$contentType = "application/json"

# Get AFD Configuration.
Write-Host "Invoking Azure REST API to get AFD configuration"
$afdConfig = Invoke-WebRequest -method get -uri $uri -headers $headers | ConvertFrom-Json

# Edit AFD Configuration to toggle backend host state
Write-Host "Checking BackendHost: $targetBackendHost In Backend Pool: $targetBackendPool"

foreach ($backendPool in $afdConfig.properties.backendPools) {
    if ($backendPool.name -eq $targetBackendPool) {
        foreach ($backends in $backendPool.properties.backends) {
            if ($backends.address -eq $targetBackendHost) {
                $currentState = $backends.enabledState
                Write-Host "Current State of $targetBackendHost is $currentState"
                if ($currentState -eq $desiredState) {
                    Write-Host "$targetBackendHost is already in the desired state of $desiredState"
                    exit
                }
                $backends.enabledState = $desiredState
                Write-Host "$targetBackendHost Updated to $desiredState."
           }
        }
    }
}

$updateRequest = $afdConfig | ConvertTo-Json -Depth 100

# Update AFD Configuration.
Write-Host "Invoking Azure REST API to update AFD configuration"
Invoke-WebRequest -method put -uri $uri -headers $headers -ContentType $contentType -body $updateRequest

# Poll current state until the change has been fully propogated in azure
Write-Host "Polling AFD until update is complete."
do {
    $afdConfig = Invoke-WebRequest -method get -uri $uri -headers $headers | ConvertFrom-Json

    foreach ($backendPool in $afdConfig.properties.backendPools) {
        if ($backendPool.name -eq $targetBackendPool) {
            foreach ($backends in $backendPool.properties.backends) {
                if ($backends.address -eq $targetBackendHost) {
                    $currentState = $backends.enabledState
                }
            }
        }
    }
    Write-Host "$targetBackendHost is currently in $currentState"
    Start-Sleep -Seconds 1
} until ($currentState -eq $desiredState)

Write-Host "$targetBackendHost has successfully been updated to $desiredState"

I am able to achieve your ask using PowerShell.我可以使用 PowerShell 来满足您的要求。

Here is the script:这是脚本:

$resourceGroup1 = "frontdoor" $frontDoor1 = "msrini" $resourceGroup1 = "前门" $frontDoor1 = "msrini"

$afd = Get-AzFrontDoor -ResourceGroupName $resourceGroup1 -name $frontDoor1 $afd = 获取-AzFrontDoor -ResourceGroupName $resourceGroup1 -name $frontDoor1

$loadBalancingSetting1=$afd.LoadBalancingSettings $loadBalancingSetting1=$afd.LoadBalancingSettings

$afd.BackendPools.backends[0].EnabledState = "Disabled" $afd.BackendPools.backends[0].EnabledState = "已禁用"

$backendpool1=$afd.BackendPools $backendpool1=$afd.BackendPools

$frontendEndpoint1 = $afd.FrontendEndpoints $frontendEndpoint1 = $afd.FrontendEndpoints

$healthProbeSetting1= $afd.HealthProbeSettings $healthProbeSetting1= $afd.HealthProbeSettings

$routingrule1 = $afd.RoutingRules $routingrule1 = $afd.RoutingRules

$backendpoolsettings1 = $afd.BackendPoolsSetting $backendpoolsettings1 = $afd.BackendPoolsSetting

Set-AzFrontDoor -Name $frontDoor1 -ResourceGroupName $resourceGroup1 -RoutingRule $routingrule1 -BackendPool $backendpool1 -FrontendEndpoint $frontendEndpoint1 -LoadBalancingSetting $loadBalancingSetting1 -HealthProbeSetting $healthProbeSetting1 -BackendPoolsSetting $backendpoolsettings1 Set-AzFrontDoor -Name $frontDoor1 -ResourceGroupName $resourceGroup1 -RoutingRule $routingrule1 -BackendPool $backendpool1 -FrontendEndpoint $frontendEndpoint1 -LoadBalancingSetting $loadBalancingSetting1 -HealthProbeSetting $healthProbeSetting1 -BackendPoolsSetting $backendpoolsettings1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Creating DataBricks Azure Key Vault Secret Scope Backend using Rest Api and DataBricks CLI - Creating DataBricks Azure Key Vault Secret Scope Backend using Rest Api and DataBricks CLI Azure CLI - 如何显示 API 的操作后端(HTTPs 端点)信息 - Azure Cli - How to show API's operation backend (HTTPs endpoint) infos 如何在 azure 中保护后端到后端 api 消耗 - How to secure backend to backend api consumption in azure Azure应用程序网关将“/ *”转发到后端池 - Azure Application Gateway forwarding “/*” to Backend Pool 使用ip作为后端池地址的Azure前门,其中自定义主机标头返回503 - Azure Front Doors with ip as backend pool addresses with custom host header returning 503 带有私有 Api 后端的 Azure WebApp - Azure WebApp with private Api backend Azure API 后端服务 URL - Azure API backend service URL 在 Azure 上部署 Angular 后端 API - Deploy Angular Backend API on Azure 如何禁用对Azure RESTful服务的后端访问? - How to disable backend access to Azure RESTful services? Azure API 管理和后端 Web API - Azure API Management and Backend Web API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM