使用Azure Management C#API创建资源组

时间:2015-07-02 16:27:57

标签: c# azure

有没有办法使用Azure Management C#API创建资源组?

基本上这个REST API调用: https://msdn.microsoft.com/en-us/library/azure/dn790525.aspx

我找到了一种使用client.AffinityGroups.Create创建Affinity Group的方法,但这是我找到的最接近的东西。

2 个答案:

答案 0 :(得分:6)

我发现API调用隐藏在目前仅处于预览模式的库中。它位于以下NuGet包中,在Visual Studio中启用include prerelease以在NuGet客户端中找到它。

https://www.nuget.org/packages/Microsoft.Azure.Management.Resources/

然后创建一个资源组我可以使用

var credentials = new TokenCloudCredentials("", "");
var client = new Microsoft.Azure.Management.Resources.ResourceManagementClient(credentials);            
var result = c.ResourceGroups.CreateOrUpdateAsync("MyResourceGroup", new Microsoft.Azure.Management.Resources.Models.ResourceGroup("West US"), new System.Threading.CancellationToken()).Result;

还有另一个堆栈溢出帖子解释了如何进行身份验证: How to get Tags of Azure ResourceManagementClient object

以下博客文章详细介绍了如何设置身份验证部分所需的TokenCloudCredentials,但仅适用于命令行应用: http://www.bradygaster.com/post/using-windows-azure-active-directory-to-authenticate-the-management-libraries

如果您想使用命令行应用以外的其他内容,以下内容可用于身份验证: http://www.dushyantgill.com/blog/2015/05/23/developers-guide-to-auth-with-azure-resource-manager-api/

答案 1 :(得分:1)

转到https://resources.azure.com - ARMExplorer显示用于创建资源组的REST和PowerShell命令。所有API都基于REST。在C#中,发送WebClient请求。

相关问题