是否可以通过管理/资源管理API为Azure网站启用Always On?

时间:2014-11-05 11:55:51

标签: api rest azure azure-web-sites alwayson

我正在为Azure网站的自动部署编写一些代码(包括在Azure中创建网站)。我使用Nuget中提供的Azure管理库和Azure资源管理库。大部分已经到位,但是我无法找到一种方法来启用" Always On"通过我见过的任何API获得财产。可以通过网站的“配置”选项卡下的azure管理门户设置此属性。

我已经查过:

  1. MSDN上的属性参考:http://msdn.microsoft.com/en-us/library/azure/dn236426.aspx
  2. powershell API(get-azureresource,get-azurewebsite,...),看看是否有对Always On的引用(那里没有)
  3. REST通过Fiddler调用管理门户。这里有一个对POST的始终开启的引用https://manage.windowsazure.com/Websites/UpdateConfig(据我所知,它不是管理或资源管理API的一部分)。 JSON主体中发送的确切路径是/ siteConfig / AlwaysOn。
  4. 所以,问题是,是否可以通过"官方"启用/禁用Always On? API?

    谢谢!

3 个答案:

答案 0 :(得分:11)

我相信我找到了解决方案!

使用资源管理API,我可以通过siteConfig对象设置AlwaysOn属性。在powershell中:

Set-AzureResource -ApiVersion 2014-04-01 -PropertyObject @{"siteConfig" = @{"AlwaysOn" = $false}} -Name mywebsite -ResourceGroupName myrg -ResourceType Microsoft.Web/sites

在.NET中的资源管理API中,它与此类似。

生成的REST调用 https://management.azure.com/subscriptions/xxx/resourcegroups/yyy/providers/Microsoft.Web/sites/zzz?api-version=2014-04-01 { "location": "West Europe", "properties": { "siteConfig": { "AlwaysOn": true } }, "tags": {} }

答案 1 :(得分:2)

使用更新的ARM(Azure资源管理器)Powershell,v1.0 +

Get-AzureRmResource:https://msdn.microsoft.com/en-us/library/mt652503.aspx

Set-AzureRmResource:https://msdn.microsoft.com/en-us/library/mt652514.aspx

# Variables - substitute your own values here
$ResourceGroupName = 'My Azure RM Resource Group Name'
$WebAppName = 'My Azure RM WebApp Name'
$ClientAffinityEnabled = $false

# Property object for nested, not exposed directly properties
$WebAppPropertiesObject = @{"siteConfig" = @{"AlwaysOn" = $true}}

# Variables
$WebAppResourceType = 'microsoft.web/sites'

# Get the resource from Azure (consider adding sanity checks, e.g. is $webAppResource -eq $null)
$webAppResource = Get-AzureRmResource -ResourceType $WebAppResourceType -ResourceGroupName $ResourceGroupName -ResourceName $WebAppName

# Set a directly exposed property, in this case whether client affinity is enabled
$webAppResource.Properties.ClientAffinityEnabled = $ClientAffinityEnabled

# Pass the resource object into the cmdlet that saves the changes to Azure
$webAppResource | Set-AzureRmResource -PropertyObject $WebAppPropertiesObject -Force

答案 2 :(得分:0)

对于那些使用.Net API的人来说,它是

var cfg = await websiteClient.Sites.GetSiteConfigAsync(site.ResourceGroup, site.Name, cancellationToken).ConfigureAwait(false);
if (!cfg.AlwaysOn.GetValueOrDefault())
{
    cfg.AlwaysOn = true;
    await websiteClient.Sites.UpdateSiteConfigAsync(site.ResourceGroup, site.Name, cfg, cancellationToken).ConfigureAwait(false);
}
相关问题