2014-12-03 96 views
1

微软为azure创建了一个反人类api。我如何通过azure python sdk重新启动虚拟机?一些演示代码会很棒。通过azure python sdk重启虚拟机

+0

看看这里:https://github.com/Azure/azure-sdk-for-python/blob/master/tests/test_servicemanagementservice.py#L1852。不知道它是否适用于虚拟机,但我认为它适用于云服务。 – 2014-12-03 06:15:56

回答

0

虽然这是旧的,这里有一个示例代码:

from azure.common.credentials import ServicePrincipalCredentials 
from azure.mgmt.compute import ComputeManagementClient  
credentials = ServicePrincipalCredentials(client_id=clientid, secret=secret, 
               tenant=tenantid) 
compute_client = ComputeManagementClient(credentials, subscriptionid) 
vm_restart = compute_client.virtual_machines.restart(resource_group_name, vm_name) 
vm_restart.wait() 
vm_instance = compute_client.virtual_machines.get(resource_group_name, vm_name) 

其中vm_instance是一个包含其所有CONFG信息VM对象。

+0

非常感谢,即使我没有机会尝试。 – xdays 2017-04-06 13:47:58