簡體   English   中英

Azure Python SDK-獲取自動化帳戶的信息

[英]Azure python sdk - getting information of Automation account

我想在資源組中獲取自動化帳戶的詳細信息。 我遇到過此類azure.mgmt.automation.operations.AutomationAccountOperations。 所需的參數是client,config,serializer和deserializer。 我不確定這些參數是什么。 誰能舉例說明一下。

這是我要參考的文檔

https://azure.github.io/azure-sdk-for-python/ref/azure.mgmt.automation.operations.html#azure.mgmt.automation.operations.Operations

我的示例代碼是

> from azure.common.credentials import UserPassCredentials from
> azure.mgmt.resource import ResourceManagementClient from
> azure.mgmt.compute import ComputeManagementClient from
> azure.mgmt.automation.operations.automation_account_operations import
> AutomationAccountOperations
> 
> 
> GROUP_NAME = 'group_name'
> 
> subscription_id = '111111-11111-11111-1111'
> 
> 
> credentials = UserPassCredentials(
>     'user123@xyz.com',
>     'password' )
> 
> 
> automation_client =
> AutomationAccountOperations(credentials,subscription_id)
> 
> def get_automation_details():
>     for item in automation_client.list(GROUP_NAME):
>         print(item)

這是我在Python 3中使用azure-mgmt-automation包的示例代碼。它對我來說很好。

from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.automation import AutomationClient

subscription_id = '<your subscription id, like xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>'
credentials = ServicePrincipalCredentials(
    client_id='<your client id registered in AAD, like xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>',
    secret='<your client secret>',
    tenant='<your tenant id, like xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>'
)

client = AutomationClient(credentials, subscription_id)

# List all automation accounts in the subscription
all = client.automation_account.list()
for item in all:
    print(item)

# List the automation accounts of a resource group
resource_group_name = '<your resource group name>'
accounts_by_rg = client.automation_account.list_by_resource_group(resource_group_name)
for item in accounts_by_rg:
    print(item)

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM