@@ -2348,12 +2348,13 @@ def attach_managed_data_disk(cmd, resource_group_name, vm_name, disk=None, ids=N
23482348 source_snapshots_or_disks = None , source_disk_restore_point = None ,
23492349 new_names_of_source_snapshots_or_disks = None , new_names_of_source_disk_restore_point = None ):
23502350 # attach multiple managed disks using disk attach API
2351- vm = get_vm_to_update (cmd , resource_group_name , vm_name )
2351+ vm = get_vm_to_update_by_aaz (cmd , resource_group_name , vm_name )
2352+
23522353 if not new and not sku and not size_gb and disk_ids is not None :
23532354 if lun :
23542355 disk_lun = lun
23552356 else :
2356- disk_lun = _get_disk_lun (vm .storage_profile . data_disks )
2357+ disk_lun = _get_disk_lun_by_aaz (vm .get ( "storageProfile" , {}). get ( "dataDisks" , []) )
23572358
23582359 data_disks = []
23592360 for disk_item in disk_ids :
@@ -2374,8 +2375,8 @@ def attach_managed_data_disk(cmd, resource_group_name, vm_name, disk=None, ids=N
23742375 else :
23752376 # attach multiple managed disks using vm PUT API
23762377 from azure .mgmt .core .tools import parse_resource_id
2377- DataDisk , ManagedDiskParameters , DiskCreateOption = cmd . get_models (
2378- 'DataDisk' , 'ManagedDiskParameters' , 'DiskCreateOptionTypes' )
2378+ from . operations . vm import convert_show_result_to_snake_case
2379+
23792380 if size_gb is None :
23802381 default_size_gb = 1023
23812382
@@ -2386,30 +2387,46 @@ def attach_managed_data_disk(cmd, resource_group_name, vm_name, disk=None, ids=N
23862387 if lun :
23872388 disk_lun = lun
23882389 else :
2389- disk_lun = _get_disk_lun (vm .storage_profile . data_disks )
2390+ disk_lun = _get_disk_lun_by_aaz (vm .get ( "storageProfile" , {}). get ( "dataDisks" , []) )
23902391
23912392 if new :
2392- data_disk = DataDisk (lun = disk_lun , create_option = DiskCreateOption .empty ,
2393- name = parse_resource_id (disk_item )['name' ],
2394- disk_size_gb = size_gb if size_gb else default_size_gb , caching = caching ,
2395- managed_disk = ManagedDiskParameters (storage_account_type = sku ))
2393+ data_disk = {
2394+ 'lun' : disk_lun ,
2395+ 'createOption' : 'Empty' ,
2396+ 'name' : parse_resource_id (disk_item )['name' ],
2397+ 'diskSizeGB' : size_gb if size_gb else default_size_gb ,
2398+ 'caching' : caching ,
2399+ 'managedDisk' : {
2400+ 'storageAccountType' : sku
2401+ }
2402+ }
23962403 else :
2397- params = ManagedDiskParameters (id = disk_item , storage_account_type = sku )
2398- data_disk = DataDisk (lun = disk_lun , create_option = DiskCreateOption .attach , managed_disk = params ,
2399- caching = caching )
2404+ data_disk = {
2405+ 'lun' : disk_lun ,
2406+ 'createOption' : 'Attach' ,
2407+ 'managedDisk' : {
2408+ 'id' : disk_item ,
2409+ 'storageAccountType' : sku
2410+ },
2411+ 'caching' : caching
2412+ }
24002413
24012414 if enable_write_accelerator :
2402- data_disk .write_accelerator_enabled = enable_write_accelerator
2403-
2404- vm .storage_profile .data_disks .append (data_disk )
2405- disk_lun = _get_disk_lun (vm .storage_profile .data_disks )
2415+ data_disk ["writeAcceleratorEnabled" ] = enable_write_accelerator
2416+
2417+ if "storageProfile" not in vm :
2418+ vm ["storageProfile" ] = {}
2419+ if "dataDisks" not in vm ["storageProfile" ]:
2420+ vm ["storageProfile" ]["dataDisks" ] = []
2421+ vm ["storageProfile" ]["dataDisks" ].append (data_disk )
2422+ disk_lun = _get_disk_lun_by_aaz (vm .get ("storageProfile" , {}).get ("dataDisks" , []))
24062423 if source_snapshots_or_disks is not None :
24072424 if new_names_of_source_snapshots_or_disks is None :
24082425 new_names_of_source_snapshots_or_disks = [None ] * len (source_snapshots_or_disks )
24092426 for disk_id , disk_name in zip (source_snapshots_or_disks , new_names_of_source_snapshots_or_disks ):
24102427 disk = {
24112428 'name' : disk_name ,
2412- 'create_option ' : 'Copy' ,
2429+ 'createOption ' : 'Copy' ,
24132430 'caching' : caching ,
24142431 'lun' : disk_lun ,
24152432 'writeAcceleratorEnabled' : enable_write_accelerator ,
@@ -2419,7 +2436,7 @@ def attach_managed_data_disk(cmd, resource_group_name, vm_name, disk=None, ids=N
24192436 }
24202437 if size_gb is not None :
24212438 disk .update ({
2422- 'diskSizeGb ' : size_gb
2439+ 'diskSizeGB ' : size_gb
24232440 })
24242441 if sku is not None :
24252442 disk .update ({
@@ -2428,14 +2445,18 @@ def attach_managed_data_disk(cmd, resource_group_name, vm_name, disk=None, ids=N
24282445 }
24292446 })
24302447 disk_lun += 1
2431- vm .storage_profile .data_disks .append (disk )
2448+ if "storageProfile" not in vm :
2449+ vm ["storageProfile" ] = {}
2450+ if "dataDisks" not in vm ["storageProfile" ]:
2451+ vm ["storageProfile" ]["dataDisks" ] = []
2452+ vm ["storageProfile" ]["dataDisks" ].append (disk )
24322453 if source_disk_restore_point is not None :
24332454 if new_names_of_source_disk_restore_point is None :
24342455 new_names_of_source_disk_restore_point = [None ] * len (source_disk_restore_point )
24352456 for disk_id , disk_name in zip (source_disk_restore_point , new_names_of_source_disk_restore_point ):
24362457 disk = {
24372458 'name' : disk_name ,
2438- 'create_option ' : 'Restore' ,
2459+ 'createOption ' : 'Restore' ,
24392460 'caching' : caching ,
24402461 'lun' : disk_lun ,
24412462 'writeAcceleratorEnabled' : enable_write_accelerator ,
@@ -2445,7 +2466,7 @@ def attach_managed_data_disk(cmd, resource_group_name, vm_name, disk=None, ids=N
24452466 }
24462467 if size_gb is not None :
24472468 disk .update ({
2448- 'diskSizeGb ' : size_gb
2469+ 'diskSizeGB ' : size_gb
24492470 })
24502471 if sku is not None :
24512472 disk .update ({
@@ -2454,9 +2475,14 @@ def attach_managed_data_disk(cmd, resource_group_name, vm_name, disk=None, ids=N
24542475 }
24552476 })
24562477 disk_lun += 1
2457- vm .storage_profile .data_disks .append (disk )
2478+ if "storageProfile" not in vm :
2479+ vm ["storageProfile" ] = {}
2480+ if "dataDisks" not in vm ["storageProfile" ]:
2481+ vm ["storageProfile" ]["dataDisks" ] = []
2482+ vm ["storageProfile" ]["dataDisks" ].append (disk )
24582483
2459- set_vm (cmd , vm )
2484+ vm = convert_show_result_to_snake_case (vm )
2485+ set_vm_by_aaz (cmd , vm )
24602486
24612487
24622488def detach_unmanaged_data_disk (cmd , resource_group_name , vm_name , disk_name ):
@@ -2476,6 +2502,8 @@ def detach_unmanaged_data_disk(cmd, resource_group_name, vm_name, disk_name):
24762502
24772503
24782504def detach_managed_data_disk (cmd , resource_group_name , vm_name , disk_name = None , force_detach = None , disk_ids = None ):
2505+ from .operations .vm import convert_show_result_to_snake_case
2506+
24792507 if disk_ids is not None :
24802508 data_disks = []
24812509 for disk_item in disk_ids :
@@ -2489,27 +2517,29 @@ def detach_managed_data_disk(cmd, resource_group_name, vm_name, disk_name=None,
24892517 return result
24902518 else :
24912519 # here we handle managed disk
2492- vm = get_vm_to_update (cmd , resource_group_name , vm_name )
2520+ vm = get_vm_to_update_by_aaz (cmd , resource_group_name , vm_name )
24932521 if not force_detach :
24942522 # pylint: disable=no-member
2495- leftovers = [d for d in vm .storage_profile .data_disks if d .name .lower () != disk_name .lower ()]
2496- if len (vm .storage_profile .data_disks ) == len (leftovers ):
2523+ leftovers = [d for d in vm .get ("storageProfile" , {}).get ("dataDisks" , [])
2524+ if d ["name" ].lower () != disk_name .lower ()]
2525+ if len (vm .get ("storageProfile" , {}).get ("dataDisks" , [])) == len (leftovers ):
24972526 raise ResourceNotFoundError ("No disk with the name '{}' was found" .format (disk_name ))
24982527 else :
2499- DiskDetachOptionTypes = cmd .get_models ('DiskDetachOptionTypes' , resource_type = ResourceType .MGMT_COMPUTE ,
2500- operation_group = 'virtual_machines' )
2501- leftovers = vm .storage_profile .data_disks
2528+ leftovers = vm .get ("storageProfile" , {}).get ("dataDisks" , [])
25022529 is_contains = False
25032530 for d in leftovers :
2504- if d . name .lower () == disk_name .lower ():
2505- d . to_be_detached = True
2506- d . detach_option = DiskDetachOptionTypes . FORCE_DETACH
2531+ if d [ " name" ] .lower () == disk_name .lower ():
2532+ d [ "toBeDetached" ] = True
2533+ d [ "detachOption" ] = "ForceDetach"
25072534 is_contains = True
25082535 break
25092536 if not is_contains :
25102537 raise ResourceNotFoundError ("No disk with the name '{}' was found" .format (disk_name ))
2511- vm .storage_profile .data_disks = leftovers
2512- set_vm (cmd , vm )
2538+ if "storageProfile" not in vm :
2539+ vm ["storageProfile" ] = {}
2540+ vm ["storageProfile" ]["dataDisks" ] = leftovers
2541+ vm = convert_show_result_to_snake_case (vm )
2542+ set_vm_by_aaz (cmd , vm )
25132543# endregion
25142544
25152545
0 commit comments