azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

Generic update should convert camelCased keys to python_case

Open milan-janecek opened this issue 9 years ago • 5 comments

Description

When i run:

az vm update -n VM_NAME-g VM_GROUP --add osProfile.secrets '{"sourceVault":{"id":"valid key vault uri"},"vaultCertificates":[{"certificateUrl": "valid uri to certificate"}]}'

I receive:

ERROR: 'sourceVault'
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\main.py", line 36, in main
    cmd_result = APPLICATION.execute(args)
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\core\application.py", line 211, in execute
    result = expanded_arg.func(params)
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\core\commands\__init__.py", line 346, in __call__
    return self.handler(*args, **kwargs)
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\core\commands\arm.py", line 407, in handler
    raise ex
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\core\commands\arm.py", line 390, in handler
    opres = setter(client, **setterargs) if client else setter(**setterargs)
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\mgmt\compute\compute\v2016_04_30_preview\operations\virtual_machines_operations.py", line 180, in create_or_update
    body_content = self._serialize.body(parameters, 'VirtualMachine')
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\msrest\serialization.py", line 301, in body
    data = _convert_to_datatype(data, data_type, self.dependencies)
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\msrest\serialization.py", line 182, in _convert_to_datatype
    getattr(data, attr), mapconfig['type'], localtypes))
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\msrest\serialization.py", line 182, in _convert_to_datatype
    getattr(data, attr), mapconfig['type'], localtypes))
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\msrest\serialization.py", line 156, in _convert_to_datatype
    param, data_type[1:-1], localtypes) for param in data
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\msrest\serialization.py", line 156, in <listcomp>
    param, data_type[1:-1], localtypes) for param in data
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\msrest\serialization.py", line 171, in _convert_to_datatype
    localtypes) for key in data
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\msrest\serialization.py", line 171, in <dictcomp>
    localtypes) for key in data
KeyError: 'sourceVault'

I guess updating osProfile.secrets is not yet supported (although--secrets in az vm create are) but would like to get this in Azure CLI as I am now forced to use Powershell's Add-​Azure​Rm​VM​Secret which seems to be the only option which works now for uploading certificates to VMs.


Environment summary

Install Method: How did you install the CLI? (e.g. pip, interactive script, apt-get, Docker, MSI, nightly)
Answer here: MSI

CLI Version: What version of the CLI and modules are installed? (Use az --version)
Answer here: 2.0.9

OS Version: What OS and version are you using?
Answer here: Windows 7 Enterprise

Shell Type: What shell are you using? (e.g. bash, cmd.exe, Bash on Windows)
Answer here: tested in both cmd.exe and gitbash, same results

milan-janecek avatar Jul 06 '17 19:07 milan-janecek

Please try the following: '{"source_vault":{"id":"valid key vault uri"},"vault_certificates":[{"certificate_url": "valid uri to certificate"}]}'

The SDK expects python_casing, not camelCasing.

tjprescott avatar Jul 06 '17 20:07 tjprescott

That worked. Thanks a lot! Although not sure if az vm update -h gives the right help. Below are examples mentioned in the help:

Examples Add or update a tag. az -n name -g group --set tags.tagName=tagValue

Remove a tag.
    az <command> -n name -g group --remove tags.tagName

Set the primary NIC of a VM.
    az <command> -n name -g group --set networkProfile.networkInterfaces[1].primary=false
    networkProfile.networkInterfaces[0].primary=true

Add a new non-primary NIC to a VM.
    az <command> -n name -g group --add networkProfile.networkInterfaces primary=false
    id=<NIC_ID>

Remove the fourth NIC from a VM.
    az <command> -n name -g group --remove networkProfile.networkInterfaces 3

Nothing there about not using standard json camelCasing.

Is python_casing mentioned somewhere else in the Azure CLI docs? Something like, if you pass json to update commands, use python_casing? If not, can we reconsider this as documentation issue?

milan-janecek avatar Jul 06 '17 21:07 milan-janecek

Hi @milan-janecek the help text is correct. The generic updates look something like <verb> <path> <value> (i.e. set myList[0] "foo"). So internally the paths are converted from camelCase to python_case. However, the value portion is always just treated as is, which is why, when you set a whole JSON object, they need to already be in python_case.

That's the explanation, but we can definitely look into applying that same conversion to the keys of a parsed JSON object.

tjprescott avatar Jul 07 '17 00:07 tjprescott

The changes @lmazuel is making to the SDK should automagically fix this, but I'll do the testing and verification on the CLI side.

tjprescott avatar Aug 02 '17 23:08 tjprescott

Thanks to @lmazuel this has been fixed for the entire Python SDK! Thanks @lmazuel!! 🎉 🎉

tjprescott avatar Aug 23 '17 19:08 tjprescott