2017-05-04 12 views
0
#!/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を使用しました。

+0

あなたのパッケージとpythonのバージョンは何ですか? – 4c74356b41

+0

'pip install azure-mgmt-compute == 0.30.0rc5'を試してみます。 –

+0

@ PeterPan-MSFT:ありがとうございました。 – sas

答えて

1

あなたが言及している例では、「requirements.txt」ファイルに必要なバージョンがあることを確認してください。

私は、このチュートリアルであまりにも古いパッケージを残念ながらインストールする "pip install azure"を使用していると思います。 ReadTheDocsやGithubのFrontPageの上インストールを参照してください。注:

TL; DRは;,紺碧-MGMTをインストールし、直接 "--pre紺碧のインストールピップ" または」ピップを使用してください-compute "

+0

ありがとう:)私はazure-mgmt-compute == 0.30.0rc5&haikunatorとしてrequirements.txtのpythonモジュールを更新しました。 – sas

関連する問題