Exemplo 3: Exclusão de instâncias do DCS Redis em lotes
Cenário
Esta seção descreve como excluir instâncias do DCS Redis em lotes chamando as API. Para obter detalhes sobre como chamar as API, consulte Chamada das API.
As API envolvidas
Chame as API para executar as seguintes etapas necessárias para excluir instâncias do DCS Redis em lotes:
Passo 1: Consultar os ID das instâncias a serem excluídas
- Consulte os ID de instância.
- URI
- Exemplo de solicitação
GET https://{dcs_endpoint}/v2/7d80ae32f57b499eb8781f9a9f57c538/instances
Para obter o valor de {dcs_endpoint}, consulte Regiões e endpoints.
- Exemplo de resposta
{ "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 }
- Registre o instance_id das instâncias a serem excluídas conforme necessário.
Passo 2: Excluir instâncias em lotes
- URI
- Exemplo de solicitação
DELETE https://{dcs_endpoint}/v2/{project_id}/instances
Para obter o valor de {dcs_endpoint}, consulte Regiões e endpoints.
Corpo:
{ "instances": [ "aabe73af-1db8-4401-b39c-c56996023989", "9d78d0f4-a110-4bcd-8ca3-5aec414163c1" ] }
- Exemplo de resposta
{ "results": [ { "result": "success", "instance": "aabe73af-1db8-4401-b39c-c56996023989" }, { "result": "success", "instance": "9d78d0f4-a110-4bcd-8ca3-5aec414163c1" } ] }
Para obter detalhes sobre os parâmetros para a exclusão de instâncias do DCS Redis em lotes, consulte Exclusão de instâncias de DCS em massa.