簡體   English   中英

如何使用 fluent Resource Manager SDK 獲取部署的 outputResources?

[英]How to get the outputResources of a deployment using the fluent Resource Manager SDK?

使用 Azure REST API 的GET 部署端點時,可以獲得給定部署的詳細信息,包括 outputResources,其中列出了從 ARM 模板部署創建的實際資源

不幸的是,在使用 Azure Resource Manager Fluent SDK 時,我似乎找不到訪問 outputResources 的等效方法。

我嘗試過使用以下內容:

var deployments = ResourceManager.Authenticate(credentials)
.WithSubscription(subscriptionId)
.Deployments.ListByResourceGroup(resourceGroup)
.Where(x => x.Name == deploymentName)
.OrderByDescending(x => x.Timestamp)
.First();

但這似乎不允許我獲取已部署的實際資源的詳細信息。

這些似乎是deployment的唯一可訪問屬性在此處輸入圖像描述

您可以使用Azure Management Libraries for .NET獲取部署的詳細信息。

  1. 安裝 Microsoft.Azure.Management.Fluent 包

  2. 創建一個身份驗證文件作為AUTH.md

  3. 樣本

    static void Main(string[] args) { IAzure azure = Azure.Authenticate("C:\\Users\\v-linjji\\my.azureauth").WithDefaultSubscription(); var deployments = azure.Deployments.ListByResourceGroup("JackWebApp"); foreach(var deployment in deployments) { Console.WriteLine(deployment.Timestamp + " -> " + deployment.Name); foreach(var dependency in deployment.Dependencies) { Console.WriteLine(dependency.Id); } foreach(var operation in deployment.DeploymentOperations.List()) { Console.WriteLine(operation.OperationId + " -> " + operation.StatusCode); } Console.WriteLine("Outputs:" + deployment.Outputs); Console.WriteLine(); } Console.ReadLine(); }

結果:

在此處輸入圖像描述

使用 Azure SDK 執行部署會返回一個IDeployment對象,並且您要查找的屬性現在嵌套得很深。

與您的部署相關的所有操作都位於IDeployment.DeploymentOperations下。 您可以調用.List()來獲取枚舉器並逐步執行它們。

每個DeploymentOperations對象都有一些您會感興趣的成員,對我最有用的是:

foreach(IDeploymentOperation op in deployment.DeploymentOperations.List())
{
    op.ProvisioningState // Completed, In Progress, Error
    op.StatusMessage // OK, Failed, etc
    op.TargetResource.Id // the fully qualified resource Id of your deployment
    op.TargetResource.ResourceName // the name of the new item
    op.TargetResource.ResourceType // the type of the new item, StorageAccount, Networking, etc
}

重申一下,您會找到 ID,這可能是這條路徑下最重要的

op.TargetResource.Id // the fully qualified resource Id of your deployment
/subscriptions/abc123/resourcegroup/MycoolGroup123/storageAccount/abc123efg

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM