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

Consumption examples

Open dejan-shuki opened this issue 7 years ago • 8 comments

Can you add some examples to Azure Consumption libraries for python documentation?

dejan-shuki avatar Oct 27 '19 14:10 dejan-shuki

@dejan-shuki thanks for reporting this - I am routing this to the right team for review

kaerm avatar Oct 28 '19 17:10 kaerm

any updates?

ahaw021 avatar Jan 29 '20 03:01 ahaw021

@nickzhums can you take a look at this?

kaerm avatar Jan 29 '20 17:01 kaerm

@kaerm

Find below.

# various credentials options (flexible programming)

import azure.common.credentials as credential_options
import os

# TODO: add MSI / ADAL / CLI options

azure_credential = credential_options.UserPassCredentials(os.environ["AZURE_USERNAME"],os.environ["AZURE_PASSWORD"])
# azure_credential = credential_options.ServicePrincipalCredentials(os.environ["AZURE_CLIENT_ID"],os.environ["AZURE_CLIENT_SECRET"])


#grab subscription (currently an environmental variable)

azure_subscription = os.environ["AZURE_SUBSCRIPTION_ID"]

print(f"Azure Credential Object created. Details: {azure_credential}")
print(f"Working on Subscription ID {azure_subscription}")

from azure.mgmt.consumption.consumption_management_client import ConsumptionManagementClient
consumption_client = ConsumptionManagementClient(azure_credential,azure_subscription)
print(f"Created Consumption Client Utilisng API Version {consumption_client.api_version} \r\n\r\n")

# Price Sheet Operations Object
# Methods: https://azuresdkdocs.blob.core.windows.net/$web/python/azure-mgmt-consumption/3.0.0/azure.mgmt.consumption.operations.html

price_sheet_client = consumption_client.price_sheet
print(f"Using Price Sheet Operations --- API Version: {price_sheet_client.api_version}")

# get pricesheets using the get() method This method take paramters. 
# review options https://azuresdkdocs.blob.core.windows.net/$web/python/azure-mgmt-consumption/3.0.0/azure.mgmt.consumption.operations.html

price_sheet_results = price_sheet_client.get()

for price_sheet in price_sheet_results.pricesheets:
    print(price_sheet)
    print("\r\n")

ahaw021 avatar Feb 06 '20 07:02 ahaw021

image

ahaw021 avatar Feb 06 '20 08:02 ahaw021

@dejan-shuki any specific use case you are looking for?

nickzhums avatar Feb 06 '20 08:02 nickzhums

Please see this example https://github.com/ms-premp/AzureConsumptionSamples/blob/master/Python_sdk/usage_details_list_python_sdk_example.py

ms-premp avatar Jun 28 '20 09:06 ms-premp

closing as per Prem's inputs.

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