azure-cli: "az container logs" does not work in 2.28.0

Describe the bug

Command Name az container logs does not work in 2.28.0. I works fine in 2.27.2

Errors:

The command failed with an unexpected error. Here is the traceback:
'ContainerInstanceManagementClient' object has no attribute 'container'
Traceback (most recent call last):
  File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 231, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 657, in execute
    raise ex
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 720, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 691, in _run_job
    result = cmd_copy(params)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 328, in __call__
    return self.handler(*args, **kwargs)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/command_operation.py", line 112, in handler
    client = self.client_factory(self.cli_ctx, command_args) if self.client_factory else None
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/container/_client_factory.py", line 18, in cf_container
    return _container_instance_client_factory(cli_ctx).container
AttributeError: 'ContainerInstanceManagementClient' object has no attribute 'container'

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • Put any pre-requisite steps here…
  • az container logs -g xxxx -n xxxx

Expected Behavior

Logs from the container should be shown.

Environment Summary

Linux-5.13.12-x86_64-with-debian-11.0, Debian GNU/Linux 11 (bullseye)
Python 3.6.10
Installer: DEB

azure-cli 2.28.0

Extensions:
portal 0.1.1
log-analytics 0.2.2
import-export 0.1.1

Additional Context

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 25
  • Comments: 32 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I am also having this problem with the az container exec ... command. I get a similar error message:

The command failed with an unexpected error. Here is the traceback:
'ContainerInstanceManagementClient' object has no attribute 'container'
Traceback (most recent call last):
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 231, in invoke
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 657, in execute
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 720, in _run_jobs_serially
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 691, in _run_job
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 328, in __call__
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/container/custom.py", line 609, in container_exec
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/container/_client_factory.py", line 18, in cf_container
AttributeError: 'ContainerInstanceManagementClient' object has no attribute 'container'
To open an issue, please run: 'az feedback'

(azure-cli installed via chocolatey)

Verified that 2.29.0 works fine as before.

Why is the latest installer linked to this broken version? MS, please downgrade on your website. I was trying the CLI for the first time yesterday and assumed I was doing something wrong. I finally found this thread and downgraded and everything is fine. I lost half a day because while you have known about this bug for a month you still direct people to the broken version. Literally the first thing I wanted to do with my first container was of course “az container exec”. This issue is keeping people from adopting your tools.

+1 Indeed @guywood13 , I had the same issue yesterday. I have created a task to downgrade az cli to the previous version


- task: Bash@3
  displayName: 'Change version of Az CLI'
  inputs:
    targetType: inline
    script: |
      sudo apt-get update
      sudo apt-get install ca-certificates curl apt-transport-https lsb-release gnupg
      curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null
      AZ_REPO=$(lsb_release -cs)
      echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | sudo tee /etc/apt/sources.list.d/azure-cli.list
      sudo apt-get update
      sudo apt-get install --allow-downgrades azure-cli=2.27.2-1~bionic

+1 Plus MS have upgraded their MS hosted agents in Azure DevOps on 13th to this version so downgrading isn’t easy.

I’m running az with docker for now:

$ cat az
#!/usr/bin/env bash

if [ ! -d ${XDG_DATA_HOME}/docker-az ] ; then
  echo "\${XDG_DATA_HOME}/docker-az does not exist. Aborting"
  exit 1
fi

docker run -u $(id -u):$(id -g) -v ${XDG_DATA_HOME}/docker-az:/home/az -e HOME=/home/az --rm -i mcr.microsoft.com/azure-cli:2.27.2 az "${@}"

Hope this helps someone!

if your use-case is DELETE, here is a workaround that avoids downgrading the CLI, and uses it to take care of the auth

RESOURCE_GROUP=my-rg
ACI_CONTAINER_NAME=containername
SUBSCRIPTION_ID="xxxxxxxxxxxxxxxxxxxxxxxx"
az rest --method delete \
        --uri "/subscriptions/{subscriptionId}/resourceGroups/${RESOURCE_GROUP}/providers/Microsoft.ContainerInstance/containerGroups/${ACI_CONTAINER_NAME}?api-version=2019-12-01" \
        --subscription ${SUBSCRIPTION_ID}

there is a gigantic blocker if you are using AzureCli Task on Azure DevOps. There is no way to specify to this task the version to be use, so latest is always used .

@mhomm I am getting the below error when i tried to downgrade… I also tried with 2.27.1 and got a similar error. Any idea?

E: Version ‘2.27.2-1~bionic’ for ‘azure-cli’ was not found

You might need a different version, for me 2.27.2-1~focal worked. See the link below for other versions.

https://pkgs.org/download/azure-cli

As @NakagawaMakoto mention, after I downgrade to 2.27.2 exec command works nicely. Here is link for installer https://azurecliprod.blob.core.windows.net/msi/azure-cli-2.27.2.msi