Skip to content

Commit d7f9a9c

Browse files
committed
Fixed snake case conversion error
1 parent 3189275 commit d7f9a9c

2 files changed

Lines changed: 25 additions & 21 deletions

File tree

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,13 @@ def _is_linux_os(vm):
322322

323323
def _is_linux_os_by_aaz(vm):
324324
os_type = None
325-
if vm.get("storageProfile", {}).get("osDisk", {}).get("osType", None) is not None:
326-
os_type = vm["storageProfile"]["osDisk"]["osType"]
325+
if vm.get("storage_profile", {}).get("os_disk", {}).get("os_type", None) is not None:
326+
os_type = vm["storage_profile"]["os_disk"]["os_type"]
327327
if os_type:
328328
return os_type.lower() == 'linux'
329329
# the os_type could be None for VM scaleset, let us check out os configurations
330-
if vm.get("osProfile", {}).get("linuxConfiguration", None) is not None:
331-
return bool(vm["osProfile"]["linuxConfiguration"])
330+
if vm.get("os_profile", {}).get("linux_configuration", None) is not None:
331+
return bool(vm["os_profile"]["linux_configuration"])
332332
return False
333333

334334

@@ -1722,17 +1722,15 @@ def set_vm(cmd, instance, lro_operation=None, no_wait=False):
17221722

17231723

17241724
def set_vm_by_aaz(cmd, vm, no_wait=False):
1725-
from .aaz.latest.vm import Update as _VMUpdate
1725+
from .aaz.latest.vm import Create as _VMCreate
17261726

17271727
parsed_id = _parse_rg_name(vm['id'])
17281728

1729-
class SetVM(_VMUpdate):
1729+
class SetVM(_VMCreate):
17301730
def pre_operations(self):
17311731
args = self.ctx.args
17321732
args.no_wait = no_wait
1733-
1734-
def pre_instance_update(self, instance):
1735-
instance.properties.os_profile.secrets = vm.get('osProfile', {}).get('secrets', [])
1733+
args.os_profile.secrets = vm.get('os_profile', {}).get('secrets', [])
17361734

17371735
def _output(self, *args, **kwargs):
17381736
from azure.cli.core.aaz import AAZUndefined, has_value
@@ -3310,7 +3308,9 @@ def get_vm_format_secret(cmd, secrets, certificate_store=None, keyvault=None, re
33103308
def add_vm_secret(cmd, resource_group_name, vm_name, keyvault, certificate, certificate_store=None):
33113309
from azure.mgmt.core.tools import parse_resource_id
33123310
from ._vm_utils import create_data_plane_keyvault_certificate_client, get_key_vault_base_url
3311+
from .operations.vm import convert_show_result_to_snake_case
33133312
vm = get_vm_to_update_by_aaz(cmd, resource_group_name, vm_name)
3313+
vm = convert_show_result_to_snake_case(vm)
33143314

33153315
if '://' not in certificate: # has a cert name rather a full url?
33163316
keyvault_client = create_data_plane_keyvault_certificate_client(
@@ -3323,28 +3323,28 @@ def add_vm_secret(cmd, resource_group_name, vm_name, keyvault, certificate, cert
33233323
elif certificate_store:
33243324
raise CLIError('Usage error: --certificate-store is only applicable on Windows VM')
33253325
vault_cert = {
3326-
'certificateStore': certificate_store,
3327-
'certificateUrl': certificate
3326+
'certificate_store': certificate_store,
3327+
'certificate_url': certificate
33283328
}
3329-
vault_secret_group = next((x for x in vm.get('osProfile', {}).get('secrets', [])
3330-
if x.get('sourceVault', {}).get('id', '').lower() == keyvault.lower()), None)
3329+
vault_secret_group = next((x for x in vm.get('os_profile', {}).get('secrets', [])
3330+
if x.get('source_vault', {}).get('id', '').lower() == keyvault.lower()), None)
33313331
if vault_secret_group:
3332-
vault_secret_group.get('vaultCertificates', []).append(vault_cert)
3332+
vault_secret_group.get('vault_certificates', []).append(vault_cert)
33333333
else:
33343334
vault_secret_group = {
3335-
'sourceVault': {
3335+
'source_vault': {
33363336
'id': keyvault
33373337
},
3338-
'vaultCertificates': [vault_cert]
3338+
'vault_certificates': [vault_cert]
33393339
}
33403340

3341-
if not vm.get('osProfile'):
3342-
vm['osProfile'] = {'secret': []}
3341+
if not vm.get('os_profile'):
3342+
vm['os_profile'] = {'secret': []}
33433343

3344-
if not vm.get('osProfile').get('secrets'):
3345-
vm['osProfile']['secrets'] = []
3344+
if not vm.get('os_profile').get('secrets'):
3345+
vm['os_profile']['secrets'] = []
33463346

3347-
vm['osProfile']['secrets'].append(vault_secret_group)
3347+
vm['os_profile']['secrets'].append(vault_secret_group)
33483348

33493349
vm = set_vm_by_aaz(cmd, vm)
33503350
return vm.get('osProfile', {}).get('secrets', [])
@@ -3363,6 +3363,7 @@ def list_vm_secrets(cmd, resource_group_name, vm_name):
33633363

33643364

33653365
def remove_vm_secret(cmd, resource_group_name, vm_name, keyvault, certificate=None):
3366+
from .operations.vm import convert_show_result_to_snake_case
33663367
vm = get_vm_to_update_by_aaz(cmd, resource_group_name, vm_name)
33673368

33683369
# support 2 kinds of filter:
@@ -3389,6 +3390,7 @@ def remove_vm_secret(cmd, resource_group_name, vm_name, keyvault, certificate=No
33893390
to_keep = [x for x in to_keep if x.get('vaultCertificates')] # purge all groups w/o any cert entries
33903391

33913392
vm['osProfile']['secrets'] = to_keep
3393+
vm = convert_show_result_to_snake_case(vm)
33923394
vm = set_vm_by_aaz(cmd, vm)
33933395
return vm.get('osProfile', {}).get('secrets', [])
33943396
# endregion

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ def __call__(self, *args, **kwargs):
262262

263263
def convert_show_result_to_snake_case(result):
264264
new_result = {}
265+
if "id" in result:
266+
new_result["id"] = result["id"]
265267
if "extendedLocation" in result:
266268
new_result["extended_location"] = result["extendedLocation"]
267269
if "identity" in result:

0 commit comments

Comments
 (0)