浏览 Azure Python SDK

Navigating Azure Python SDK

我无法理解文档的组织方式。我最困惑的部分是每个 class 中的模型方法,例如:Model class for resource management class

这些模型是什么?

class 有多个文档页面,所有这些文档都不同:One page for resource management client class (this has the models package), Another page resource management client(这不是)

本文档的结构如何?例如,如何找到处理自动缩放的 class?一些重要的链接导致找不到页面:this one is linked directly from this(事实上,此页面中提到的大多数链接都会导致 404 - 根据我的说法,所有这些都是与文档相关的非常重要的链接!)。我在搜索处理资源管理的 class 时偶然发现了这一点。 我通常通过转到文档页面并导航文档树来尝试找到 classes。进行 google 搜索然后通过搜索进行梳理并不理想。现在我能找到正确的 class 或方法的唯一方法是通过给定的示例并希望其中一个示例包含我的用例。相比之下,AWS python SDK 使用起来非常直观。

如果我遗漏了一些对理解本文档至关重要的pythonic 概念,请告诉我一些我应该注意的概念。

作为一个具体示例,如果我想列出资源组的所有自动缩放设置,我该如何找到相同的 python SDK?

如果要使用pthond sdk列出资源组的所有自动缩放设置,我们可以使用包azure.mgmt.monitor中的方法MonitorManagementClient.autoscale_settings.list_by_resource_group()。详情请参考here

例如

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

  2. 安装sdk

pip install azure-mgmt-monitor
  1. 代码
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>')