Search code examples
azureazure-sdk-python

Navigating Azure Python SDK


I'm unable to understand how the documentation is organized. The part I am most confused about is models method in each class, for example: Model class for resource management class

What are these models?

There are multiple documentation pages for a class, and all of these documentation are different: One page for resource management client class (this has the models package), Another page resource management client (this does not)

How is this documentation structured? For example, how do I find a class that deals with autoscaling? Some important links lead to page not founds: this one is linked directly from this (In fact most of the links mentioned in this page lead to 404 - and according to me all of these are very important links with respect to the documentation!). I stumbled upon this while searching for a class that deals with managing resources. I usually try to find classes by going to the documentation page and navigating the documentation tree. Doing a google search and then combing through the search is not ideal. Right now the only way I can find the right class or the method is by going through the samples given and hoping that one of the samples contains my use case. In comparison the AWS python SDK is extremely intuitive to use.

If I am missing some pythonic concepts that are essential to understanding this documentation please tell me me some concepts that I should be aware of.

As a concrete example if I want to list all the autoscale settings for a resource group how do I find the python SDK for the same?


Solution

  • If you want to list all the autoscale settings for a resource group with pthond sdk, we can use the method MonitorManagementClient.autoscale_settings.list_by_resource_group() in the package azure.mgmt.monitor. For more details, please refer to here

    For example

    1. create a service principal and assign azure rabc role to the sp

    2. Install sdk

    pip install azure-mgmt-monitor
    
    1. Code
    from azure.identity import ClientSecretCredential
    
    from azure.mgmt.monitor import MonitorManagementClient
    
    CLIENT_ID = 'the appId of the sp'
    CLIENT_SECRET = 'the client secret of the sp'
    TENANT_ID = ' '
    SUBSCRIPTION_ID = ' '
    creds = ClientSecretCredential(tenant_id=TENANT_ID,
                                   client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
    
    monitor_client = MonitorManagementClient(
        credential=creds, subscription_id=SUBSCRIPTION_ID)
    results = monitor_client.autoscale_settings.list_by_resource_group(
        resource_group_name='<group name>')