查询所有实例列表
功能介绍
查询租户的实例列表,支持按照条件查询。
调用方法
请参见如何调用API。
URI
GET /v2/{project_id}/instances
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
参数解释: 项目ID,获取方式请参见获取项目ID。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
engine |
是 |
String |
参数解释: 消息引擎。 约束限制: 不涉及。 取值范围: kafka。 默认取值: 不涉及。 |
name |
否 |
String |
参数解释: 实例名称。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
instance_id |
否 |
String |
参数解释: 实例ID。获取方法如下:调用“查询所有实例列表”接口,从响应体中获取实例ID。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
status |
否 |
String |
参数解释: 实例状态,详细状态说明请参考实例状态说明。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
include_failure |
否 |
String |
参数解释: 是否返回创建失败的实例数。 约束限制: 不涉及。 取值范围:
默认取值: 不涉及。 |
exact_match_name |
否 |
String |
参数解释: 是否按照实例名称进行精确匹配查询。 约束限制: 不涉及。 取值范围:
默认取值: 'false'。 |
enterprise_project_id |
否 |
String |
参数解释: 企业项目ID。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
offset |
否 |
String |
参数解释: 偏移量,表示从此偏移量开始查询。 约束限制: 不涉及。 取值范围: 大于等于0。 默认取值: 不涉及。 |
limit |
否 |
String |
参数解释: 当次查询返回的实例最大个数。 约束限制: 不涉及。 取值范围: 1~50。 默认取值: 10。 |
请求参数
无
响应参数
状态码:200
参数 |
参数类型 |
描述 |
---|---|---|
instances |
Array of ShowInstanceResp objects |
参数解释: 实例列表。 |
instance_num |
Integer |
参数解释: 实例数量。 取值范围: 不涉及。 |
参数 |
参数类型 |
描述 |
---|---|---|
name |
String |
参数解释: 实例名称。 取值范围: 不涉及。 |
engine |
String |
参数解释: 引擎。 取值范围:
|
engine_version |
String |
参数解释: Kafka的版本。 取值范围:
|
description |
String |
参数解释: 实例描述。 取值范围: 不涉及。 |
specification |
String |
参数解释: 实例规格。 取值范围: 不涉及。 |
storage_space |
Integer |
参数解释: 消息存储空间,单位:GB。 取值范围:
|
partition_num |
String |
参数解释: Kafka实例的分区数量。 取值范围: 不涉及。 |
used_storage_space |
Integer |
参数解释: 已使用的消息存储空间,单位:GB。 取值范围: 不涉及。 |
dns_enable |
Boolean |
参数解释: 实例是否开启域名访问功能。 取值范围:
|
connect_address |
String |
参数解释: 实例连接IP地址。 取值范围: 不涉及。 |
port |
Integer |
参数解释: 实例连接端口。 取值范围: 不涉及。 |
status |
String |
参数解释: 实例的状态。详细状态说明请参考实例状态说明。 取值范围: 不涉及。 |
instance_id |
String |
参数解释: 实例ID。 取值范围: 不涉及。 |
resource_spec_code |
String |
参数解释: 资源规格标识。 取值范围:
|
charging_mode |
Integer |
参数解释: 付费模式。 取值范围:
|
vpc_id |
String |
参数解释: VPC ID。 取值范围: 不涉及。 |
vpc_name |
String |
参数解释: VPC的名称。 取值范围: 不涉及。 |
created_at |
String |
参数解释: 完成创建时间。 格式为时间戳,指从格林威治时间 1970年01月01日00时00分00秒起至指定时间的偏差总毫秒数。 取值范围: 不涉及。 |
subnet_name |
String |
参数解释: 子网名称。 取值范围: 不涉及。 |
subnet_cidr |
String |
参数解释: 子网网段。 取值范围: 不涉及。 |
user_id |
String |
参数解释: 用户ID。 取值范围: 不涉及。 |
user_name |
String |
参数解释: 用户名。 取值范围: 不涉及。 |
access_user |
String |
参数解释: 实例访问用户名。 取值范围: 不涉及。 |
order_id |
String |
参数解释: 订单ID,只有在包周期计费时才会有order_id值,其他计费方式order_id值为空。 取值范围: 不涉及。 |
maintain_begin |
String |
参数解释: 维护时间窗开始时间,格式为HH:mm:ss。 取值范围: 不涉及。 |
maintain_end |
String |
参数解释: 维护时间窗结束时间,格式为HH:mm:ss。 取值范围: 不涉及。 |
enable_publicip |
Boolean |
参数解释: 实例是否开启公网访问功能。 取值范围:
|
management_connect_address |
String |
参数解释: Kafka实例的Kafka Manager连接地址。 取值范围: 不涉及。 |
ssl_enable |
Boolean |
参数解释: 是否开启安全认证。 取值范围:
|
broker_ssl_enable |
Boolean |
参数解释: 是否开启broker间副本加密传输。 取值范围:
|
kafka_security_protocol |
String |
参数解释: Kafka使用的安全协议。 若实例详情中不存在port_protocols返回参数,则kafka_security_protocol同时代表内网访问、公网访问以及跨VPC访问的安全协议。 若实例详情中存在port_protocols返回参数,则kafka_security_protocol仅代表跨VPC访问的安全协议。内网访问公网访问的安全协议请参考port_protocols参数。 取值范围:
|
sasl_enabled_mechanisms |
Array of strings |
参数解释: 开启SASL后使用的认证机制。 |
ssl_two_way_enable |
Boolean |
参数解释: 是否开启双向认证。 取值范围:
|
cert_replaced |
Boolean |
参数解释: 是否开启证书替换。 取值范围:
|
public_management_connect_address |
String |
参数解释: 公网访问Kafka Manager连接地址。 取值范围: 不涉及。 |
enterprise_project_id |
String |
参数解释: 企业项目ID。 取值范围: 不涉及。 |
is_logical_volume |
Boolean |
参数解释: 实例扩容时用于区分老实例与新实例。 取值范围:
|
extend_times |
Integer |
参数解释: 实例扩容磁盘次数,如果超过20次则无法扩容磁盘。 取值范围: 不涉及。 |
enable_auto_topic |
Boolean |
参数解释: 是否开启自动创建topic。 取值范围:
|
type |
String |
参数解释: 实例类型。 取值范围:
|
product_id |
String |
参数解释: 产品标识。 取值范围: 不涉及。 |
security_group_id |
String |
参数解释: 安全组ID。 取值范围: 不涉及。 |
security_group_name |
String |
参数解释: 安全组名称。 取值范围: 不涉及。 |
subnet_id |
String |
参数解释: 子网ID。 取值范围: 不涉及。 |
available_zones |
Array of strings |
参数解释: 实例节点所在的可用区,返回“可用区ID”。 |
available_zone_names |
Array of strings |
参数解释: 实例节点所在的可用区名称,返回“可用区名称”。 |
total_storage_space |
Integer |
参数解释: 总共消息存储空间,单位:GB。 取值范围: 不涉及。 |
public_connect_address |
String |
参数解释: 实例公网连接IP地址。当实例开启了公网访问,实例才包含该参数。 取值范围: 不涉及。 |
public_connect_domain_name |
String |
参数解释: 实例公网连接域名。当实例开启了公网访问,实例才包含该参数。 取值范围: 不涉及。 |
storage_resource_id |
String |
参数解释: 存储资源ID。 取值范围: 不涉及。 |
storage_spec_code |
String |
参数解释: IO规格。 取值范围: 不涉及。 |
service_type |
String |
参数解释: 服务类型。 取值范围: advanced |
storage_type |
String |
参数解释: 存储类型。 取值范围: 不涉及。 |
retention_policy |
String |
参数解释: 消息老化策略。 取值范围:
|
kafka_public_status |
String |
参数解释: Kafka公网开启状态。 取值范围:
|
public_bandwidth |
Integer |
参数解释: kafka公网访问带宽。 取值范围: 不涉及。 |
enable_log_collection |
Boolean |
参数解释: 是否开启消息收集功能。 取值范围:
|
new_auth_cert |
Boolean |
参数解释: 是否开启新证书。 取值范围:
|
cross_vpc_info |
String |
参数解释: 跨VPC访问信息。 取值范围: 不涉及。 |
ipv6_enable |
Boolean |
参数解释: 是否开启IPv6。 取值范围:
|
ipv6_connect_addresses |
Array of strings |
参数解释: IPv6的连接地址。 |
connector_enable |
Boolean |
参数解释: 是否开启转储。 取值范围:
|
connector_node_num |
Integer |
参数解释: connector节点数量。 取值范围: 2-16。 |
connector_id |
String |
参数解释: 转储任务ID。 取值范围: 不涉及。 |
rest_enable |
Boolean |
参数解释: 是否开启Kafka rest功能。 取值范围:
|
rest_connect_address |
String |
参数解释: Kafka rest连接地址。 取值范围: 不涉及。 |
public_boundwidth |
Integer |
参数解释: Kafka公网访问带宽。待删除版本。 取值范围: 不涉及。 |
message_query_inst_enable |
Boolean |
参数解释: 是否开启消息查询功能。 取值范围:
|
vpc_client_plain |
Boolean |
参数解释: 是否开启VPC明文访问。 取值范围:
|
support_features |
String |
参数解释: Kafka实例支持的特性功能。 取值范围: 不涉及。 |
trace_enable |
Boolean |
参数解释: 是否开启消息轨迹功能。 取值范围:
|
agent_enable |
Boolean |
参数解释: 是否开启代理。 取值范围:
|
pod_connect_address |
String |
参数解释: 租户侧连接地址。 取值范围: 不涉及。 |
disk_encrypted |
Boolean |
参数解释: 是否开启磁盘加密。 取值范围:
|
disk_encrypted_key |
String |
参数解释: 磁盘加密key,未开启磁盘加密时为空。 取值范围: 不涉及。 |
kafka_private_connect_address |
String |
参数解释: Kafka实例内网连接地址。 取值范围: 不涉及。 |
kafka_private_connect_domain_name |
String |
参数解释: Kafka实例内网连接域名。 取值范围: 不涉及。 |
ces_version |
String |
参数解释: 云监控版本。 取值范围: 不涉及。 |
public_access_enabled |
String |
参数解释: 区分实例什么时候开启的公网访问 取值范围:
|
node_num |
Integer |
参数解释: 节点数。 取值范围:
|
port_protocols |
PortProtocolsEntity object |
参数解释: 实例支持的连接方式及其连接地址。 |
enable_acl |
Boolean |
参数解释: 是否开启访问控制。 取值范围:
|
new_spec_billing_enable |
Boolean |
参数解释: 是否启用新规格计费。 取值范围:
|
broker_num |
Integer |
参数解释: 节点数量。 取值范围: 不涉及。 |
tags |
Array of TagEntity objects |
参数解释: 标签列表。 |
dr_enable |
Boolean |
参数解释: 是否为容灾实例。 取值范围:
|
参数 |
参数类型 |
描述 |
---|---|---|
private_plain_enable |
Boolean |
参数解释: 实例是否支持内网PLAINTEXT访问接入方式。 取值范围:
|
private_plain_address |
String |
参数解释: kafka内网PLAINTEXT接入方式连接地址。 取值范围: 不涉及 |
private_plain_domain_name |
String |
参数解释: 内网明文连接域名。 取值范围: 不涉及 |
private_sasl_ssl_enable |
Boolean |
参数解释: 实例是否支持内网SASL_SSL访问接入方式。 取值范围:
|
private_sasl_ssl_address |
String |
参数解释: kafka内网SASL_SSL接入方式连接地址。 取值范围: 不涉及 |
private_sasl_ssl_domain_name |
String |
参数解释: 内网SASL_SSL连接域名。 取值范围: 不涉及 |
private_sasl_plaintext_enable |
Boolean |
参数解释: 实例是否支持内网SASL_PLAINTEXT访问接入方式。 取值范围:
|
private_sasl_plaintext_address |
String |
参数解释: kafka内网SASL_PLAINTEXT接入方式连接地址。 取值范围: 不涉及 |
private_sasl_plaintext_domain_name |
String |
参数解释: 内网SASL_PLAINTEXT连接域名。 取值范围: 不涉及 |
public_plain_enable |
Boolean |
参数解释: 实例是否支持公网PLAINTEXT访问接入方式。 取值范围:
|
public_plain_address |
String |
参数解释: kafka公网PLAINTEXT接入方式连接地址。 取值范围: 不涉及 |
public_plain_domain_name |
String |
参数解释: 公网明文连接域名。 取值范围: 不涉及 |
public_sasl_ssl_enable |
Boolean |
参数解释: 实例是否支持公网SASL_SSL访问接入方式。 取值范围:
|
public_sasl_ssl_address |
String |
参数解释: kafka公网SASL_SSL接入方式连接地址。 取值范围: 不涉及 |
public_sasl_ssl_domain_name |
String |
参数解释: 公网SASL_SSL连接域名。 取值范围: 不涉及 |
public_sasl_plaintext_enable |
Boolean |
参数解释: 实例是否支持公网SASL_PLAINTEXT访问接入方式。 取值范围:
|
public_sasl_plaintext_address |
String |
参数解释: kafka公网SASL_PLAINTEXT接入方式连接地址。 取值范围: 不涉及 |
public_sasl_plaintext_domain_name |
String |
参数解释: 公网SASL_PLAINTEXT连接域名。 取值范围: 不涉及 |
参数 |
参数类型 |
描述 |
---|---|---|
key |
String |
参数解释: 标签键。 约束限制:
取值范围: 不涉及。 默认取值: 不涉及。 |
value |
String |
参数解释: 标签值。 约束限制:
取值范围: 不涉及。 默认取值: 不涉及。 |
请求示例
查询所有实例列表
GET https://{endpoint}/v2/{project_id}/instances
响应示例
状态码:200
查询所有实例列表成功。
{
"instances" : [ {
"name" : "kafka-2085975099",
"engine" : "kafka",
"port" : 9092,
"status" : "RUNNING",
"type" : "cluster",
"specification" : "100MB",
"engine_version" : "1.1.0",
"connect_address" : "192.168.0.100,192.168.0.61,192.168.0.72",
"instance_id" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"resource_spec_code" : "dms.instance.kafka.cluster.c3.mini",
"charging_mode" : 1,
"vpc_id" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"vpc_name" : "dms-test",
"created_at" : "1585618587087",
"product_id" : "00300-30308-0--0",
"security_group_id" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"security_group_name" : "Sys-default",
"subnet_id" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"available_zones" : [ "38b0f7a602344246bcb0da47b5d548e7" ],
"available_zone_names" : [ "AZ1" ],
"user_id" : "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"user_name" : "paas_dms",
"maintain_begin" : "02:00:00",
"maintain_end" : "06:00:00",
"enable_log_collection" : false,
"new_auth_cert" : false,
"storage_space" : 492,
"total_storage_space" : 600,
"used_storage_space" : 25,
"partition_num" : "300",
"enable_publicip" : false,
"ssl_enable" : false,
"broker_ssl_enable" : false,
"cert_replaced" : false,
"management_connect_address" : "https://192.168.0.100:9999",
"cross_vpc_info" : "{\"192.168.0.61\":{\"advertised_ip\":\"192.168.0.61\",\"port\":9011,\"port_id\":\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"},\"192.168.0.72\":{\"advertised_ip\":\"192.168.0.72\",\"port\":9011,\"port_id\":\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"},\"192.168.0.100\":{\"advertised_ip\":\"192.168.0.100\",\"port\":9011,\"port_id\":\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"}}",
"storage_resource_id" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"storage_spec_code" : "dms.physical.storage.ultra",
"service_type" : "advanced",
"storage_type" : "hec",
"enterprise_project_id" : "0",
"is_logical_volume" : true,
"extend_times" : 0,
"retention_policy" : "produce_reject",
"ipv6_enable" : false,
"ipv6_connect_addresses" : [ ],
"connector_enable" : false,
"connector_node_num" : 0,
"connector_id" : "",
"rest_enable" : false,
"rest_connect_address" : "",
"kafka_public_status" : "closed",
"public_bandwidth" : 0,
"message_query_inst_enable" : true,
"vpc_client_plain" : false,
"support_features" : "kafka.new.pod.port,feature.physerver.kafka.topic.modify,feature.physerver.kafka.topic.accesspolicy,message_trace_enable,features.pod.token.access,feature.physerver.kafka.pulbic.dynamic,roma_app_enable,features.log.collection,auto_topic_switch,feature.physerver.kafka.user.manager",
"trace_enable" : false,
"agent_enable" : false,
"pod_connect_address" : "100.86.75.15:9080,100.86.142.77:9080,100.86.250.167:9080",
"disk_encrypted" : false,
"kafka_private_connect_address" : "192.168.0.61:9092,192.168.0.100:9092,192.168.0.72:9092",
"enable_auto_topic" : false,
"new_spec_billing_enable" : false,
"ces_version" : "linux"
} ],
"instance_num" : 1
}
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 |
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.kafka.v2.region.KafkaRegion;
import com.huaweicloud.sdk.kafka.v2.*;
import com.huaweicloud.sdk.kafka.v2.model.*;
public class ListInstancesSolution {
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");
String projectId = "{project_id}";
ICredential auth = new BasicCredentials()
.withProjectId(projectId)
.withAk(ak)
.withSk(sk);
KafkaClient client = KafkaClient.newBuilder()
.withCredential(auth)
.withRegion(KafkaRegion.valueOf("<YOUR REGION>"))
.build();
ListInstancesRequest request = new ListInstancesRequest();
try {
ListInstancesResponse response = client.listInstances(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 |
# coding: utf-8
import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkkafka.v2.region.kafka_region import KafkaRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkkafka.v2 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 = os.environ["CLOUD_SDK_AK"]
sk = os.environ["CLOUD_SDK_SK"]
projectId = "{project_id}"
credentials = BasicCredentials(ak, sk, projectId)
client = KafkaClient.new_builder() \
.with_credentials(credentials) \
.with_region(KafkaRegion.value_of("<YOUR REGION>")) \
.build()
try:
request = ListInstancesRequest()
response = client.list_instances(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 |
package main
import (
"fmt"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
kafka "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2/model"
region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2/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")
projectId := "{project_id}"
auth := basic.NewCredentialsBuilder().
WithAk(ak).
WithSk(sk).
WithProjectId(projectId).
Build()
client := kafka.NewKafkaClient(
kafka.KafkaClientBuilder().
WithRegion(region.ValueOf("<YOUR REGION>")).
WithCredential(auth).
Build())
request := &model.ListInstancesRequest{}
response, err := client.ListInstances(request)
if err == nil {
fmt.Printf("%+v\n", response)
} else {
fmt.Println(err)
}
}
|
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的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 |
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.kafka.v2.region.KafkaRegion;
import com.huaweicloud.sdk.kafka.v2.*;
import com.huaweicloud.sdk.kafka.v2.model.*;
public class ListInstancesSolution {
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");
String projectId = "{project_id}";
ICredential auth = new BasicCredentials()
.withProjectId(projectId)
.withAk(ak)
.withSk(sk);
KafkaClient client = KafkaClient.newBuilder()
.withCredential(auth)
.withRegion(KafkaRegion.valueOf("<YOUR REGION>"))
.build();
ListInstancesRequest request = new ListInstancesRequest();
try {
ListInstancesResponse response = client.listInstances(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 |
# coding: utf-8
import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkkafka.v2.region.kafka_region import KafkaRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkkafka.v2 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 = os.environ["CLOUD_SDK_AK"]
sk = os.environ["CLOUD_SDK_SK"]
projectId = "{project_id}"
credentials = BasicCredentials(ak, sk, projectId)
client = KafkaClient.new_builder() \
.with_credentials(credentials) \
.with_region(KafkaRegion.value_of("<YOUR REGION>")) \
.build()
try:
request = ListInstancesRequest()
response = client.list_instances(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 |
package main
import (
"fmt"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
kafka "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2/model"
region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2/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")
projectId := "{project_id}"
auth := basic.NewCredentialsBuilder().
WithAk(ak).
WithSk(sk).
WithProjectId(projectId).
Build()
client := kafka.NewKafkaClient(
kafka.KafkaClientBuilder().
WithRegion(region.ValueOf("<YOUR REGION>")).
WithCredential(auth).
Build())
request := &model.ListInstancesRequest{}
response, err := client.ListInstances(request)
if err == nil {
fmt.Printf("%+v\n", response)
} else {
fmt.Println(err)
}
}
|
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
查询所有实例列表成功。 |
错误码
请参见错误码。