1

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

谢谢你

4

1 回答 1

3

您可以参考 Azure SDK for Python 的文档并找到方法deallocateVirtualMachinesOperations请参阅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)
于 2016-03-10T06:15:15.010 回答