Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Updated Python content to comply with PEP8 (via autopep8) (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
sptramer authored and lmazuel committed Jun 27, 2019
1 parent 56e71b3 commit c2644ff
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
27 changes: 18 additions & 9 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def run_example():

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

try:
# Create a NIC
Expand Down Expand Up @@ -159,7 +160,8 @@ def run_example():
# 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']
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,
Expand All @@ -169,15 +171,17 @@ def run_example():

# 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 = 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(
"\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

Expand All @@ -192,17 +196,20 @@ def run_example():

# Start the VM
print('\nStart VM')
async_vm_start = compute_client.virtual_machines.start(GROUP_NAME, VM_NAME)
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 = 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 = compute_client.virtual_machines.power_off(
GROUP_NAME, VM_NAME)
async_vm_stop.wait()

# List VMs in subscription
Expand All @@ -217,7 +224,8 @@ def run_example():

# Delete VM
print('\nDelete VM')
async_vm_delete = compute_client.virtual_machines.delete(GROUP_NAME, VM_NAME)
async_vm_delete = compute_client.virtual_machines.delete(
GROUP_NAME, VM_NAME)
async_vm_delete.wait()

# Create Windows VM
Expand All @@ -234,7 +242,8 @@ def run_example():
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 = resource_client.resource_groups.delete(
GROUP_NAME)
delete_async_operation.wait()
print("\nDeleted: {}".format(GROUP_NAME))

Expand Down
4 changes: 2 additions & 2 deletions tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def test_example(self):
run_example()
else:
with patch('example.get_credentials', VirtualMachineExampleTest.fake_credentials), \
patch('example.STORAGE_ACCOUNT_NAME', DUMMY_STORAGE_NAME):
patch('example.STORAGE_ACCOUNT_NAME', DUMMY_STORAGE_NAME):
run_example()


if __name__ == '__main__':
unittest.main()
unittest.main()
23 changes: 16 additions & 7 deletions unmanaged-disks/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@
# AZURE_CLIENT_SECRET: with your Azure Active Directory Application Secret
# AZURE_SUBSCRIPTION_ID: with your Azure Subscription Id
#


def run_example():
"""Resource Group management example."""
#
# Create all clients with an Application (service principal) token provider
#
subscription_id = os.environ.get(
'AZURE_SUBSCRIPTION_ID',
'11111111-1111-1111-1111-111111111111') # your Azure Subscription Id
'11111111-1111-1111-1111-111111111111') # your Azure Subscription Id
credentials = ServicePrincipalCredentials(
client_id=os.environ['AZURE_CLIENT_ID'],
secret=os.environ['AZURE_CLIENT_SECRET'],
Expand All @@ -78,7 +80,8 @@ def run_example():

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

# Create a storage account
print('\nCreate a storage account')
Expand Down Expand Up @@ -135,7 +138,7 @@ def run_example():
'disk_size_gb': 1,
'lun': 0,
'vhd': {
'uri' : "http://{}.blob.core.windows.net/vhds/mydatadisk1.vhd".format(
'uri': "http://{}.blob.core.windows.net/vhds/mydatadisk1.vhd".format(
STORAGE_ACCOUNT_NAME)
},
'create_option': 'Empty'
Expand Down Expand Up @@ -165,7 +168,8 @@ def run_example():

# Deallocating the VM (resize prepare)
print('\nDeallocating the VM (resize prepare)')
async_vm_deallocate = compute_client.virtual_machines.deallocate(GROUP_NAME, VM_NAME)
async_vm_deallocate = compute_client.virtual_machines.deallocate(
GROUP_NAME, VM_NAME)
async_vm_deallocate.wait()

# Update OS disk size by 10Gb
Expand All @@ -191,12 +195,14 @@ def run_example():

# Restart the VM
print('\nRestart VM')
async_vm_restart = compute_client.virtual_machines.restart(GROUP_NAME, VM_NAME)
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 = compute_client.virtual_machines.power_off(
GROUP_NAME, VM_NAME)
async_vm_stop.wait()

# List VMs in subscription
Expand All @@ -211,7 +217,8 @@ def run_example():

# Delete VM
print('\nDelete VM')
async_vm_delete = compute_client.virtual_machines.delete(GROUP_NAME, VM_NAME)
async_vm_delete = compute_client.virtual_machines.delete(
GROUP_NAME, VM_NAME)
async_vm_delete.wait()

# Create Windows VM
Expand All @@ -230,6 +237,7 @@ def run_example():
delete_async_operation.wait()
print("\nDeleted: {}".format(GROUP_NAME))


def create_nic(network_client):
"""Create a Network Interface for a VM.
"""
Expand Down Expand Up @@ -274,6 +282,7 @@ def create_nic(network_client):
)
return async_nic_creation.result()


def create_vm_parameters(nic_id, vm_reference):
"""Create the VM parameters structure.
"""
Expand Down

0 comments on commit c2644ff

Please # to comment.