Failed to delete ACI even if begin_delete() was called correctly

Jun Ge 20 Reputation points
2024-07-26T18:20:46.53+00:00

Hi, I have a function as the following, which can call begin_delete() correctly, but the aci wasn't deleted in fact. Can you please help? Thanks.

FYI: I can delete the aci manually.

def delete_aci(task_id, logger):
  try:
    subscription_id = Config.LOGTUNNEL_SUBSCRIPTION_ID
    resource_group_name = Config.LOGTUNNEL_RESOURCE_GROUP_NAME
    credential = generate_credentials(logger)

    container_group_name = task_id + 'ACIGROUP'

    container_client = ContainerInstanceManagementClient(credential, subscription_id)
    container_client.container_groups.begin_delete(
        resource_group_name,
        container_group_name
    ).result()

    logger.log(ST_LOG, f"Container group '{container_group_name}' deletion started.")
    return 0

  except Exception as e:
    logger.log(ST_ERROR, f'{e}')
    return -1

The following is debug log:

[2024-07-26T16:40:36.018Z] Request URL: 'https://management.azure.com/subscriptions/694eb334-301a-471e-9c4c-ec0ad5bceee7/resourceGroups/support-tunnel-resource-group/providers/Microsoft.ContainerInstance/containerGroups/e6e74256-3ebb-44e8-9e9c-1734c9dda993ACIGROUPACIGROUP?api-version=REDACTED'

Request method: 'DELETE'

Request headers:

'Accept': 'application/json'

'x-ms-client-request-id': 'c8568269-4b6d-11ef-b6e2-00155da7777a'

'User-Agent': 'azsdk-python-mgmt-containerinstance/10.1.0 Python/3.11.5 (Windows-10-10.0.22621-SP0)'

'Authorization': 'REDACTED'

No body was attached to the request[2024-07-26T16:40:36.009Z] Response status: 200

Response headers:

'Cache-Control': 'no-store, no-cache'

'Pragma': 'no-cache'

'Content-Type': 'application/json; charset=utf-8'

'Expires': '-1'

'Strict-Transport-Security': 'REDACTED'

'X-Content-Type-Options': 'REDACTED'

'P3P': 'REDACTED'

'client-request-id': 'REDACTED'

'x-ms-request-id': 'e2e39b08-e82f-4a1b-9200-ea3edf604a01'

'x-ms-ests-server': 'REDACTED'

'x-ms-clitelem': 'REDACTED'

'x-ms-srs': 'REDACTED'

'X-XSS-Protection': 'REDACTED'

'Set-Cookie': 'REDACTED'

'Date': 'Fri, 26 Jul 2024 16:40:35 GMT'

'Content-Length': '1392'

[2024-07-26T16:40:36.175Z] 6524 724 07/26 12:40:36 MSG "Container group 'e6e74256-3ebb-44e8-9e9c-1734c9dda993ACIGROUPACIGROUP' deletion started." - docker_helper.py->delete_aci():347

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,978 questions
0 comments No comments
{count} votes

Accepted answer
  1. hossein jalilian 7,055 Reputation points
    2024-07-26T18:42:56.32+00:00

    Thanks for posting your question in the Microsoft Q&A forum.

    Ensure that the container_group_name is correctly constructed and matches the exact name of the container group you want to delete. Verify the name by checking the Azure portal or using Azure CLI commands like az container show, and make sure that the API version used in the request is compatible with the ContainerInstanceManagementClient.

    The begin_delete method is asynchronous, meaning the deletion request starts but doesn't wait for it to complete. You should handle this by checking the status of the operation or periodically polling the status.

    def delete_aci(task_id, logger):
        try:
            subscription_id = Config.LOGTUNNEL_SUBSCRIPTION_ID
            resource_group_name = Config.LOGTUNNEL_RESOURCE_GROUP_NAME
            credential = generate_credentials(logger)
            container_group_name = task_id + 'ACIGROUP'
            container_client = ContainerInstanceManagementClient(credential, subscription_id)
            poller = container_client.container_groups.begin_delete(
                resource_group_name,
                container_group_name
            )
            # Wait for the deletion to complete
            poller.wait()
            logger.log(ST_LOG, f"Container group '{container_group_name}' deletion completed.")
            return 0
        except Exception as e:
            logger.log(ST_ERROR, f'{e}')
            return -1
    
    

    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.