Azure-Samples / virtual-machines-python-manage

An example illustrating how to use Python to manage your Azure Virtual Machines
MIT License
104 stars 84 forks source link

AttributeError: 'ComputeManagementClient' object has no attribute 'disks' #11

Closed jsilberm closed 7 years ago

jsilberm commented 7 years ago

Looks like something changed ... and broke ???

#!/usr/bin/env python3.6
import os
import sys
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.compute import ComputeManagementClient

#
# Required
#
envars = ["ARM_SUBSCRIPTION_ID", "ARM_CLIENT_ID", "ARM_CLIENT_SECRET", "ARM_TENANT_ID", "ARM_REGION" ]

def check_env():
    for e in envars:
        if not os.getenv(e):
            print ("ERROR: %s must be set in the environmet" % e)
            sys.exit(1)

check_env()
subscription_id = os.environ.get('ARM_SUBSCRIPTION_ID')
credentials = ServicePrincipalCredentials(
       client_id=os.environ['ARM_CLIENT_ID'],
       secret=os.environ['ARM_CLIENT_SECRET'],
       tenant=os.environ['ARM_TENANT_ID']
)

region = os.environ['ARM_REGION']
if not region:
   print ("ERROR: ARM_REGION not set")
   sys.exit(1)

compute_client = ComputeManagementClient(credentials, subscription_id)

async_creation = compute_client.disks.create_or_update(
        resource_group,
        "/dev/xvda",
        {
            'location': region,
            'disk_size_gb': 50,
            'creation_data': {
                'create_option': "empty"
            }
        }
    )
disk_resource = async_creation.result()
print ("Disk = ", disk_resource)

===================

Traceback (most recent call last): File "./broke.py", line 36, in async_creation = compute_client.disks.create_or_update( AttributeError: 'ComputeManagementClient' object has no attribute 'disks'

lmazuel commented 7 years ago

As discussed in the SDK issue, you need at least azure-mgmt-compute. Note that the requirements.txt file here ask for 2.0 at least. Thanks,