是否有用于 Azure 资源管理 API 调用的 C# sdk/wrapper?
Is there a C# sdk/wrapper for Azure Resource Management API calls?
我想执行基于资源组的调用。例如:
https://msdn.microsoft.com/en-us/library/azure/mt163572.aspx
Azure 管理库似乎没有此功能(除非我遗漏了什么)。是否有任何可用的 SDK 或客户端包装器可以进行此类调用?
编辑:
Gaurav 指出了我所需要的。打算让人们扎实并扩展我所做的工作以帮助清除 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
. You can find the complete source code for Azure Resource Manager here: https://github.com/Azure/azure-sdk-for-net/tree/master/src/ResourceManagement。
我想执行基于资源组的调用。例如: https://msdn.microsoft.com/en-us/library/azure/mt163572.aspx
Azure 管理库似乎没有此功能(除非我遗漏了什么)。是否有任何可用的 SDK 或客户端包装器可以进行此类调用?
编辑: Gaurav 指出了我所需要的。打算让人们扎实并扩展我所做的工作以帮助清除 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
. You can find the complete source code for Azure Resource Manager here: https://github.com/Azure/azure-sdk-for-net/tree/master/src/ResourceManagement。