1818from azure .cli .core .azclierror import AzureConnectionError
1919from azure .cli .core .azclierror import ForbiddenError
2020from azure .cli .core ._profile import Profile
21- from azure .core .exceptions import ResourceNotFoundError as ComputeClientResourceNotFoundError
21+ from azure .core .exceptions import HttpResponseError
2222from azext_serialconsole ._client_factory import cf_serialconsole
2323from azext_serialconsole ._client_factory import cf_serial_port
2424
@@ -602,34 +602,27 @@ def check_resource(cli_ctx, resource_group_name, vm_vmss_name, vmss_instanceid):
602602 check_serial_console_enabled (cli_ctx , storage_account_region )
603603
604604 if vmss_instanceid :
605- if 'osName' in result . additional_properties and "windows" in result .additional_properties [ 'osName' ] .lower ():
605+ if "windows" in result .get ( 'osName' , '' ) .lower ():
606606 GV .os_is_windows = True
607607
608- power_state = ',' .join (
609- [ s . display_status for s in result . statuses if s .code .startswith ('PowerState/' )]).lower ()
608+ power_state = ',' .join ([ s . get ( 'displayStatus' ) for s in result . get ( 'statuses' , [])
609+ if s .get ( ' code' , '' ) .startswith ('PowerState/' )]).lower ()
610610 if "deallocating" in power_state or "deallocated" in power_state :
611611 error_message = "Azure Serial Console requires a virtual machine to be running."
612612 recommendation = 'Use "az vmss start" to start the Virtual Machine.'
613- raise AzureConnectionError (
614- error_message , recommendation = recommendation )
613+ raise AzureConnectionError (error_message , recommendation = recommendation )
615614 else :
616- if (result .instance_view is not None and
617- result .instance_view .os_name is not None and
618- "windows" in result .instance_view .os_name .lower ()):
615+ if "windows" in result .get ('instanceView' , {}).get ('osName' , '' ).lower ():
619616 GV .os_is_windows = True
620- if (result .storage_profile is not None and
621- result .storage_profile .image_reference is not None and
622- result .storage_profile .image_reference .offer is not None and
623- "windows" in result .storage_profile .image_reference .offer .lower ()):
617+ if "windows" in result .get ('storageProfile' , {}).get ('imageReference' , {}).get ('offer' , '' ).lower ():
624618 GV .os_is_windows = True
625619
626- power_state = ',' .join (
627- [ s . display_status for s in result . instance_view . statuses if s .code .startswith ('PowerState/' )])
620+ power_state = ',' .join ([ s . get ( 'displayStatus' ) for s in result . get ( 'instanceView' , {}). get ( 'statuses' , [])
621+ if s .get ( ' code' , '' ) .startswith ('PowerState/' )])
628622 if "deallocating" in power_state or "deallocated" in power_state :
629623 error_message = "Azure Serial Console requires a virtual machine to be running."
630624 recommendation = 'Use "az vm start" to start the Virtual Machine.'
631- raise AzureConnectionError (
632- error_message , recommendation = recommendation )
625+ raise AzureConnectionError (error_message , recommendation = recommendation )
633626
634627
635628def connect_serialconsole (cmd , resource_group_name , vm_vmss_name , vmss_instanceid = None ):
@@ -679,7 +672,7 @@ def disable_serialconsole(cmd):
679672
680673
681674def get_region_from_storage_account (cli_ctx , resource_group_name , vm_vmss_name , vmss_instanceid ):
682- from azure .cli .command_modules .vm .operations . vmss_vms import VMSSVMSShow
675+ from azure .cli .command_modules .vm .aaz . latest . vmss . vms . instance_view import Show as VMSSVMSInstanceView
683676 from azure .cli .command_modules .vm .operations .vm import VMShow
684677 from azure .cli .command_modules .vm .operations .vmss import VMSSShow
685678 from azext_serialconsole ._client_factory import storage_client_factory
@@ -693,10 +686,9 @@ def get_region_from_storage_account(cli_ctx, resource_group_name, vm_vmss_name,
693686 command_args = {
694687 'instance_id' : vmss_instanceid ,
695688 'resource_group' : resource_group_name ,
696- 'vm_scale_set_name' : vm_vmss_name ,
697- 'expand' : 'instanceView'
689+ 'vm_scale_set_name' : vm_vmss_name
698690 }
699- result_data = VMSSVMSShow (cli_ctx = cli_ctx )(command_args = command_args )
691+ result_data = VMSSVMSInstanceView (cli_ctx = cli_ctx )(command_args = command_args )
700692 result = result_data
701693
702694 if result_data .get ('bootDiagnostics' ) is None :
@@ -723,14 +715,14 @@ def get_region_from_storage_account(cli_ctx, resource_group_name, vm_vmss_name,
723715 }
724716 result_data = VMShow (cli_ctx = cli_ctx )(command_args = command_args )
725717 result = result_data
726- except ComputeClientResourceNotFoundError as e :
718+ except HttpResponseError as e :
727719 try :
728720 command_args = {
729721 'resource_group' : resource_group_name ,
730722 'vm_scale_set_name' : vm_vmss_name
731723 }
732724 VMSSShow (cli_ctx = cli_ctx )(command_args = command_args )
733- except ComputeClientResourceNotFoundError :
725+ except HttpResponseError :
734726 raise e from e
735727 error_message = e .message
736728 recommendation = ("We found that you specified a Virtual Machine Scale Set and not a VM. "
0 commit comments