azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

consumption

Open vsnarkhede13 opened this issue 6 years ago • 8 comments

I want to extract all the resources, resource type(storage/vm/any else) and its consumed price using python. I've tried to get it through billing but didn't get results as expected.

Code: import datetime import azure.mgmt.consumption import azure.mgmt.consumption.models from azure.mgmt.consumption.models import UsageDetailPaged from azure.mgmt.consumption.consumption_management_client import ConsumptionManagementClientConfiguration,ConsumptionManagementClient from msrest.paging import Paged #All credentials are added appropriately for security reasons those are not added in this query. from azure.common.credentials import ServicePrincipalCredentials from azure.mgmt.billing import BillingManagementClient try1 = ConsumptionManagementClient(credentials,subscription_id) billing_client = BillingManagementClient(credentials, subscription_id) print(billing_client.invoices.list())

vsnarkhede13 avatar Feb 03 '20 08:02 vsnarkhede13

@vsnarkhede13 thanks for the feedback, looping the right team to take a look at it //cc: @nickzhums

kaerm avatar Feb 06 '20 18:02 kaerm

If there is a sample of results, it will be better. Thank you

dw511214992 avatar Feb 07 '20 06:02 dw511214992

If there is a sample of results, it will be better. Thank you

{ "accountName": null, "additionalProperties": null, "billableQuantity": "None", "billingPeriodId": "", "consumedService": "Microsoft.Storage", "costCenter": null, "currency": "INR", "departmentName": null, "id": "", "instanceId": "", "instanceLocation": "IN West", "instanceName": "(instance name)", "invoiceId": null, "isEstimated": true, "meterDetails": null, "meterId": "", "name": "", "pretaxCost": "0.0034", "product": "", "subscriptionGuid": "**", "subscriptionName": "(subscription type)", "tags": null, "type": "Microsoft.Consumption/usageDetails", "usageEnd": "(end details)", "usageQuantity": "0.144", "usageStart": "(Start details)" }

vsnarkhede13 avatar Feb 07 '20 06:02 vsnarkhede13

The result is gotten from billing service and we need help from billing service team.

dw511214992 avatar Feb 10 '20 10:02 dw511214992

Hi @vsnarkhede13 , You can use service commerce to extract all the resources, resource type(storage/vm/any else) and its consumed price ,and please install package azure-mgmt-commerce.

The detailed code is shown below (here is the official document for your reference):

from azure.mgmt.commerce import UsageManagementClient 
from datetime import date, timedelta 
from azure.common.credentials import ServicePrincipalCredentials 
subscription_id='<Your Subscription ID>'   
credentials = ServicePrincipalCredentials(   
 client_id='<Your service principal App ID>',   
 secret='<Your service principal password>',   
 tenant='<Your tenant ID>'   
)   
commerce_client = UsageManagementClient(credentials, subscription_id) 
aggregate_data = commerce_client.usage_aggregates.list( 
  str(date.today() - timedelta(days=1))+'T00:00:00Z', 
  str(date.today())+'T00:00:00Z' 
) 

@jongio

v-xuto avatar Mar 06 '20 02:03 v-xuto

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ms-premp.

ghost avatar May 04 '20 19:05 ghost

please try this.

https://github.com/ms-premp/AzureConsumptionSamples/blob/master/Python_sdk/usage_details_list_python_sdk_example.py

ms-premp avatar Jun 03 '20 17:06 ms-premp

Closing this issue based on the recommendations given by Prem. Please feel free to re-open this issue if needed, after reviewing the sample shared.

ramaganesan-rg avatar Jun 29 '20 00:06 ramaganesan-rg