更新时间:2024-02-04 GMT+08:00
分享

查询实例列表

功能介绍

根据指定条件查询实例列表。

调用方法

请参见如何调用API

URI

GET /v3.1/{project_id}/instances

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

租户在某一Region下的project ID。

获取方法请参见获取项目ID

表2 Query参数

参数

是否必选

参数类型

描述

id

String

实例ID。“*”为系统保留字符,如果id是以“*”起始,表示按照“*”后面的值模糊匹配,否则,按照id精确匹配查询。不能只传入“*”。

name

String

实例名称。

“*”为系统保留字符,如果name是以“*”起始,表示按照“*”后面的值模糊匹配,否则,按照name精确匹配查询。不能只传入“*”。

type

String

按照实例类型查询。目前仅支持Cluster。

datastore_type

String

数据库类型,现在只支持gaussdb-mysql。

vpc_id

String

虚拟私有云ID。

subnet_id

String

子网的网络ID信息。

private_ip

String

读写内网IP地址。

readonly_private_ip

String

读内网IP地址。

proxy_ip

String

读写分离IP地址。

offset

Integer

索引位置,偏移量。从第一条数据偏移offset条数据后开始查询,默认为0(偏移0条数据,表示从第一条数据开始查询),必须为数字,不能为负数。

limit

Integer

查询记录数。默认为100,不能为负数,最小值为1,最大值为100。

tags

String

根据实例标签键值对进行查询。

  • {key}表示标签键。

  • {value}表示标签值。

如果同时使用多个标签键值对进行查询,中间使用逗号分隔开,表示查询同时包含指定标签键值对的实例。key不能重复,key之间是与的关系。

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。

通过调用IAM服务获取用户Token接口获取。

请求响应成功后在响应消息头中包含的“X-Subject-Token”的值即为Token值。

X-Language

String

请求语言类型。默认en-us。 取值范围:

  • en-us

  • zh-cn

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

instances

Array of MysqlInstanceListInfoUnifyStatus objects

实例列表信息。

total_count

Integer

总记录数。

表5 MysqlInstanceListInfoUnifyStatus

参数

参数类型

描述

id

String

实例ID,严格匹配UUID规则。

name

String

创建的实例名称。

status

String

实例状态。

取值:

  • 值为“creating”,表示实例正在创建。

  • 值为“normal”,表示实例正常。

  • 值为“abnormal”,表示实例异常。

  • 值为“createfail”,表示实例创建失败。

private_ips

Array of strings

实例写内网IP地址列表。弹性云服务器创建成功后该值存在,其他情况下为空字列表。

proxy_ips

Array of strings

实例读写分离IP地址列表。GaussDB(for MySQL)实例开启代理成功后该值存在,其他情况下为空列表。

readonly_private_ips

Array of strings

实例读内网IP地址列表。弹性云服务器创建成功后该值存在,其他情况下为空列表。

public_ips

Array of strings

实例外网IP地址列表。

port

String

数据库端口号。

type

String

实例类型,取值为“Cluster”。

region

String

实例所在区域。

datastore

MysqlDatastoreWithKernelVersion object

数据库信息。

created

String

创建时间,格式为"yyyy-mm-ddThh:mm:ssZ"。

其中,T指某个时间的开始;Z指时区偏移量,例如偏移1个小时显示为+0100。

updated

String

更新时间,格式与"created"字段对应格式完全相同。

db_user_name

String

默认用户名。

vpc_id

String

虚拟私有云ID。

subnet_id

String

子网的网络ID信息。

security_group_id

String

安全组ID。

flavor_ref

String

规格码。

flavor_info

MysqlFlavorInfo object

flavor规格信息。

volume

MysqlVolumeInfo object

存储盘信息。

backup_strategy

MysqlBackupStrategy object

自动备份策略。

enterprise_project_id

String

企业项目ID。

time_zone

String

时区。

charge_info

MysqlChargeInfo object

计费类型信息,支持包年包月和按需,默认为按需。

dedicated_resource_id

String

专属资源池ID,只有数据库实例属于专属资源池才会返回该参数。

tags

Array of InstanceTagItem objects

