AttributeError: 'ContainerGroupsOperations' object has no attribute 'delete' - azure

I run the following "az container delete" on old cli version successfully. However, when I upgraded to 2.28.0, it failed with error
az container delete --subscription xx --resource-group xx --name xx
Errors:
The command failed with an unexpected error. Here is the traceback:
'ContainerGroupsOperations' object has no attribute 'delete'
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 66, in delete_container
AttributeError: 'ContainerGroupsOperations' object has no attribute 'delete

This is a known issue introduced by Microsoft updating Az CLI to version 2.28.0.
There is no solution other that downgrade at the moment but MS is acknowledged.
You can track the track their responses in the official repo:
https://github.com/Azure/azure-cli/issues/19475
Still, there are some workarounds to address it.
Using REST API:
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}
Using PowerShell:
Remove-AzContainerGroup -Name ${var.resourceName} -ResourceGroupName ${var.resourceGroup} -Confirm:$False

Got the same error at DevOps jobs, week ago everything was successful. Didn't find any possibilities how to change az version from UI.
https://developercommunity.visualstudio.com/t/set-up-fixed-az-cli-version-in-my-pipeline/960733

Related

Unable to run index migration in OpenSearch

I have a docker compose running where a django backend, opensearch & opensearch dashboard are running. I have connected the backend to talk to opensearch and I'm able to query it successfully. I'm trying to create indexes using this command inside the docker container.
./manage.py opensearch --rebuild
Reference: https://django-opensearch-dsl.readthedocs.io/en/latest/getting_started/#create-and-populate-opensearchs-indices
I get the following error when I run the above command
root#ed186e462ca3:/app# ./manage.py opensearch --rebuild
/usr/local/lib/python3.6/site-packages/OpenSSL/crypto.py:8: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
from cryptography import utils, x509
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 224, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 37, in load_command_class
return module.Command()
File "/usr/local/lib/python3.6/site-packages/django_opensearch_dsl/management/commands/opensearch.py", line 32, in __init__
if settings.TESTING: # pragma: no cover
File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 80, in __getattr__
val = getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'TESTING'
Sentry is attempting to send 1 pending error messages
Waiting up to 2 seconds
Press Ctrl-C to quit
I'm not sure where I'm going wrong. Any help would be greatful.
TIA
For future reference, this was indeed a bug in django-opensearch-dsl which was fix in the 0.3.0 release.

Azure bastion failing to connect to VM

