#!/usr/bin/env python
import os
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.compute import ComputeManagementClient
def run_example():
"""Resource Group management example."""
#
# Create all clients with an Application (service principal) token provider
#
subscription_id = os.environ['AZURE_SUBSCRIPTION_ID']
credentials = ServicePrincipalCredentials(
client_id=os.environ['AZURE_CLIENT_ID'],
secret=os.environ['AZURE_CLIENT_SECRET'],
tenant=os.environ['AZURE_TENANT_ID']
)
compute_client=ComputeManagementClient(credentials,subscription_id)
###########
# Prepare #
###########
# List VM in resource group
print('\nList VMs in resource group')
for vm in compute_client.virtual_machines.list():
print("\tVM: {}".format(vm.name))
if __name__ == "__main__":
run_example()
ubuntuサーバーにazure python sdkをインストールして、すべての必要な手順を実行しました。このサンプルコードでもエラーが発生します。Azure python sdkが動作しない
Traceback (most recent call last):
File "app.py", line 30, in <module>
run_example()
File "app.py", line 18, in run_example
compute_client=ComputeManagementClient(credentials,subscription_id)
TypeError: __init__() takes exactly 2 arguments (3 given)
この例では、thisを使用しました。
あなたのパッケージとpythonのバージョンは何ですか? – 4c74356b41
'pip install azure-mgmt-compute == 0.30.0rc5'を試してみます。 –
@ PeterPan-MSFT:ありがとうございました。 – sas