Reputation: 111
I am looking for examples of how to use the Azure .NET SDK to query for the current usage and remaining quotas for Compute resources (say Dsv3 vCPUs).
Thanks!
Upvotes: 0
Views: 121
Reputation: 23121
According to my test, we can use Azure .Net SDK Microsoft.Azure.Management.Compute.Fluent
to list the usage of Microsoft.Comput resource in one Azure Subscription. For more details, please refer to the document
az login
az ad sp create-for-rbac --name <ServicePrincipalName>
az role assignment create --assignee <ServicePrincipalName> --role Contributor
var tenantId = "<your tenant id>";
var clientId = "<your sp app id> ";
var clientSecret = "<your sp passowrd>";
var subscriptionId = "<your subscription id>";
AzureCredentials credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
clientId,
clientSecret,
tenantId,
AzureEnvironment.AzureGlobalCloud);
RestClient restClient = RestClient.Configure()
.WithEnvironment(AzureEnvironment.AzureGlobalCloud)
.WithCredentials(credentials)
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Build();
ComputeManagementClientclient = new ComputeManagementClient(restClient);
client.SubscriptionId = subscriptionId;
foreach (var s1 in await UsageOperationsExtensions.ListAsync(client.Usage, Region.AsiaSouthEast.Name)) {
Console.WriteLine("Name: " + s1.Name.LocalizedValue +"\nUnit: "+ UsageInner.Unit + "\nCurrentValue: " + s1.CurrentValue + "\nLimit: " + s1.Limit);
Console.WriteLine("-----------------------");
}
Upvotes: 2