Skip to content

Commit 92a78f0

Browse files
committed
Updated code to fix generic --add in update command
1 parent da4c054 commit 92a78f0

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4325,8 +4325,8 @@ def get_vmss_modified_by_aaz(cmd, resource_group_name, name, instance_id=None, s
43254325
vms["storageProfile"]["imageReference"] = None
43264326
return vms
43274327

4328-
from .operations.vmss import VMSSShow
4329-
vmss = VMSSShow(cli_ctx=cmd.cli_ctx)(command_args={
4328+
from .operations.vmss import VMSSShowForUpdate
4329+
vmss = VMSSShowForUpdate(cli_ctx=cmd.cli_ctx)(command_args={
43304330
'resource_group': resource_group_name,
43314331
"vm_scale_set_name": name,
43324332
})

‎src/azure-cli/azure/cli/command_modules/vm/operations/vmss.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,40 @@ def _output(self, *args, **kwargs):
7070
return result
7171

7272

73+
_VMSS_IP_CONFIG_OPTIONAL_COLLECTIONS = (
74+
'applicationGatewayBackendAddressPools',
75+
'applicationSecurityGroups',
76+
'loadBalancerBackendAddressPools',
77+
'loadBalancerInboundNatPools',
78+
)
79+
80+
81+
def _normalize_vmss_generic_update_collections(vmss):
82+
# AAZ omits unset optional properties, while generic `--add` needs them present as None.
83+
vm_profile = vmss.get('virtualMachineProfile')
84+
network_profile = vm_profile.get('networkProfile') if isinstance(vm_profile, dict) else None
85+
nic_configs = network_profile.get('networkInterfaceConfigurations') if isinstance(network_profile, dict) else None
86+
if not isinstance(nic_configs, list):
87+
return vmss
88+
for nic_config in nic_configs:
89+
ip_configs = nic_config.get('ipConfigurations') if isinstance(nic_config, dict) else None
90+
if not isinstance(ip_configs, list):
91+
continue
92+
for ip_config in ip_configs:
93+
if isinstance(ip_config, dict):
94+
for collection in _VMSS_IP_CONFIG_OPTIONAL_COLLECTIONS:
95+
ip_config.setdefault(collection, None)
96+
return vmss
97+
98+
99+
class VMSSShowForUpdate(VMSSShow):
100+
"""Show a VMSS with optional IP-config collections initialized for generic update."""
101+
102+
def _output(self, *args, **kwargs):
103+
result = super()._output(*args, **kwargs)
104+
return _normalize_vmss_generic_update_collections(result)
105+
106+
73107
class VMSSPatch(_VMSSPatch):
74108

75109
def _output(self, *args, **kwargs):

0 commit comments

Comments
 (0)