[英]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中泥濘的泥濘水域,我要做的就是為人們做一個堅實的工作。
在您的應用程序的數據包管理器中執行:Install-Package Microsoft.Azure.Management.Resources -Pre Then Install-Package Microsoft.Azure.Management.Compute -Pre Then Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory -Pre
按照此博客獲取授權標題/令牌: 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 Resource Manager的完整源代碼: https : //github.com/Azure/azure-sdk-for-net/tree/master/src/ResourceManagement 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.