【问题标题】:Azure python sdk - getting information of Automation accountAzure python sdk - 获取自动化帐户的信息
【发布时间】:2019-07-18 14:10:05
【问题描述】:

我想获取资源组中自动化帐户的详细信息。我遇到过此类 azure.mgmt.automation.operations.AutomationAccountOperations 。所需的参数是客户端、配置、序列化器和反序列化器。我不确定这些参数是什么。谁能举例说明一下。

这是我所指的文档

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 azure


    【解决方案1】:

    这是我在 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)
    

    希望对你有帮助。

    【讨论】:

    • 嘿,谢谢彼得,这很有帮助。我想在这个自动化帐户中找出更新管理下的机器的详细信息。我怎样才能得到那个
    猜你喜欢
    • 2020-04-20
    • 1970-01-01
    • 1970-01-01
    • 2020-11-27
    • 2022-01-22
    • 2020-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多