I am trying to connect to a Linux VM with a network bastion in Azure. I am running the following command.
az network bastion ssh --name "<bastion-host>" --resource-group "<resource-group>" --target-resource-id "/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.Compute/virtualMachines/<vm-name>" --auth-type password --username azureuser
And getting the error in azure CLI
Exception in thread Thread-1 (_start_tunnel):
Traceback (most recent call last):
File "threading.py", line 1009, in _bootstrap_inner
File "threading.py", line 946, in run
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/network/custom.py", line 8482, in _start_tunnel
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/network/tunnel.py", line 184, in start_server
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/network/tunnel.py", line 117, in _listen
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/network/tunnel.py", line 104, in _get_auth_token
msrestazure.azure_exceptions.CloudError: Unexpected internal error
Terminate batch job (Y/N)? y ```
I have contacted Microsoft support team about this issue and it seems, the network bastion is still under preview and it's an internal error. The response from Microsoft team was:
"Due to an improper cleanup of closed connections, this caused newer connections to fail"

az login command failure

Trying to set up Azure CLI on my Kali Linux. This is the version of kali.
kali#kali:~$ uname -a
Linux kali 5.5.0-kali2-amd64 #1 SMP Debian
5.5.17-1kali1 (2020-04-21) x86_64 GNU/Linux
After installation, when I run az login, it takes me to the browser where I enter required credentials that are accepted, and the browser then shows following message.
You have logged into Microsoft Azure!
However, in the shell window, it shows the following error.
kali#kali:~$ az login
You have logged in. Now let us find all the subscriptions to which you have access...
The command failed with an unexpected error. Here is the traceback:
'SubscriptionClient' object has no attribute 'config'
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/knack/cli.py", line 215, in invoke
cmd_result = self.invocation.execute(args)
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/_init_.py", line 654, in execute
raise ex
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/_init_.py", line 718, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/_init_.py", line 711, in _run_job
six.reraise(*sys.exc_info())
File "/usr/lib/python3/dist-packages/six.py", line 703, in reraise
raise value
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/_init_.py", line 688, in _run_job
result = cmd_copy(params)
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/_init.py", line 325, in __call_
return self.handler(*args, **kwargs)
File "/usr/lib/python3/dist-packages/azure/cli/core/_init_.py", line 782, in default_command_handler
return op(**command_args)
File "/usr/lib/python3/dist-packages/azure/cli/command_modules/profile/custom.py", line 152, in login
subscriptions = profile.find_subscriptions_on_login(
File "/usr/lib/python3/dist-packages/azure/cli/core/_profile.py", line 195, in find_subscriptions_on_login
subscriptions = subscription_finder.find_through_authorization_code_flow(
File "/usr/lib/python3/dist-packages/azure/cli/core/_profile.py", line 849, in find_through_authorization_code_flow
result = self._find_using_common_tenant(token_entry[_ACCESS_TOKEN], resource)
File "/usr/lib/python3/dist-packages/azure/cli/core/_profile.py", line 893, in _find_using_common_tenant
client = self._arm_client_factory(token_credential)
File "/usr/lib/python3/dist-packages/azure/cli/core/_profile.py", line 812, in create_arm_client_factory
configure_common_settings(cli_ctx, client)
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/client_factory.py", line 79, in configure_common_settings
client.config.enable_http_logger = True
AttributeError: 'SubscriptionClient' object has no attribute 'config'
To open an issue, please run: 'az feedback'
What does this error mean and how can this be addressed?
honestly this looks like a version mismatch on the libraries you are using? I'd probably remove az cli completely and remove all the python modules that are related to azure and reinstall it, alternatively, just use a docker image with az cli provided by microsoft:
docker run -it mcr.microsoft.com/azure-cli

Error when deploying my Visual Studio project zip file to azure "The command failed with an unexpected error. Here is the traceback:"

I have created an Asp.NET web application using Visual studio 2019 >> i publish the project to my c drive >> zip the generated files. then i wanted to deploy it to Azure web app >> i open azure command line >> i run this command:-
C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9>az webapp deployment source config-zip --resource-group "PUS" --name "TGPUS" --src " C:\pus\bin.zip"
But i got these exceptions:-
Getting scm site credentials for zip deployment
The command failed with an unexpected error. Here is the traceback:
[Errno 22] Invalid argument: 'C:\\Program Files\\Microsoft SDKs\\Azure\\.NET SDK\\v2.9\\ C:\\pus\\bin.zip'
Traceback (most recent call last):
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-64vfp5fb\knack\knack\cli.py", line 206, in invoke
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-64vfp5fb\azure-cli-core\azure\cli\core\commands\__init__.py", line 608, in execute
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-64vfp5fb\azure-cli-core\azure\cli\core\commands\__init__.py", line 666, in _run_jobs_serially
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-64vfp5fb\azure-cli-core\azure\cli\core\commands\__init__.py", line 659, in _run_job
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-64vfp5fb\six\six.py", line 696, in reraise
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-64vfp5fb\azure-cli-core\azure\cli\core\commands\__init__.py", line 636, in _run_job
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-64vfp5fb\azure-cli-core\azure\cli\core\commands\__init__.py", line 306, in __call__
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-64vfp5fb\azure-cli-core\azure\cli\core\__init__.py", line 493, in default_command_handler
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-64vfp5fb\azure-cli\azure\cli\command_modules\appservice\custom.py", line 344, in enable_zip_deploy_webapp
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-64vfp5fb\azure-cli\azure\cli\command_modules\appservice\custom.py", line 369, in enable_zip_deploy
OSError: [Errno 22] Invalid argument: 'C:\\Program Files\\Microsoft SDKs\\Azure\\.NET SDK\\v2.9\\ C:\\pus\\bin.zip'
To open an issue, please run: 'az feedback'
There is a tiny error in your command. For --src " C:\pus\bin.zip", there is a redundant white-space in
" C:\pus\bin.zip". Just remove the white-space, and it will work.
so the correct command should be:
az webapp deployment source config-zip --resource-group "PUS" --name "TGPUS" --src "C:\pus\bin.zip"
The screenshot of my test:

Error while connecting to AKS via Azure Cli from PowerShell

while connecting with Azure kubernetes cluster from windows via powershell, I am getting an error.
The command being used is -
az aks get-credentials --name clustername --resource-group rgname --subscription subsId
The command failed with an unexpected error. Here is the traceback:
'name'
Traceback (most recent call last):
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qdpilz60\knack\knack\cli.py", line 206, in invoke
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qdpilz60\azure-cli-core\azure\cli\core\commands\__init__.py", line 578, in execute
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qdpilz60\azure-cli-core\azure\cli\core\commands\__init__.py", line 636, in _run_jobs_serially
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qdpilz60\azure-cli-core\azure\cli\core\commands\__init__.py", line 629, in _run_job
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qdpilz60\six\six.py", line 693, in reraise
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qdpilz60\azure-cli-core\azure\cli\core\commands\__init__.py", line 606, in _run_job
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qdpilz60\azure-cli-core\azure\cli\core\commands\__init__.py", line 305, in __call__
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qdpilz60\azure-cli-core\azure\cli\core\__init__.py", line 485, in default_command_handler
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qdpilz60\azure-cli\azure\cli\command_modules\acs\custom.py", line 1693, in aks_get_credentials
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qdpilz60\azure-cli\azure\cli\command_modules\acs\custom.py", line 2422, in _print_or_merge_credentials
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qdpilz60\azure-cli\azure\cli\command_modules\acs\custom.py", line 1063, in merge_kubernetes_configurations
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qdpilz60\azure-cli\azure\cli\command_modules\acs\custom.py", line 1012, in _handle_merge
KeyError: 'name'
This error happens when your ~/.kube/config is structured differently than what az aks get-credentials expects, for example when certain keys are missing. See https://github.com/Azure/azure-cli/issues/10812
You can resolve this issue by deleting ~/.kube/config.

Resources