text
stringlengths 1
93.6k
|
|---|
# Create Windows VM
|
print('\nCreating Windows Virtual Machine')
|
# Recycling NIC of previous VM
|
vm_parameters = create_vm_parameters(nic.id, VM_REFERENCE['windows'])
|
async_vm_creation = compute_client.virtual_machines.create_or_update(
|
GROUP_NAME, VM_NAME, vm_parameters)
|
async_vm_creation.wait()
|
except CloudError:
|
print('A VM operation failed:\n{}'.format(traceback.format_exc()))
|
else:
|
print('All example operations completed successfully!')
|
finally:
|
# Delete Resource group and everything in it
|
print('\nDelete Resource Group')
|
delete_async_operation = resource_client.resource_groups.delete(
|
GROUP_NAME)
|
delete_async_operation.wait()
|
print("\nDeleted: {}".format(GROUP_NAME))
|
def create_nic(network_client):
|
"""Create a Network Interface for a VM.
|
"""
|
# Create VNet
|
print('\nCreate Vnet')
|
async_vnet_creation = network_client.virtual_networks.create_or_update(
|
GROUP_NAME,
|
VNET_NAME,
|
{
|
'location': LOCATION,
|
'address_space': {
|
'address_prefixes': ['10.0.0.0/16']
|
}
|
}
|
)
|
async_vnet_creation.wait()
|
# Create Subnet
|
print('\nCreate Subnet')
|
async_subnet_creation = network_client.subnets.create_or_update(
|
GROUP_NAME,
|
VNET_NAME,
|
SUBNET_NAME,
|
{'address_prefix': '10.0.0.0/24'}
|
)
|
subnet_info = async_subnet_creation.result()
|
# Create NIC
|
print('\nCreate NIC')
|
async_nic_creation = network_client.network_interfaces.create_or_update(
|
GROUP_NAME,
|
NIC_NAME,
|
{
|
'location': LOCATION,
|
'ip_configurations': [{
|
'name': IP_CONFIG_NAME,
|
'subnet': {
|
'id': subnet_info.id
|
}
|
}]
|
}
|
)
|
return async_nic_creation.result()
|
def create_vm_parameters(nic_id, vm_reference):
|
"""Create the VM parameters structure.
|
"""
|
return {
|
'location': LOCATION,
|
'os_profile': {
|
'computer_name': VM_NAME,
|
'admin_username': USERNAME,
|
'admin_password': PASSWORD
|
},
|
'hardware_profile': {
|
'vm_size': 'Standard_DS1_v2'
|
},
|
'storage_profile': {
|
'image_reference': {
|
'publisher': vm_reference['publisher'],
|
'offer': vm_reference['offer'],
|
'sku': vm_reference['sku'],
|
'version': vm_reference['version']
|
},
|
},
|
'network_profile': {
|
'network_interfaces': [{
|
'id': nic_id,
|
}]
|
},
|
}
|
if __name__ == "__main__":
|
run_example()
|
# <FILESEP>
|
import os
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.