标签列表。

表6 MysqlDatastoreWithKernelVersion

参数

参数类型

描述

type

String

数据库引擎,现在只支持gaussdb-mysql。

version

String

数据库版本。

kernel_version

String

数据库内核版本。

表7 MysqlFlavorInfo

参数

参数类型

描述

vcpus

String

CPU核数。

ram

String

内存大小,单位GB。

表8 MysqlVolumeInfo

参数

参数类型

描述

type

String

磁盘类型。

size

String

已使用磁盘大小,单位GB。

表9 MysqlBackupStrategy

参数

参数类型

描述

start_time

String

自动备份开始时间段。自动备份将在该时间一个小时内触发。

取值范围:非空,格式必须为hh:mm-HH:MM且有效,当前时间指UTC时间。

  1. HH取值必须比hh大1。

  2. mm和MM取值必须相同,且取值必须为00。

keep_days

String

自动备份保留天数,取值范围:1-732。

表10 MysqlChargeInfo

参数

参数类型

描述

charge_mode

String

计费模式。

取值范围:

  • prePaid:预付费,即包年/包月。

  • postPaid:后付费,即按需付费。

枚举值:

  • prePaid

  • postPaid

period_type

String

订购周期类型。

取值范围:

  • month:包月。

  • year:包年。

说明:“charge_mode”为“prePaid”时生效,且为必选值。

枚举值:

  • month

  • year

period_num

Integer

“charge_mode”为“prePaid”时生效,且为必选值,指定订购的时间。

取值范围:

  • “period_type”为“month”时,取值为1~9。

  • “period_type”为“year”时,取值为1~3。

is_auto_renew

String

创建包年/包月实例时可指定,表示是否自动续订,续订的周期和原周期相同,且续订时会自动支付。

  • true:为自动续订。

  • false:为不自动续订,默认该方式。

is_auto_pay

String

创建包年/包月实例时可指定,表示是否自动从客户的帐户中支付,此字段不影响自动续订的支付方式。

  • true:为自动支付,默认该方式。

  • false:为手动支付。

表11 InstanceTagItem

参数

参数类型

描述

key

String

标签键。

value

String

标签值。

状态码: 400

表12 响应Body参数

参数

参数类型

描述

error_code

String

错误码。

error_msg

String

错误消息。

状态码: 500

表13 响应Body参数

参数

参数类型

描述

error_code

String

错误码。

error_msg

String

错误消息。

请求示例

查询GaussDB(for MySQL)实例列表,读写内网IP地址是192.168.0.142。

GET        https://{endpoint}/v3.1/054e292c9880d4992f02c0196d3ea468/instances?id=61a4ea66210545909d74a05c27a7179ein07&name=gaussdb-mysql-instance01&type=Cluster&datastore_type=gaussdb-mysql&vpc_id=3cedfc54-b105-4652-a4e0-847b11576b58&subnet_id=c1cfa53c-65d3-431e-8552-326bf310c7ad&private_ip=192.168.0.142&offset=0&limit=10&tags=taurusKey1=value1

响应示例

状态码: 200

Success.

{
  "total_count" : 1,
  "instances" : [ {
    "id" : "61a4ea66210545909d74a05c27a7179ein07",
    "name" : "gaussdb-mysql-instance01",
    "status" : "normal",
    "port" : 3306,
    "type" : "Cluster",
    "private_ips" : [ "192.168.0.142" ],
    "readonly_private_ips" : [ "192.168.0.228", "192.168.0.165" ],
    "proxy_ips" : [ "192.168.0.15" ],
    "db_user_name" : "root",
    "region" : "cn-north-4",
    "datastore" : {
      "type" : "gaussdb-mysql",
      "version" : "8.0",
      "kernel_version" : "2.0.29.1"
    },
    "created" : "2018-08-20T02:33:49_0800",
    "updated" : "2018-08-20T02:33:49_0800",
    "volume" : {
      "type" : "POOL",
      "size" : 100
    },
    "vpc_id" : "3cedfc54-b105-4652-a4e0-847b11576b58",
    "subnet_id" : "c1cfa53c-65d3-431e-8552-326bf310c7ad",
    "security_group_id" : "fc577a1a-f202-424a-977f-24faec3fdd55",
    "flavor_ref" : "gaussdb.mysql.c3.small.4",
    "flavor_info" : {
      "vcpus" : 8,
      "ram" : 16
    },
    "backup_strategy" : {
      "start_time" : "19:00-20:00",
      "keep_days" : 7
    },
    "charge_info" : {
      "charge_mode" : "postPaid"
    },
    "enterprise_project_id" : 0,
    "time_zone" : "UTC",
    "tags" : [ {
      "key" : "taurusKey1",
      "value" : "value1"
    } ]
  } ]
}

