Azure python sdk获取自动化账户信息

2024-06-06 05:41:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我想获取资源组中自动化帐户的详细信息。我遇到过这个班azure.mgmt.automation自动化.操作.自动化会计操作. 所需的参数是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)

Tags: namefromimportclientfor参数groupazure
1条回答
网友
1楼 · 发布于 2024-06-06 05:41:46

下面是我在python3中使用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)

希望有帮助。你知道吗

相关问题 更多 >