![](/img/trans.png)
[英]How to get list of Empty Resource Groups by using of Azure Mgmt SDK fluent
[英]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();
但這似乎不允許我獲取已部署的實際資源的詳細信息。
您可以使用Azure Management Libraries for .NET獲取部署的詳細信息。
安裝 Microsoft.Azure.Management.Fluent 包
創建一個身份驗證文件作為AUTH.md
樣本
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.