gpt4 book ai didi

python - Azure python SDK - 从资源组中删除或取消分配虚拟机

转载 作者:行者123 更新时间:2023-11-30 22:59:08 28 4
gpt4 key购买 nike

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

谢谢

最佳答案

您可以引用Azure SDK for Python的文档,找到VirtualMachinesOperationsdeallocate方法,参见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)

关于python - Azure python SDK - 从资源组中删除或取消分配虚拟机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35889467/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com