Help Center> Distributed Cache Service> API Reference> Examples> Example 3: Deleting DCS Redis Instances in Batches
Updated on 2024-03-05 GMT+08:00

Example 3: Deleting DCS Redis Instances in Batches

Scenario

This section describes how to delete DCS Redis instances in batches by calling APIs. For details about how to call APIs, see Calling APIs.

Involved APIs

Call APIs to perform the following steps required to delete DCS Redis instances in batches:

Step 1: Query the IDs of the Instances to Be Deleted

  1. Query the instance IDs.

    • URI

      URI format: GET /v2/{project_id}/instances

    • Example request

      GET https://{dcs_endpoint}/v2/7d80ae32f57b499eb8781f9a9f57c538/instances

      To obtain the value of {dcs_endpoint}, see Regions and Endpoints.

    • Example response
      {
      	"instances": [{
      		"free": null,
      		"max_memory": 1024,
      		"used_memory": 2,
      		"instance_id": "aabe73af-1db8-4401-b39c-c56996023989",
      		"name": "dcs-8b1c-000",
      		"resource_spec_code": "redis.ha.xu1.large.r2.1",
      		"engine": "Redis",
      		"engine_version": "5.0",
      		"internal_version": null,
      		"charging_mode": 0,
      		"capacity": 1,
      		"capacity_minor": null,
      		"vpc_id": "cec3dca1-3700-4305-8eb0-5669c01f05b6",
      		"vpc_name": null,
      		"ip": "192.168.0.12",
      		"domainName": "redis-aabe73a-dcs-8b1c-000.dcs.huaweicloud.com",
      		"domain_name": "redis-aabe73a-dcs-8b1c-000.dcs.huaweicloud.com",
      		"readonlyDomainName": null,
      		"readonly_domain_name": null,
      		"port": 6379,
      		"status": "RUNNING",
      		"freeze_scene": null,
      		"created_at": "2020-06-18T03:11:30.615Z",
      		"update_at": "2020-06-18T03:11:58.936Z",
      		"error_code": null,
      		"user_id": "05040c67cc00256f1f28c009a1c2a0f7",
      		"user_name": "dcstest",
      		"maintain_begin": "02:00:00",
      		"maintain_end": "06:00:00",
      		"no_password_access": "true",
      		"access_user": null,
      		"enable_publicip": false,
      		"publicip_id": null,
      		"publicip_address": null,
      		"enable_ssl": false,
      		"service_upgrade": false,
      		"service_task_id": "",
      		"enterprise_project_id": "0",
      		"security_group_id": null,
      		"tags": null,
      		"product_type": "generic",
      		"cpu_type": "x86_64",
      		"storage_type": "DRAM",
      		"task_status": null,
      		"launched_at": "2020-06-18T03:11:58.945Z",
      		"is_free": null,
      		"libos": false,
      		"cache_mode": "ha",
      		"available_zones": ["dfeb4826256b47aa828e72d7522e108c",
      		"043c7e39ecb347a08dc8fcb6c35a274e"],
      		"subnet_id": "e6eb5ff4-da2a-4323-bddc-c7b179f9aa1e",
      		"backend_addrs": null,
      		"crr_role": null,
      		"cloud_service_type_code": "hws.service.type.dcs",
      		"cloud_resource_type_code": "hws.resource.type.dcs3",
      		"support_slow_log_flag": null,
      		"ipv6": null,
      		"enable_ipv6": false,
      		"description": ""
      	},
      	{
      		"free": null,
      		"max_memory": 1024,
      		"used_memory": 2,
      		"instance_id": "9d78d0f4-a110-4bcd-8ca3-5aec414163c1",
      		"name": "dcs-8b1c-001",
      		"resource_spec_code": "redis.ha.xu1.large.r2.1",
      		"engine": "Redis",
      		"engine_version": "5.0",
      		"internal_version": null,
      		"charging_mode": 0,
      		"capacity": 1,
      		"capacity_minor": null,
      		"vpc_id": "cec3dca1-3700-4305-8eb0-5669c01f05b6",
      		"vpc_name": null,
      		"ip": "192.168.0.33",
      		"domainName": "redis-9d78d0f-dcs-8b1c-001.dcs.huaweicloud.com",
      		"domain_name": "redis-9d78d0f-dcs-8b1c-001.dcs.huaweicloud.com",
      		"readonlyDomainName": null,
      		"readonly_domain_name": null,
      		"port": 6379,
      		"status": "RUNNING",
      		"freeze_scene": null,
      		"created_at": "2020-06-18T03:11:30.618Z",
      		"update_at": "2020-06-18T03:11:58.937Z",
      		"error_code": null,
      		"user_id": "05040c67cc00256f1f28c009a1c2a0f7",
      		"user_name": "dcstest",
      		"maintain_begin": "02:00:00",
      		"maintain_end": "06:00:00",
      		"no_password_access": "true",
      		"access_user": null,
      		"enable_publicip": false,
      		"publicip_id": null,
      		"publicip_address": null,
      		"enable_ssl": false,
      		"service_upgrade": false,
      		"service_task_id": "",
      		"enterprise_project_id": "0",
      		"security_group_id": null,
      		"tags": null,
      		"product_type": "generic",
      		"cpu_type": "x86_64",
      		"storage_type": "DRAM",
      		"task_status": null,
      		"launched_at": "2020-06-18T03:11:58.943Z",
      		"is_free": null,
      		"libos": false,
      		"cache_mode": "ha",
      		"available_zones": ["dfeb4826256b47aa828e72d7522e108c",
      		"043c7e39ecb347a08dc8fcb6c35a274e"],
      		"subnet_id": "e6eb5ff4-da2a-4323-bddc-c7b179f9aa1e",
      		"backend_addrs": null,
      		"crr_role": null,
      		"cloud_service_type_code": "hws.service.type.dcs",
      		"cloud_resource_type_code": "hws.resource.type.dcs3",
      		"support_slow_log_flag": null,
      		"ipv6": null,
      		"enable_ipv6": false,
      		"description": ""
      	}],
      	"instance_num": 2
      }

  2. Record the instance_id of the instances to be deleted as required.

Step 2: Delete Instances in Batches

  • URI

    URI format: DELETE /v2/{project_id}/instances

  • Example request

    DELETE https://{dcs_endpoint}/v2/{project_id}/instances

    To obtain the value of {dcs_endpoint}, see Regions and Endpoints.

    Body:

    {
     "instances": [
      "aabe73af-1db8-4401-b39c-c56996023989",
      "9d78d0f4-a110-4bcd-8ca3-5aec414163c1"
     ]
    }
  • Example response
    {
     "results": [
      {
       "result": "success",
       "instance": "aabe73af-1db8-4401-b39c-c56996023989"
      },
      {
       "result": "success",
       "instance": "9d78d0f4-a110-4bcd-8ca3-5aec414163c1"
      }
     ]
    }

    For details about the parameters for deleting DCS Redis instances in batches, see Batch Deleting DCS Instances.