text
stringlengths 1
93.6k
|
|---|
'create_option': DiskCreateOption.empty
|
}
|
}
|
)
|
data_disk = async_disk_creation.result()
|
# Get the virtual machine by name
|
print('\nGet Virtual Machine by Name')
|
virtual_machine = compute_client.virtual_machines.get(
|
GROUP_NAME,
|
VM_NAME
|
)
|
# Attach data disk
|
print('\nAttach Data Disk')
|
virtual_machine.storage_profile.data_disks.append({
|
'lun': 12,
|
'name': 'mydatadisk1',
|
'create_option': DiskCreateOption.attach,
|
'managed_disk': {
|
'id': data_disk.id
|
}
|
})
|
async_disk_attach = compute_client.virtual_machines.create_or_update(
|
GROUP_NAME,
|
virtual_machine.name,
|
virtual_machine
|
)
|
async_disk_attach.wait()
|
# Detach data disk
|
print('\nDetach Data Disk')
|
data_disks = virtual_machine.storage_profile.data_disks
|
data_disks[:] = [
|
disk for disk in data_disks if disk.name != 'mydatadisk1']
|
async_vm_update = compute_client.virtual_machines.create_or_update(
|
GROUP_NAME,
|
VM_NAME,
|
virtual_machine
|
)
|
virtual_machine = async_vm_update.result()
|
# Deallocating the VM (in preparation for a disk resize)
|
print('\nDeallocating the VM (to prepare for a disk resize)')
|
async_vm_deallocate = compute_client.virtual_machines.deallocate(
|
GROUP_NAME, VM_NAME)
|
async_vm_deallocate.wait()
|
# Increase OS disk size by 10 GB
|
print('\nUpdate OS disk size')
|
os_disk_name = virtual_machine.storage_profile.os_disk.name
|
os_disk = compute_client.disks.get(GROUP_NAME, os_disk_name)
|
if not os_disk.disk_size_gb:
|
print(
|
"\tServer is not returning the OS disk size, possible bug in the server?")
|
print("\tAssuming that the OS disk size is 30 GB")
|
os_disk.disk_size_gb = 30
|
os_disk.disk_size_gb += 10
|
async_disk_update = compute_client.disks.create_or_update(
|
GROUP_NAME,
|
os_disk.name,
|
os_disk
|
)
|
async_disk_update.wait()
|
# Start the VM
|
print('\nStart VM')
|
async_vm_start = compute_client.virtual_machines.start(
|
GROUP_NAME, VM_NAME)
|
async_vm_start.wait()
|
# Restart the VM
|
print('\nRestart VM')
|
async_vm_restart = compute_client.virtual_machines.restart(
|
GROUP_NAME, VM_NAME)
|
async_vm_restart.wait()
|
# Stop the VM
|
print('\nStop VM')
|
async_vm_stop = compute_client.virtual_machines.power_off(
|
GROUP_NAME, VM_NAME)
|
async_vm_stop.wait()
|
# List VMs in subscription
|
print('\nList VMs in subscription')
|
for vm in compute_client.virtual_machines.list_all():
|
print("\tVM: {}".format(vm.name))
|
# List VM in resource group
|
print('\nList VMs in resource group')
|
for vm in compute_client.virtual_machines.list(GROUP_NAME):
|
print("\tVM: {}".format(vm.name))
|
# Delete VM
|
print('\nDelete VM')
|
async_vm_delete = compute_client.virtual_machines.delete(
|
GROUP_NAME, VM_NAME)
|
async_vm_delete.wait()
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.