Skip to content

Commit 0c09c9a

Browse files
authored
[Compute] Fix issue #31685: az vm/vmss update Fix error with NoneType object has no attribute mode when update wireserver profile (#31855)
1 parent d0a24c7 commit 0c09c9a

File tree

4 files changed

+5627
-3477
lines changed

4 files changed

+5627
-3477
lines changed

src/azure-cli/azure/cli/command_modules/vm/_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ def load_arguments(self, _):
12461246
c.argument('v_cpus_available', type=int, min_api='2021-11-01', help='Specify the number of vCPUs available')
12471247
c.argument('v_cpus_per_core', type=int, min_api='2021-11-01', help='Specify the ratio of vCPU to physical core. Setting this property to 1 also means that hyper-threading is disabled.')
12481248
c.argument('disk_controller_type', disk_controller_type)
1249-
c.argument('enable_proxy_agent', arg_type=get_three_state_flag(), min_api='2023-09-01', help='Specify whether proxy agent feature should be enabled on the virtual machine or virtual machine scale set.')
1249+
c.argument('enable_proxy_agent', arg_type=get_three_state_flag(), min_api='2023-09-01', help='Specify whether metadata security protoco (proxy agent) feature should be enabled on the virtual machine or virtual machine scale set.')
12501250
c.argument('proxy_agent_mode', deprecate_info=c.deprecate(target='--proxy-agent-mode', redirect='--wire-server-mode'), arg_type=get_enum_type(self.get_models('Mode')), min_api='2023-09-01', help='Specify the mode that proxy agent will execute on if the feature is enabled.')
12511251
c.argument('wire_server_mode', arg_type=get_enum_type(self.get_models('Mode')), min_api='2024-11-01', help='Specify the mode that proxy agent will execute on if the feature is enabled.')
12521252
c.argument('wire_server_access_control_profile_reference_id', options_list=['--wire-server-access-control-profile-reference-id', '--wire-server-profile-id'], min_api='2024-11-01', help='Specify the access control profile version resource id of wire server.')

