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

查询网格 - ShowMesh

功能介绍

该API用于获取指定网格的详细信息

调用方法

请参见如何调用API

授权信息

账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。

  • 如果使用角色与策略授权,具体权限要求请参见权限和授权项
  • 如果使用身份策略授权,需具备如下身份策略权限。

    授权项

    访问级别

    资源类型(*为必须)

    条件键

    别名

    依赖的授权项

    asm:mesh:get

    Read

    mesh *

    • g:EnterpriseProjectId

    • g:ResourceTag/<tag-key>

    -

    -

URI

GET /v1/{project_id}/meshes/{mesh_id}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID。

mesh_id

String

网格ID。

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

调用接口的认证方式分为Token和AK/SK两种,如果您使用的Token方式,此参数为必填,请填写Token的值。

响应参数

状态码:200

表3 响应Body参数

参数

参数类型

描述

apiVersion

String

API版本,固定值“v1”,该值不可修改

kind

String

API类型,固定值“Mesh”或“mesh”,该值不可修改

metadata

MeshMetadata object

网格的基本信息,为集合类的元素类型,包含一组由不同名称定义的属性

spec

MeshSpec object

集合类的元素类型,您对需要管理的网格对象进行详细描述的主体部分都在spec中给出。ASM通过spec的描述来创建或更新对象

status

MeshStatus object

集合类的元素类型,用于记录对象在系统中的当前状态信息。

该对象为系统自动生成,不需要用户填写

表4 MeshMetadata

参数

参数类型

描述

name

String

网格名称。

命名规则:以小写字母开头,由小写字母、数字、中划线(-)组成,长度范围4-64位,且不能以中划线(-)结尾

uid

String

网格ID,资源唯一标识,创建成功后自动生成,填写无效

creationTimestamp

String

网格创建时间

表5 MeshSpec

参数

参数类型

描述

type

String

网格类型。

取值范围:

  • InCluster: 集群内控制平面形态,基础版网格取值为InCluster。目前仅支持该类型。

version

String

网格版本。

extendParams

MeshExtendParams object

服务网格扩展信息。

ipv6Enable

Boolean

网格是否支持IPV6

tags

Array of MeshTags objects

网格资源标签。如果需要配置资源标签,请确认当前region的TMS服务已上线。

config

MeshConfig object

网格配置。

表6 MeshExtendParams

参数

参数类型

描述

clusters

Array of MeshCluster objects

网格内集群信息

表7 MeshCluster

参数

参数类型

描述

clusterID

String

集群ID,资源唯一标识,通过该ID查询需要添加的集群

injection

InjectionConfig object

sidecar注入配置

installation

InstallationConfig object

网格组件安装配置

表8 InjectionConfig

参数

参数类型

描述

namespaces

Selector object

需要注入的命名空间

表9 InstallationConfig

参数

参数类型

描述

nodes

Selector object

安装网格组件的节点

表10 Selector

参数

参数类型

描述

fieldSelector

FieldSelector object

字段选择器

表11 FieldSelector

参数

参数类型

描述

key

String

Key值

operator

String

操作符,仅支持取值"In"

values

Array of strings

Value值

表12 MeshTags

参数

参数类型

描述

key

String

Key值。

不能为空,最多支持128个字符

可用UTF-8格式表示的汉字、字母、数字和空格

支持部分特殊字符:_.:/=+-@

不能以"sys"开头

value

String

Value值。

可以为空但不能缺省,最多支持255个字符

可用UTF-8格式表示的汉字、字母、数字和空格

支持部分特殊字符:_.:/=+-@

表13 MeshConfig

参数

参数类型

描述

proxyConfig

ProxyConfig object

网格数据面配置

telemetryConfig

TelemetryConfig object

网格的可观测性配置

表14 ProxyConfig

参数

参数类型

描述

includeIPRanges

String

拦截对外访问的地址范围,以半角英文逗号(,)分隔的IP网段

excludeIPRanges

String

排除拦截对外访问的地址范围,以半角英文逗号(,)分隔的IP网段

excludeOutboundPorts

String

排除拦截对外访问端口,以半角英文逗号(,)分隔的出站端口列表

excludeInboundPorts

String

排除拦截访问服务的端口,以半角英文逗号(,)分隔的入站端口列表

includeOutboundPorts

String

拦截对外访问端口,以半角英文逗号(,)分隔的出站端口列表

includeInboundPorts

String

拦截访问服务的端口,以半角英文逗号(,)分隔的入站端口列表

表15 TelemetryConfig

参数

参数类型

描述

metrics

Metric object

应用指标配置,用于上报ASM网格指标数据。如果要启用该配置,集群需安装云原生监控插件。

accessLogging

AccessLogging object

AccessLog配置,用于上报ASM网格内Istio代理的访问日志。如果要启用该配置,集群需安装云原生日志采集插件。

tracing

Tracing object

Tracing配置,用于上报ASM网格内的调用链数据。

表16 Metric

参数

参数类型

描述

aom

Array of Aom objects

AOM实例配置。

表17 Aom

参数

参数类型

描述

instanceID

String

