weixin_40001025
weixin_40001025
2020-12-01 11:35

az network nic update --set error "string indices must be integers"

Description

Outline the issue here:

Hi I am trying to update a property of a nic but the cli show this error


for i in $(az network nic list --query "[?contains(name, 'mySearchString')]".id --output tsv) ; do az network nic update --ids ${i} --set ipConfigurations[0].loadBalancerBackendAddressPools=MybackendPoolName ; done

string indices must be integers
Traceback (most recent call last):
  File "/opt/az/lib/python3.6/site-packages/azure/cli/main.py", line 36, in main
    cmd_result = APPLICATION.execute(args)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/application.py", line 203, in execute
    result = expanded_arg.func(params)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 278, in __call__
    return self.handler(*args, **kwargs)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/arm.py", line 349, in handler
    raise ex
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/arm.py", line 332, in handler
    opres = setter(client, **setterargs) if client else setter(**setterargs)
  File "/opt/az/lib/python3.6/site-packages/azure/mgmt/network/v2017_03_01/operations/network_interfaces_operations.py", line 233, in create_or_update
    body_content = self._serialize.body(parameters, 'NetworkInterface')
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 301, in body
    data = _convert_to_datatype(data, data_type, self.dependencies)
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 182, in _convert_to_datatype
    getattr(data, attr), mapconfig['type'], localtypes))
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 156, in _convert_to_datatype
    param, data_type[1:-1], localtypes) for param in data
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 156, in <listcomp>
    param, data_type[1:-1], localtypes) for param in data
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 182, in _convert_to_datatype
    getattr(data, attr), mapconfig['type'], localtypes))
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 156, in _convert_to_datatype
    param, data_type[1:-1], localtypes) for param in data
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 156, in <listcomp>
    param, data_type[1:-1], localtypes) for param in data
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 171, in _convert_to_datatype
    localtypes) for key in data
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 171, in <dictcomp>
    localtypes) for key in data
TypeError: string indices must be integers
string indices must be integers
Traceback (most recent call last):
  File "/opt/az/lib/python3.6/site-packages/azure/cli/main.py", line 36, in main
    cmd_result = APPLICATION.execute(args)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/application.py", line 203, in execute
    result = expanded_arg.func(params)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 278, in __call__
    return self.handler(*args, **kwargs)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/arm.py", line 349, in handler
    raise ex
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/arm.py", line 332, in handler
    opres = setter(client, **setterargs) if client else setter(**setterargs)
  File "/opt/az/lib/python3.6/site-packages/azure/mgmt/network/v2017_03_01/operations/network_interfaces_operations.py", line 233, in create_or_update
    body_content = self._serialize.body(parameters, 'NetworkInterface')
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 301, in body
    data = _convert_to_datatype(data, data_type, self.dependencies)
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 182, in _convert_to_datatype
    getattr(data, attr), mapconfig['type'], localtypes))
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 156, in _convert_to_datatype
    param, data_type[1:-1], localtypes) for param in data
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 156, in <listcomp>
    param, data_type[1:-1], localtypes) for param in data
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 182, in _convert_to_datatype
    getattr(data, attr), mapconfig['type'], localtypes))
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 156, in _convert_to_datatype
    param, data_type[1:-1], localtypes) for param in data
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 156, in <listcomp>
    param, data_type[1:-1], localtypes) for param in data
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 171, in _convert_to_datatype
    localtypes) for key in data
  File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 171, in <dictcomp>
    localtypes) for key in data
TypeError: string indices must be integers
</dictcomp></listcomp></listcomp></dictcomp></listcomp></listcomp>

Environment summary

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

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

$ az --version azure-cli (2.0.6)

acr (2.0.4) acs (2.0.6) appservice (0.1.6) batch (2.0.4) cdn (0.0.2) cloud (2.0.2) cognitiveservices (0.1.2) command-modules-nspkg (2.0.0) component (2.0.4) configure (2.0.6) core (2.0.6) cosmosdb (0.1.6) dla (0.0.6) dls (0.0.6) feedback (2.0.2) find (0.2.2) interactive (0.3.2) iot (0.1.5) keyvault (2.0.4) lab (0.0.4) monitor (0.0.4) network (2.0.6) nspkg (3.0.0) profile (2.0.4) rdbms (0.0.1) redis (0.2.3) resource (2.0.6) role (2.0.4) sf (1.0.1) sql (2.0.3) storage (2.0.6) vm (2.0.6)

Python (Linux) 3.6.1 (default, May 18 2017, 14:59:59) [GCC 4.8.4]

Python location '/opt/az/bin/python3'

OS Version: What OS and version are you using?
Answer here: Distributor ID: Ubuntu Description: Ubuntu 14.04.5 LTS Release: 14.04 Codename: trusty

Shell Type: What shell are you using? (e.g. bash, cmd.exe, Bash on Windows)
Answer here: bash

该提问来源于开源项目:Azure/azure-cli

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • weixin_39583521 weixin_39583521 5月前

    Is there a reason you aren't just using the az network nic ip-config address-pool add command?

    点赞 评论 复制链接分享
  • weixin_39583521 weixin_39583521 5月前

    It looks like your syntax is wrong: --set ipConfigurations[0].loadBalancerBackendAddressPools=MybackendPoolName

    Since this is a collection, you could add to the collection with: --add ipConfigurations[0].loadBalancerBackendAddressPools {'id': 'myBackendPoolID'}

    Or you could replace the entire collection with: --set ipConfigurations[0].loadBalancerBackendAddressPools=[{'id': 'MybackendPoolID'}]

    点赞 评论 复制链接分享
  • weixin_40001025 weixin_40001025 5月前

    Hi

    Thanks for the answer. I was based in a script of azure official documentation process, so

    I have finally used this in my script

    bash
    for i in $(az network nic list --query "[?contains(name, 'mySearchString')]".ipConfigurations[0].id --output tsv) ; do
    
        az network nic ip-config address-pool add --address-pool /
        $(az network lb address-pool list --resource-group ${rgName} --lb-name ${elbName} /
        --query "[?name=='${elbBePoolName}']".id --output tsv) --ids ${i}
    
    done
    

    But, I think the help about this questions (properties, set, add, etc.) is not too clear

    Generic Update Arguments --add : Add an object to a list of objects by specifying a path and key value pairs. Example: --add property.listProperty <key=value, string or JSON string>. --remove : Remove a property or an element from a list. Example: --remove property.list OR --remove propertyToRemove. --set : Update an object by specifying a property path and value to set. Example: --set property1.property2=<value>.

    Some real examples with index, values, collections... like you shows before (I have not tested it), could help the users if they are added to azure official documentation and cli help.

    Thanks

    点赞 评论 复制链接分享
  • weixin_39583521 weixin_39583521 5月前

    Absolutely. This is covered by issue #1582.

    点赞 评论 复制链接分享
  • weixin_39720865 weixin_39720865 5月前

    14830

    点赞 评论 复制链接分享

相关推荐