我想执行基于资源组的调用。例如: https://msdn.microsoft.com/en-us/library/azure/mt163572.aspx
Azure 管理库似乎没有此功能(除非我遗漏了某些内容)。是否有任何 SDK 或客户端包装器可以进行此类调用?
编辑: 高拉夫准确地指出了我所需要的。我将为人们提供扎实的帮助,并扩展我所做的工作,以帮助清除 Azure 资源管理 API 的浑水。
在应用程序的数据包管理器中执行以下操作: 安装包 Microsoft.Azure.Management.Resources -Pre 然后 安装包 Microsoft.Azure.Management.Compute -Pre 然后 安装包 Microsoft.IdentityModel.Clients.ActiveDirectory -Pre
按照此博客获取授权 header / token : https://msdn.microsoft.com/en-us/library/azure/dn722415.aspx
然后像这样调用新的 API(注意轻微的名称更改):
class Program
{
static void Main(string[] args)
{
var token = GetAuthorizationHeader();
var credential = new Microsoft.Rest.TokenCredentials(token);
using (var client = new ComputeManagementClient(credential) { SubscriptionId = ConfigurationManager.AppSettings["subscriptionId"] })
{
var vms = client.VirtualMachines.ListAll();
}
}
private static string GetAuthorizationHeader()
{
AuthenticationResult result = null;
var context = new AuthenticationContext("https://login.windows.net/" + ConfigurationManager.AppSettings["tenantId"]);
string clientId = ConfigurationManager.AppSettings["clientId"];
string clientSecret = ConfigurationManager.AppSettings["clientSecret"];
ClientCredential clientCred = new ClientCredential(clientId, clientSecret);
var thread = new Thread(() =>
{
result = context.AcquireToken(
"https://management.core.windows.net/",
clientCred);
});
thread.SetApartmentState(ApartmentState.STA);
thread.Name = "AquireTokenThread";
thread.Start();
thread.Join();
if (result == null)
{
throw new InvalidOperationException("Failed to obtain the JWT token");
}
string token = result.AccessToken;
return token;
}
}
最佳答案
我相信您正在寻找的软件包是 Microsoft.Azure.Management.Resources 3.4.0-preview
。您可以在此处找到 Azure 资源管理器的完整源代码:https://github.com/Azure/azure-sdk-for-net/tree/master/src/ResourceManagement .
关于c# - 是否有用于 Azure 资源管理 API 调用的 C# sdk/包装器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35278231/