
# 查询Kafka产品规格核数 - ShowKafkaProductCores
#### 功能介绍
查询Kafka产品规格核数。
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-kafka/api-call-process.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-kafka/api-grant-policy.html)。
- 如果使用身份策略授权，当前API调用无需身份策略权限。
 
#### URI
GET /v2/kafka/products/cores
表1Query参数 
| 参数          | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
|:---|:---|:---|:---|
| instance_id | 否    | String | **参数解释**： 实例ID。获取方法如下：调用"查询所有实例列表"接口，从响应体中获取实例ID。实例ID非必填项，只有填写实例ID响应体才会返回total_extend_storage_space。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| product_id  | 是    | String | **参数解释**： 产品ID。 **约束限制**： 不涉及。 **取值范围**： - s6.2u4g.single.small：规格kafka.2u4g.single.small的产品ID。   - c6.2u4g.single：规格kafka.2u4g.single的产品ID。   - s6.2u4g.cluster.small：规格kafka.2u4g.cluster.small的产品ID。   - c6.2u4g.cluster：规格kafka.2u4g.cluster的产品ID。   - c6.4u8g.cluster：规格kafka.4u8g.cluster的产品ID。   - c6.8u16g.cluster：规格kafka.8u16g.cluster的产品ID。   - c6.12u24g.cluster：规格kafka.12u24g.cluster的产品ID。   - c6.16u32g.cluster：规格kafka.16u32g.cluster的产品ID。    **默认取值**： 不涉及。 |
| broker_num  | 是    | String | **参数解释**： broker数量。 **约束限制**： 不涉及。 **取值范围**： - Kafka实例规格为kafka.2u4g.single.small时，代理数建议取值范围1。   - Kafka实例规格为kafka.2u4g.single时，代理数建议取值范围1。   - Kafka实例规格为kafka.2u4g.cluster.small时，代理数取值范围3-30。   - Kafka实例规格为kafka.2u4g.cluster时，代理数取值范围3-30。   - Kafka实例规格为kafka.4u8g.cluster时，代理数取值范围3-30。   - Kafka实例规格为kafka.8u16g.cluster时，代理数取值范围3-50。   - Kafka实例规格为kafka.12u24g.cluster时，代理数取值范围3-50。   - Kafka实例规格为kafka.16u32g.cluster时，代理数取值范围3-50。    **默认取值**： 不涉及。              |
   
#### 请求参数
无
#### 响应参数
**状态码：200**
表2响应Body参数 
| 参数                         | 参数类型    | 描述                                                                                                                                                                                                                                                       |
|:---|:---|:---|
| core_num                   | Integer | **参数解释**： 核数。 **取值范围**： 不涉及。                                                                                                  |
| total_extend_storage_space | Integer | **参数解释**： 预估存储空间，当填写的broker_num小于等于当前实例真实值时，显示为当前实例的存储空间。如果填写的broker_num大于当前实例真实值时，显示为所填写broker_num时实例的预估存储空间。 **取值范围**： 不涉及。 |
   
#### 请求示例
```
GET https://{endpoint}/v2/kafka/products/cores?instance_id={instance_id}&product_id={product_id}&broker_num={broker_num}
```
#### 响应示例
**状态码：200**
查询成功。
```
{
  "core_num" : 100,
  "total_extend_storage_space" : 300
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  ```
  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 ShowKafkaProductCoresSolution {
      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);
          KafkaClient client = KafkaClient.newBuilder()
                  .withCredential(auth)
                  .withRegion(KafkaRegion.valueOf("<YOUR REGION>"))
                  .build();
          ShowKafkaProductCoresRequest request = new ShowKafkaProductCoresRequest();
          try {
              ShowKafkaProductCoresResponse response = client.showKafkaProductCores(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());
          }
      }
  }
  ```
- [Python]
  ```
  # 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"]
      credentials = BasicCredentials(ak, sk)
      client = KafkaClient.new_builder() \
          .with_credentials(credentials) \
          .with_region(KafkaRegion.value_of("<YOUR REGION>")) \
          .build()
      try:
          request = ShowKafkaProductCoresRequest()
          response = client.show_kafka_product_cores(request)
          print(response)
      except exceptions.ClientRequestException as e:
          print(e.status_code)
          print(e.request_id)
          print(e.error_code)
          print(e.error_msg)
  ```
- [Go]
  ```
  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")
      auth, err := basic.NewCredentialsBuilder().
          WithAk(ak).
          WithSk(sk).
          SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      hcClient, err := kafka.KafkaClientBuilder().
           WithRegion(region.ValueOf("<YOUR REGION>")).
           WithCredential(auth).
           SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      client := kafka.NewKafkaClient(hcClient)
      request := &model.ShowKafkaProductCoresRequest{}
  response, err := client.ShowKafkaProductCores(request)
  if err == nil {
          fmt.Printf("%+v\n", response)
      } else {
          fmt.Println(err)
      }
  }
  ```
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/Kafka/sdk?api=ShowKafkaProductCores)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述    |
|:---|:---|
| 200 | 查询成功。 |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-kafka/ErrorCode.html)。