AOM实例ID。

表18 AccessLogging

参数

参数类型

描述

lts

Array of LtsConfig objects

LTS配置

表19 LtsConfig

参数

参数类型

描述

logGroupID

String

AccessLog日志组ID

logStreamID

String

AccessLog输出日志流ID

表20 Tracing

参数

参数类型

描述

randomSamplingPercentage

Float

tracing采样率

defaultProviders

Array of strings

tracing默认上报的provider名称,必须与extensionProviders中的name字段匹配,或使用ASM预设的provider "apm-otel"。

如果使用"apm-otel",需确认当前region已支持APM2.0且网格版本大于1.18。

extensionProviders

Array of TracingExtensionProvider objects

用户自配置provider,目前支持zipkin协议。

如果用户配置zipkin协议的provider,请保证网格版本大于等于1.15。

表21 TracingExtensionProvider

参数

参数类型

描述

name

String

provider实例name

zipkin

ZipkinTracingProvider object

zipkin协议provider自有配置

表22 ZipkinTracingProvider

参数

参数类型

描述

service

String

zipkin服务地址

port

Integer

zipkin服务端口

表23 MeshStatus

参数

参数类型

描述

phase

String

网格状态,取值如下

  • Running:运行中,表示网格处于正常运行状态

  • Creating:创建中,表示网格正处于创建过程中

  • CreateFailed:创建失败

  • Deleting:删除中,表示网格正处于删除过程中

  • DeleteFailed:删除失败

  • Upgrading:升级中,表示网格正处于升级过程中

  • UpgradeFailed:升级失败

  • RollingBack:回滚中,表示网格正处于回滚过程中

  • RollbackFailed:回滚失败

updateTimestamp

String

网格更新时间

状态码:400

表24 响应Body参数

参数

参数类型

描述

errorCode

String

错误码

errorMsg

String

错误描述

状态码:404

表25 响应Body参数

参数

参数类型

描述

errorCode

String

错误码

errorMsg

String

错误描述

状态码:500

表26 响应Body参数

参数

参数类型

描述

errorCode

String

错误码

errorMsg

String

错误描述

请求示例

响应示例

状态码:200

表示获取网格成功

{
  "kind" : "Mesh",
  "apiVersion" : "v1",
  "metadata" : {
    "name" : "mesh-test-api",
    "uid" : "a1efdc3e-xxxx-xxxx-xxxx-94bef433347e",
    "creationTimestamp" : "2025-04-10T07:48:37Z"
  },
  "spec" : {
    "type" : "InCluster",
    "version" : "1.18.7-r5",
    "config" : {
      "telemetryConfig" : {
        "metrics" : {
          "aom" : [ {
            "instanceID" : "602a5b7e-xxxx-xxxx-xxxx-4268c35b0424"
          } ]
        },
        "accessLogging" : {
          "lts" : [ {
            "logGroupID" : "b884eaeb-xxxx-xxxx-xxxx-f442de73c392",
            "logStreamID" : "362e11e8-xxxx-xxxx-xxxx-0afdc68da7d2"
          } ]
        },
        "tracing" : {
          "randomSamplingPercentage" : 1,
          "defaultProviders" : [ "zipkin" ],
          "extensionProviders" : [ {
            "name" : "zipkin",
            "zipkin" : {
              "service" : "zipkin.monitoring.svc.cluster.local",
              "port" : 9411
            }
          } ]
        }
      },
      "proxyConfig" : {
        "includeIPRanges" : "10.247.0.0/16"
      }
    },
    "extendParams" : {
      "clusters" : [ {
        "clusterID" : "cb0ef541-xxxx-xxxx-xxxx-0255ac1001b7"
      } ]
    }
  },
  "status" : {
    "phase" : "Running",
    "updateTimestamp" : "2025-04-10T07:58:43Z"
  }
}

SDK代码示例

SDK代码示例如下。

Java

 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
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.asm.v1.region.AsmRegion;
import com.huaweicloud.sdk.asm.v1.*;
import com.huaweicloud.sdk.asm.v1.model.*;


public class ShowMeshSolution {

    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);

        AsmClient client = AsmClient.newBuilder()
                .withCredential(auth)
                .withRegion(AsmRegion.valueOf("<YOUR REGION>"))
                .build();
        ShowMeshRequest request = new ShowMeshRequest();
        request.withMeshId("{mesh_id}");
        try {
            ShowMeshResponse response = client.showMesh(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

 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
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkasm.v1.region.asm_region import AsmRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkasm.v1 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 = AsmClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(AsmRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ShowMeshRequest()
        request.mesh_id = "{mesh_id}"
        response = client.show_mesh(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

 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
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    asm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/asm/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/asm/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/asm/v1/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 := asm.NewAsmClient(
        asm.AsmClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ShowMeshRequest{}
	request.MeshId = "{mesh_id}"
	response, err := client.ShowMesh(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多

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

状态码

状态码

描述

200

表示获取网格成功

400

用户提供的参数有问题,未通过校验

404

未找到指定的网格

500

查询过程中出现问题

错误码

请参见错误码

相关文档