.net 用の Azure 管理ライブラリは初めてです。サブスクリプションに関して、または一般的に .Net または Rest API 用の Azure 管理ライブラリを使用して、利用可能な VM インスタンスのサイズを列挙するにはどうすればよいですか? 提案してください。
3 に答える
を呼び出して、リージョンの VM サイズのリストを取得できます。
https://management.azure.com/subscriptions/{subscription-id}/providers/Microsoft.Compute/locations/{location}/vmSizes?api-version={api-version}
ここに記載されているように -リージョンで利用可能なすべての仮想マシンのサイズを一覧表示します
同じための.Netクラスもありますが、使用されている例は見つかりませんでした-ここに文書化されています-VirtualMachineSizeOperationsExtensions.List
Certificate Base Authenticationを使用して、VM サイズのリストを取得できます。
Get Certificate メソッド
private static X509Certificate2 GetStoreCertificate(string subscriptionId, string thumbprint)
{
List<StoreLocation> locations = new List<StoreLocation>
{
StoreLocation.CurrentUser,
StoreLocation.LocalMachine
};
foreach (var location in locations)
{
X509Store store = new X509Store(StoreName.My, location);
try
{
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection certificates = store.Certificates.Find(
X509FindType.FindByThumbprint, thumbprint, false);
if (certificates.Count == 1)
{
return certificates[0];
}
}
finally
{
store.Close();
}
}
throw new ArgumentException(string.Format("A Certificate with Thumbprint '{0}' could not be located.",thumbprint));
}
ここでは、VM サイズを取得する同じ方法について説明します
private static X509Certificate2 Certificate = GetStoreCertificate(Your-subscriptionid,Your-thumbprint);
Microsoft.Azure.CertificateCloudCredentials credentials = new Microsoft.Azure.CertificateCloudCredentials(Your-subscriptionid, Certificate);
var computeClient = new ComputeManagementClient(credentials) { SubscriptionId = Your-subscriptionid};
var virtualMachineSize = computeClient.VirtualMachineSizes.List(Your-region_name).ToList();
リージョン フィッターごとに VM サイズのリストを取得できます
AuthenticationContext authenticationContext = new AuthenticationContext("https://login.windows.net/tenantdomainname.onmicrosoft.com"]);
UserCredential uc = new UserCredential(authusername,authpassword);
token = authenticationContext.AcquireToken("https://management.core.windows.net/", nativetenantid, uc);
var credentials = new TokenCredentials(token);
var computeClient = new ComputeManagementClient(credentials) { SubscriptionId = subscriptionid};
var virtualMachineSize = computeClient.VirtualMachineSizes.List(region_name).ToList();
トークン ベース認証用に Azure Active Directory に 1 つのネイティブ クライアント API を作成する必要があります。それ以外の場合は、証明書ベース認証をクライアント認証に使用することもできます。
コンピューティング リソースにMicrosoft.Azure.Management.Compute.dll、v10.0.0.0を使用しています。
ここからダウンロードできます: https://www.nuget.org/packages/Microsoft.Azure.Management.Compute/13.0.4-prerelease