src/azure-cli/azure/cli/command_modules/vm/custom.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,28 +1757,31 @@ def update_vm(cmd, resource_group_name, vm_name, os_disk=None, disk_caching=None
17571757
if any(parameter is not None for parameter in proxy_agent_parameters):
17581758
ProxyAgentSettings = cmd.get_models('ProxyAgentSettings')
17591759
HostEndpointSettings = cmd.get_models('HostEndpointSettings')
1760-
wire_server = HostEndpointSettings(
1761-
mode=wire_server_mode,
1762-
in_vm_access_control_profile_reference_id=wire_server_access_control_profile_reference_id
1763-
)
1764-
imds = HostEndpointSettings(
1765-
mode=imds_mode,
1766-
in_vm_access_control_profile_reference_id=imds_access_control_profile_reference_id
1767-
)
1760+
wire_server = HostEndpointSettings()
1761+
imds = HostEndpointSettings()
17681762
if vm.security_profile is None:
17691763
vm.security_profile = SecurityProfile()
1770-
vm.security_profile.proxy_agent_settings = ProxyAgentSettings(
1771-
enabled=enable_proxy_agent, key_incarnation_id=key_incarnation_id, wire_server=wire_server, imds=imds)
1764+
vm.security_profile.proxy_agent_settings = ProxyAgentSettings(wire_server=wire_server, imds=imds)
17721765
elif vm.security_profile.proxy_agent_settings is None:
1773-
vm.security_profile.proxy_agent_settings = ProxyAgentSettings(
1774-
enabled=enable_proxy_agent, key_incarnation_id=key_incarnation_id, wire_server=wire_server, imds=imds)
1766+
vm.security_profile.proxy_agent_settings = ProxyAgentSettings(wire_server=wire_server, imds=imds)
17751767
else:
1768+
if vm.security_profile.proxy_agent_settings.wire_server is None:
1769+
vm.security_profile.proxy_agent_settings.wire_server = wire_server
1770+
if vm.security_profile.proxy_agent_settings.imds is None:
1771+
vm.security_profile.proxy_agent_settings.imds = imds
1772+
1773+
if enable_proxy_agent is not None:
17761774
vm.security_profile.proxy_agent_settings.enabled = enable_proxy_agent
1775+
if key_incarnation_id is not None:
17771776
vm.security_profile.proxy_agent_settings.key_incarnation_id = key_incarnation_id
1777+
if wire_server_mode is not None:
17781778
vm.security_profile.proxy_agent_settings.wire_server.mode = wire_server_mode
1779+
if wire_server_access_control_profile_reference_id is not None:
17791780
vm.security_profile.proxy_agent_settings.wire_server.in_vm_access_control_profile_reference_id = \
17801781
wire_server_access_control_profile_reference_id
1782+
if imds_mode is not None:
17811783
vm.security_profile.proxy_agent_settings.imds.mode = imds_mode
1784+
if imds_access_control_profile_reference_id is not None:
17821785
vm.security_profile.proxy_agent_settings.imds.in_vm_access_control_profile_reference_id = \
17831786
imds_access_control_profile_reference_id
17841787

@@ -4252,27 +4255,31 @@ def update_vmss(cmd, resource_group_name, name, license_type=None, no_wait=False
42524255
SecurityProfile = cmd.get_models('SecurityProfile')
42534256
ProxyAgentSettings = cmd.get_models('ProxyAgentSettings')
42544257
HostEndpointSettings = cmd.get_models('HostEndpointSettings')
4255-
wire_server = HostEndpointSettings(
4256-
mode=wire_server_mode,
4257-
in_vm_access_control_profile_reference_id=wire_server_access_control_profile_reference_id
4258-
)
4259-
imds = HostEndpointSettings(
4260-
mode=imds_mode,
4261-
in_vm_access_control_profile_reference_id=imds_access_control_profile_reference_id
4262-
)
4258+
wire_server = HostEndpointSettings()
4259+
imds = HostEndpointSettings()
42634260
if vmss.virtual_machine_profile.security_profile is None:
42644261
vmss.virtual_machine_profile.security_profile = SecurityProfile()
42654262
vmss.virtual_machine_profile.security_profile.proxy_agent_settings = ProxyAgentSettings(
4266-
enabled=enable_proxy_agent, wire_server=wire_server, imds=imds)
4263+
wire_server=wire_server, imds=imds)
42674264
elif vmss.virtual_machine_profile.security_profile.proxy_agent_settings is None:
42684265
vmss.virtual_machine_profile.security_profile.proxy_agent_settings = ProxyAgentSettings(
4269-
enabled=enable_proxy_agent, wire_server=wire_server, imds=imds)
4266+
wire_server=wire_server, imds=imds)
42704267
else:
4268+
if vmss.virtual_machine_profile.security_profile.proxy_agent_settings.wire_server is None:
4269+
vmss.virtual_machine_profile.security_profile.proxy_agent_settings.wire_server = wire_server
4270+
if vmss.virtual_machine_profile.security_profile.proxy_agent_settings.imds is None:
4271+
vmss.virtual_machine_profile.security_profile.proxy_agent_settings.imds = imds
4272+
4273+
if enable_proxy_agent is not None:
42714274
vmss.virtual_machine_profile.security_profile.proxy_agent_settings.enabled = enable_proxy_agent
4275+
if wire_server_mode is not None:
42724276
vmss.virtual_machine_profile.security_profile.proxy_agent_settings.wire_server.mode = wire_server_mode
4277+
if wire_server_access_control_profile_reference_id is not None:
42734278
vmss.virtual_machine_profile.security_profile.proxy_agent_settings.wire_server. \
42744279
in_vm_access_control_profile_reference_id = wire_server_access_control_profile_reference_id
4280+
if imds_mode is not None:
42754281
vmss.virtual_machine_profile.security_profile.proxy_agent_settings.imds.mode = imds_mode
4282+
if imds_access_control_profile_reference_id is not None:
42764283
vmss.virtual_machine_profile.security_profile.proxy_agent_settings.imds. \
42774284
in_vm_access_control_profile_reference_id = imds_access_control_profile_reference_id
42784285

0 commit comments

Comments
 (0)