Azure python SDK从资源组中删除或取消分配VM

2024-09-28 03:17:48 发布

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

我想使用azuresdkforpython从资源组释放VM。 我已经用sdk(compute)创建了一个虚拟机_客户端虚拟机。create\u or \u update),但我找不到任何特定方法来停止或取消分配VM。在

谢谢你


Tags: or方法客户端createsdkvmupdate资源
1条回答
网友
1楼 · 发布于 2024-09-28 03:17:48

你可以参考azuresdkforpython的文档,找到VirtualMachinesOperations的方法deallocate,请参见{a1}。在

这是代码作为参考。在

from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.compute import ComputeManagementClient, ComputeManagementClientConfiguration

credentials = ServicePrincipalCredentials(
    client_id = '<client-id>',
    secret = '<key>',
    tenant = '<tenant-id>'
)

subscription_id = '<subscription-id>'

compute_config = ComputeManagementClientConfiguration(credentials, subscription_id, api_version='2015-05-01-preview')
compute_client = ComputeManagementClient(compute_config)
resource_group_name = '<resource-group>'
vm_name = '<vm-name>'
result = compute_client.virtual_machines.deallocate(resource_group_name, vm_name)

相关问题 更多 >

    热门问题