【发布时间】:2022-08-11 00:58:26
【问题描述】:
如果不使用 clientId 和 Secrete Id,我无法使用 python 代码启动 Azure Vm。
我们可以在不使用 client_id 和 secrete id 的情况下在 python 中启动或停止 Azure vm。
这是供参考的代码。
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)
在这里我们使用客户端 ID 和所有...但我想停止我的 Azure Vm 而不需要应用程序 ID/客户端 ID ..
标签: python-3.x azure azure-devops azure-functions