Azure python SDK - 从资源组中删除或解除分配 VM



我想使用 Azure sdk for python 从资源组中解除分配 VM。我已经使用 sdk (compute_client.virtual_machines.create_or_update) 创建了一个 VM,但我找不到任何可以停止或解除分配 VM 的特定方法。

谢谢

可以

参考 Azure SDK for Python 的文档,找到方法deallocate VirtualMachinesOperations ,请参阅 http://azure-sdk-for-python.readthedocs.org/en/latest/ref/azure.mgmt.compute.operations.html#azure.mgmt.compute.operations.VirtualMachinesOperations.deallocate。

这是代码作为参考。

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)

最新更新