-1

I am using python script to create virtual machine. I am able to create virtul machine. Just wanted to add availabilty set feature.

<< some snip >>

resource_client = ResourceManagementClient(credentials, subscription_id)
compute_client = ComputeManagementClient(credentials, subscription_id)
storage_client = StorageManagementClient(credentials, subscription_id)
network_client = NetworkManagementClient(credentials, subscription_id)

# Create Resource group print('\nCreate Resource Group') resource_client.resource_groups.create_or_update(GROUP_NAME, {'location':LOCATION})

# Create a storage account
print('\nCreate a storage account')
storage_async_operation = storage_client.storage_accounts.create(
    GROUP_NAME,
    STORAGE_ACCOUNT_NAME,
    {
        'sku': {'name': 'standard_lrs'},
        'kind': 'storage',
        'location': LOCATION
    }
)
storage_async_operation.wait()

# Create a NIC
nic = create_nic(network_client)

<<>>

just looking for function which can creat availabiltyset. And i can attach to multiple vms

10305059
  • 128
  • 2
  • 13
  • so what have you tried besides pasting this example from documentation? what doesnt work? – 4c74356b41 Jan 12 '17 at 17:06
  • @4c74356b41 I am not able to figure out how to create availabilty set. I have give some tried like. compute_client.virtual_machines.create_or_update( GROUP_NAME, AVAILABLITY_SET_NAME, { 'platformFaultDomainCount': '3', 'platformUpdateDomainCount': '20', 'location': LOCATION } but it is also failing. – 10305059 Jan 12 '17 at 17:15

1 Answers1

2

AvailabilitySet has it's own create operation: http://azure-sdk-for-python.readthedocs.io/en/latest/ref/azure.mgmt.compute.operations.html#azure.mgmt.compute.operations.AvailabilitySetsOperations.create_or_update

So your code should look like:

compute_client.availability_sets.create_or_update(
    group_name,
    availability_set_name,
    availability_set_parameters
)
Laurent Mazuel
  • 3,422
  • 13
  • 27
  • Availabiltyset creation part is working fine. How can we assign this set to virtual machine creatioLn? – 10305059 Jan 12 '17 at 19:25
  • Use the "availability_set" parameter in the "virtual_machines.create_or_update". http://azure-sdk-for-python.readthedocs.io/en/latest/ref/azure.mgmt.compute.operations.html#azure.mgmt.compute.operations.VirtualMachinesOperations.create_or_update – Laurent Mazuel Jan 13 '17 at 19:47