Reputation: 1181
#!/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()
We installed azure python sdk on ubuntu server and did all the necessary steps. but still this sample code giving following error.
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)
We used this to create this example.
Upvotes: 0
Views: 1782
Reputation: 3546
In the example you mention, please look at the "requirements.txt" file to have the necessary version.
My guess is you are using "pip install azure" that will unfortunately install currently a too old package for this tutorial. See Installation note on ReadTheDocs or the Github frontpage:
TL;DR;, please use "pip install --pre azure" or directly "pip install azure-mgmt-compute"
Upvotes: 1