SDK代码示例

SDK代码示例如下。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.gaussdb.v3.region.GaussDBRegion;
import com.huaweicloud.sdk.gaussdb.v3.*;
import com.huaweicloud.sdk.gaussdb.v3.model.*;


public class ListGaussMySqlInstancesUnifyStatusSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        GaussDBClient client = GaussDBClient.newBuilder()
                .withCredential(auth)
                .withRegion(GaussDBRegion.valueOf("<YOUR REGION>"))
                .build();
        ListGaussMySqlInstancesUnifyStatusRequest request = new ListGaussMySqlInstancesUnifyStatusRequest();
        request.withId("<id>");
        request.withName("<name>");
        request.withType("<type>");
        request.withDatastoreType("<datastore_type>");
        request.withVpcId("<vpc_id>");
        request.withSubnetId("<subnet_id>");
        request.withPrivateIp("<private_ip>");
        request.withReadonlyPrivateIp("<readonly_private_ip>");
        request.withProxyIp("<proxy_ip>");
        request.withOffset(<offset>);
        request.withLimit(<limit>);
        request.withTags("<tags>");
        try {
            ListGaussMySqlInstancesUnifyStatusResponse response = client.listGaussMySqlInstancesUnifyStatus(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkgaussdb.v3.region.gaussdb_region import GaussDBRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkgaussdb.v3 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = GaussDBClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(GaussDBRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListGaussMySqlInstancesUnifyStatusRequest()
        request.id = "<id>"
        request.name = "<name>"
        request.type = "<type>"
        request.datastore_type = "<datastore_type>"
        request.vpc_id = "<vpc_id>"
        request.subnet_id = "<subnet_id>"
        request.private_ip = "<private_ip>"
        request.readonly_private_ip = "<readonly_private_ip>"
        request.proxy_ip = "<proxy_ip>"
        request.offset = <offset>
        request.limit = <limit>
        request.tags = "<tags>"
        response = client.list_gauss_my_sql_instances_unify_status(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    gaussdb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := gaussdb.NewGaussDBClient(
        gaussdb.GaussDBClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListGaussMySqlInstancesUnifyStatusRequest{}
	idRequest:= "<id>"
	request.Id = &idRequest
	nameRequest:= "<name>"
	request.Name = &nameRequest
	typeRequest:= "<type>"
	request.Type = &typeRequest
	datastoreTypeRequest:= "<datastore_type>"
	request.DatastoreType = &datastoreTypeRequest
	vpcIdRequest:= "<vpc_id>"
	request.VpcId = &vpcIdRequest
	subnetIdRequest:= "<subnet_id>"
	request.SubnetId = &subnetIdRequest
	privateIpRequest:= "<private_ip>"
	request.PrivateIp = &privateIpRequest
	readonlyPrivateIpRequest:= "<readonly_private_ip>"
	request.ReadonlyPrivateIp = &readonlyPrivateIpRequest
	proxyIpRequest:= "<proxy_ip>"
	request.ProxyIp = &proxyIpRequest
	offsetRequest:= int32(<offset>)
	request.Offset = &offsetRequest
	limitRequest:= int32(<limit>)
	request.Limit = &limitRequest
	tagsRequest:= "<tags>"
	request.Tags = &tagsRequest
	response, err := client.ListGaussMySqlInstancesUnifyStatus(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

Success.

400

Client error.

500

Server error.

错误码

请参见错误码

分享:

    相关文档

    相关产品