# 创建网格 - CreateMesh
#### 功能介绍
该API用于创建一个网格。
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-asm/asm_api_0008.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-asm/asm_api_0030.html)。
- 如果使用身份策略授权，需具备如下身份策略权限。
  
  | 授权项             | 访问级别  | 资源类型（\*为必须） | 条件键                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | 别名 | 依赖的授权项 |
  |:---|:---|:---|:---|:---|:---|
  | asm:mesh:create | Write | mesh \*     | -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | -  | -      |
  | asm:mesh:create | Write | -           | - g:EnterpriseProjectId   - g:TagKeys   - g:RequestTag/\<tag-key\>    | -  | -      |
     
  
 
#### URI
POST /v1/{project_id}/meshes
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述    |
|:---|:---|:---|:---|
| project_id | 是    | String | 项目ID。 |
   
#### 请求参数
表2请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
|:---|:---|:---|:---|
| Content-Type | 是    | String | 消息体的类型（格式）。 取值范围： - application/json;charset=utf-8：指定内容为JSON格式，并以UTF8字符编码进行编码   - application/json：指定内容为JSON格式    |
| X-Auth-Token | 是    | String | 调用接口的认证方式分为Token和AK/SK两种，如果您使用的Token方式，此参数为必填，请填写Token的值。                                                                                                                                                                                                                                                                                                                                                                                                         |
   
表3请求Body参数 
| 参数         | 是否必选 | 参数类型                                                     | 描述                                                            |
|:---|:---|:---|:---|
| apiVersion | 是    | String                                                   | API版本，固定值"v1"，该值不可修改                                          |
| kind       | 是    | String                                                   | API类型，固定值"Mesh"或"mesh"，该值不可修改                                 |
| metadata   | 是    | [MeshMetadata] object | 网格的基本信息，为集合类的元素类型，包含一组由不同名称定义的属性                              |
| spec       | 是    | [MeshSpec] object         | 集合类的元素类型，您对需要管理的网格对象进行详细描述的主体部分都在spec中给出。ASM通过spec的描述来创建或更新对象 |
   
 表4MeshMetadata 
| 参数   | 是否必选 | 参数类型   | 描述                                                                                        |
|:---|:---|:---|:---|
| name | 是    | String | 网格名称。 命名规则：以小写字母开头，由小写字母、数字、中划线(-)组成，长度范围4-64位，且不能以中划线(-)结尾 |
   
 表5MeshSpec 
| 参数           | 是否必选 | 参数类型                                                             | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
|:---|:---|:---|:---|
| type         | 是    | String                                                           | 网格类型。 取值范围： - InCluster: 集群内控制平面形态，基础版网格取值为InCluster。目前仅支持该类型。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| version      | 否    | String                                                           | **参数解释：** 网格版本，与Istio社区基线版本保持一致，建议选择最新商用版本。 在ASM控制台支持创建多种版本的网格。可登录ASM控制台创建网格，在"版本"处获取到网格版本。 **约束限制：** 格式必须为：vX.Y\[.Z\[-rN\]\]，例如 v1.18，v1.18.7，v1.18.7-r1 都将创建1.18版本的网格 - X: 对应社区Istio的主要版本   - Y: 对应社区Istio的次要版本   - Z: 对应社区Istio的补丁版本   - N: 对应ASM补丁版本    **取值范围：** 不涉及 **默认取值：** - 若不配置，默认创建最新版本的网格。   - 若指定网格本基线版本但是不指定具体r版本，则系统默认选择对应网格版本的最新r版本。建议不指定具体r版本由系统选择最新版本。    |
| extendParams | 是    | [MeshExtendParams] object | 服务网格扩展信息。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ipv6Enable   | 否    | Boolean                                                          | 网格是否支持IPV6                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| tags         | 否    | Array of [MeshTags] objects       | 网格资源标签。如果需要配置资源标签，请确认当前region的TMS服务已上线。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| config       | 否    | [MeshConfig] object             | 网格配置。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
   
 表6MeshExtendParams 
| 参数       | 是否必选 | 参数类型                                                             | 描述      |
|:---|:---|:---|:---|
| clusters | 是    | Array of [MeshCluster] objects | 网格内集群信息 |
   
 表7MeshCluster 
| 参数           | 是否必选 | 参数类型                                                                 | 描述                         |
|:---|:---|:---|:---|
| clusterID    | 是    | String                                                               | 集群ID，资源唯一标识，通过该ID查询需要添加的集群 |
| injection    | 否    | [InjectionConfig] object       | sidecar注入配置                |
| installation | 是    | [InstallationConfig] object | 网格组件安装配置                   |
   
 表8InjectionConfig 
| 参数         | 是否必选 | 参数类型                                             | 描述        |
|:---|:---|:---|:---|
| namespaces | 否    | [Selector] object | 需要注入的命名空间 |
   
 表9InstallationConfig 
| 参数    | 是否必选 | 参数类型                                             | 描述        |
|:---|:---|:---|:---|
| nodes | 是    | [Selector] object | 安装网格组件的节点 |
   
 表10Selector 
| 参数            | 是否必选 | 参数类型                                                       | 描述    |
|:---|:---|:---|:---|
| fieldSelector | 是    | [FieldSelector] object | 字段选择器 |
   
 表11FieldSelector 
| 参数       | 是否必选 | 参数类型             | 描述            |
|:---|:---|:---|:---|
| key      | 是    | String           | Key值          |
| operator | 是    | String           | 操作符，仅支持取值"In" |
| values   | 是    | Array of strings | Value值        |
   
 表12MeshTags 
| 参数    | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                   |
|:---|:---|:---|:---|
| key   | 否    | String | Key值。 不能为空，最多支持128个字符 可用UTF-8格式表示的汉字、字母、数字和空格 支持部分特殊字符：_.:/=+-@ 不能以"*sys*"开头 |
| value | 否    | String | Value值。 可以为空但不能缺省，最多支持255个字符 可用UTF-8格式表示的汉字、字母、数字和空格 支持部分特殊字符：_.:/=+-@                                     |
   
 表13MeshConfig 
| 参数              | 是否必选 | 参数类型                                                           | 描述        |
|:---|:---|:---|:---|
| proxyConfig     | 否    | [ProxyConfig] object         | 网格数据面配置   |
| telemetryConfig | 否    | [TelemetryConfig] object | 网格的可观测性配置 |
   
 表14ProxyConfig 
| 参数                   | 是否必选 | 参数类型   | 描述                              |
|:---|:---|:---|:---|
| includeIPRanges      | 否    | String | 拦截对外访问的地址范围，以半角英文逗号（,）分隔的IP网段   |
| excludeIPRanges      | 否    | String | 排除拦截对外访问的地址范围，以半角英文逗号（,）分隔的IP网段 |
| excludeOutboundPorts | 否    | String | 排除拦截对外访问端口，以半角英文逗号（,）分隔的出站端口列表  |
| excludeInboundPorts  | 否    | String | 排除拦截访问服务的端口，以半角英文逗号（,）分隔的入站端口列表 |
| includeOutboundPorts | 否    | String | 拦截对外访问端口，以半角英文逗号（,）分隔的出站端口列表    |
| includeInboundPorts  | 否    | String | 拦截访问服务的端口，以半角英文逗号（,）分隔的入站端口列表   |
   
 表15TelemetryConfig 
| 参数            | 是否必选 | 参数类型                                                       | 描述                                                          |
|:---|:---|:---|:---|
| metrics       | 否    | [Metric] object               | 应用指标配置，用于上报ASM网格指标数据。如果要启用该配置，集群需安装云原生监控插件。                 |
| accessLogging | 否    | [AccessLogging] object | AccessLog配置，用于上报ASM网格内Istio代理的访问日志。如果要启用该配置，集群需安装云原生日志采集插件。 |
| tracing       | 否    | [Tracing] object             | Tracing配置，用于上报ASM网格内的调用链数据。                                 |
   
 表16Metric 
| 参数  | 是否必选 | 参数类型                                             | 描述       |
|:---|:---|:---|:---|
| aom | 否    | Array of [Aom] objects | AOM实例配置。 |
   
 表17Aom 
| 参数         | 是否必选 | 参数类型   | 描述       |
|:---|:---|:---|:---|
| instanceID | 是    | String | AOM实例ID。 |
   
 表18AccessLogging 
| 参数  | 是否必选 | 参数类型                                                         | 描述    |
|:---|:---|:---|:---|
| lts | 否    | Array of [LtsConfig] objects | LTS配置 |
   
 表19LtsConfig 
| 参数          | 是否必选 | 参数类型   | 描述               |
|:---|:---|:---|:---|
| logGroupID  | 否    | String | AccessLog日志组ID   |
| logStreamID | 否    | String | AccessLog输出日志流ID |
   
 表20Tracing 
| 参数                       | 是否必选 | 参数类型                                                                                       | 描述                                                                                                                                                                 |
|:---|:---|:---|:---|
| 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。                                                                 |
   
 表21TracingExtensionProvider 
| 参数     | 是否必选 | 参数类型                                                                       | 描述                   |
|:---|:---|:---|:---|
| name   | 否    | String                                                                     | provider实例name       |
| zipkin | 否    | [ZipkinTracingProvider] object | zipkin协议provider自有配置 |
   
 表22ZipkinTracingProvider 
| 参数      | 是否必选 | 参数类型    | 描述         |
|:---|:---|:---|:---|
| service | 否    | String  | zipkin服务地址 |
| port    | 否    | Integer | zipkin服务端口 |
   
#### 响应参数
**状态码：201**
表23响应Body参数 
| 参数         | 参数类型                                                      | 描述                                                                           |
|:---|:---|:---|
| apiVersion | String                                                    | API版本，固定值"v1"，该值不可修改                                                         |
| kind       | String                                                    | API类型，固定值"Mesh"或"mesh"，该值不可修改                                                |
| metadata   | [MeshMetadata] object | 网格的基本信息，为集合类的元素类型，包含一组由不同名称定义的属性                                             |
| spec       | [MeshSpec] object         | 集合类的元素类型，您对需要管理的网格对象进行详细描述的主体部分都在spec中给出。ASM通过spec的描述来创建或更新对象                |
| status     | [MeshStatus] object     | 集合类的元素类型，用于记录对象在系统中的当前状态信息。 该对象为系统自动生成，不需要用户填写 |
   
 表24MeshMetadata 
| 参数                | 参数类型   | 描述                                                                                        |
|:---|:---|:---|
| name              | String | 网格名称。 命名规则：以小写字母开头，由小写字母、数字、中划线(-)组成，长度范围4-64位，且不能以中划线(-)结尾 |
| uid               | String | 网格ID，资源唯一标识，创建成功后自动生成，填写无效                                                                |
| creationTimestamp | String | 网格创建时间                                                                                    |
   
 表25MeshSpec 
| 参数           | 参数类型                                                              | 描述                                                                                                                                                                                                                                                                      |
|:---|:---|:---|
| type         | String                                                            | 网格类型。 取值范围： - InCluster: 集群内控制平面形态，基础版网格取值为InCluster。目前仅支持该类型。    |
| version      | String                                                            | **参数解释：** 网格版本，与Istio社区基线版本保持一致，建议选择最新商用版本。 在ASM控制台支持创建多种版本的网格。可登录ASM控制台创建网格，在"版本"处获取到网格版本。 **取值范围：** 不涉及                                       |
| extendParams | [MeshExtendParams] object | 服务网格扩展信息。                                                                                                                                                                                                                                                               |
| ipv6Enable   | Boolean                                                           | 网格是否支持IPV6                                                                                                                                                                                                                                                              |
| tags         | Array of [MeshTags] objects       | 网格资源标签。如果需要配置资源标签，请确认当前region的TMS服务已上线。                                                                                                                                                                                                                                 |
| config       | [MeshConfig] object             | 网格配置。                                                                                                                                                                                                                                                                   |
   
 表26MeshExtendParams 
| 参数       | 参数类型                                                              | 描述      |
|:---|:---|:---|
| clusters | Array of [MeshCluster] objects | 网格内集群信息 |
   
 表27MeshCluster 
| 参数           | 参数类型                                                                  | 描述                         |
|:---|:---|:---|
| clusterID    | String                                                                | 集群ID，资源唯一标识，通过该ID查询需要添加的集群 |
| injection    | [InjectionConfig] object       | sidecar注入配置                |
| installation | [InstallationConfig] object | 网格组件安装配置                   |
   
 表28InjectionConfig 
| 参数         | 参数类型                                              | 描述        |
|:---|:---|:---|
| namespaces | [Selector] object | 需要注入的命名空间 |
   
 表29InstallationConfig 
| 参数    | 参数类型                                              | 描述        |
|:---|:---|:---|
| nodes | [Selector] object | 安装网格组件的节点 |
   
 表30Selector 
| 参数            | 参数类型                                                        | 描述    |
|:---|:---|:---|
| fieldSelector | [FieldSelector] object | 字段选择器 |
   
 表31FieldSelector 
| 参数       | 参数类型             | 描述            |
|:---|:---|:---|
| key      | String           | Key值          |
| operator | String           | 操作符，仅支持取值"In" |
| values   | Array of strings | Value值        |
   
 表32MeshTags 
| 参数    | 参数类型   | 描述                                                                                                                                                                                                   |
|:---|:---|:---|
| key   | String | Key值。 不能为空，最多支持128个字符 可用UTF-8格式表示的汉字、字母、数字和空格 支持部分特殊字符：_.:/=+-@ 不能以"*sys*"开头 |
| value | String | Value值。 可以为空但不能缺省，最多支持255个字符 可用UTF-8格式表示的汉字、字母、数字和空格 支持部分特殊字符：_.:/=+-@                                     |
   
 表33MeshConfig 
| 参数              | 参数类型                                                            | 描述        |
|:---|:---|:---|
| proxyConfig     | [ProxyConfig] object         | 网格数据面配置   |
| telemetryConfig | [TelemetryConfig] object | 网格的可观测性配置 |
   
 表34ProxyConfig 
| 参数                   | 参数类型   | 描述                              |
|:---|:---|:---|
| includeIPRanges      | String | 拦截对外访问的地址范围，以半角英文逗号（,）分隔的IP网段   |
| excludeIPRanges      | String | 排除拦截对外访问的地址范围，以半角英文逗号（,）分隔的IP网段 |
| excludeOutboundPorts | String | 排除拦截对外访问端口，以半角英文逗号（,）分隔的出站端口列表  |
| excludeInboundPorts  | String | 排除拦截访问服务的端口，以半角英文逗号（,）分隔的入站端口列表 |
| includeOutboundPorts | String | 拦截对外访问端口，以半角英文逗号（,）分隔的出站端口列表    |
| includeInboundPorts  | String | 拦截访问服务的端口，以半角英文逗号（,）分隔的入站端口列表   |
   
 表35TelemetryConfig 
| 参数            | 参数类型                                                        | 描述                                                          |
|:---|:---|:---|
| metrics       | [Metric] object               | 应用指标配置，用于上报ASM网格指标数据。如果要启用该配置，集群需安装云原生监控插件。                 |
| accessLogging | [AccessLogging] object | AccessLog配置，用于上报ASM网格内Istio代理的访问日志。如果要启用该配置，集群需安装云原生日志采集插件。 |
| tracing       | [Tracing] object             | Tracing配置，用于上报ASM网格内的调用链数据。                                 |
   
 表36Metric 
| 参数  | 参数类型                                              | 描述       |
|:---|:---|:---|
| aom | Array of [Aom] objects | AOM实例配置。 |
   
 表37Aom 
| 参数         | 参数类型   | 描述       |
|:---|:---|:---|
| instanceID | String | AOM实例ID。 |
   
 表38AccessLogging 
| 参数  | 参数类型                                                          | 描述    |
|:---|:---|:---|
| lts | Array of [LtsConfig] objects | LTS配置 |
   
 表39LtsConfig 
| 参数          | 参数类型   | 描述               |
|:---|:---|:---|
| logGroupID  | String | AccessLog日志组ID   |
| logStreamID | String | AccessLog输出日志流ID |
   
 表40Tracing 
| 参数                       | 参数类型                                                                                        | 描述                                                                                                                                                                 |
|:---|:---|:---|
| 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。                                                                 |
   
 表41TracingExtensionProvider 
| 参数     | 参数类型                                                                        | 描述                   |
|:---|:---|:---|
| name   | String                                                                      | provider实例name       |
| zipkin | [ZipkinTracingProvider] object | zipkin协议provider自有配置 |
   
 表42ZipkinTracingProvider 
| 参数      | 参数类型    | 描述         |
|:---|:---|:---|
| service | String  | zipkin服务地址 |
| port    | Integer | zipkin服务端口 |
   
 表43MeshStatus 
| 参数              | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
|:---|:---|:---|
| phase           | String | 网格状态，取值如下 - Running：运行中，表示网格处于正常运行状态   - Creating：创建中，表示网格正处于创建过程中   - CreateFailed：创建失败   - Deleting：删除中，表示网格正处于删除过程中   - DeleteFailed：删除失败   - Upgrading：升级中，表示网格正处于升级过程中   - UpgradeFailed：升级失败   - RollingBack：回滚中，表示网格正处于回滚过程中   - RollbackFailed：回滚失败    |
| updateTimestamp | String | 网格更新时间                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
   
**状态码：400**
表44响应Body参数 
| 参数        | 参数类型   | 描述   |
|:---|:---|:---|
| errorCode | String | 错误码  |
| errorMsg  | String | 错误描述 |
   
**状态码：409**
表45响应Body参数 
| 参数        | 参数类型   | 描述   |
|:---|:---|:---|
| errorCode | String | 错误码  |
| errorMsg  | String | 错误描述 |
   
**状态码：500**
表46响应Body参数 
| 参数        | 参数类型   | 描述   |
|:---|:---|:---|
| errorCode | String | 错误码  |
| errorMsg  | String | 错误描述 |
   
#### 请求示例
创建一个版本为1.18.7-r5，且启用了可观测性配置的网格
```
POST /v1/719217bc273743xxxxxxxxae8bc34480/meshes
{
  "apiVersion" : "v1",
  "kind" : "Mesh",
  "metadata" : {
    "name" : "mesh-test-api"
  },
  "spec" : {
    "type" : "InCluster",
    "version" : "1.18.7-r5",
    "extendParams" : {
      "clusters" : [ {
        "clusterID" : "cb0ef541-xxxx-xxxx-xxxx-0255ac1001b7",
        "installation" : {
          "nodes" : {
            "fieldSelector" : {
              "key" : "UID",
              "operator" : "In",
              "values" : [ "1c531b0c-xxxx-xxxx-xxxx-0255ac100b08" ]
            }
          }
        },
        "injection" : {
          "namespaces" : {
            "fieldSelector" : {
              "key" : "Name",
              "operator" : "In",
              "values" : [ "default" ]
            }
          }
        }
      } ]
    },
    "config" : {
      "proxyConfig" : {
        "includeIPRanges" : "10.247.0.0/16"
      },
      "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
            }
          } ]
        }
      }
    }
  }
}
```
#### 响应示例
**状态码：201**
```
{
  "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" : "Creating"
  }
}
```
#### SDK代码示例
SDK代码示例如下。
#### Java
创建一个版本为1.18.7-r5，且启用了可观测性配置的网格
```
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.*;
import java.util.List;
import java.util.ArrayList;
public class CreateMeshSolution {
    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();
        CreateMeshRequest request = new CreateMeshRequest();
        Mesh body = new Mesh();
        ZipkinTracingProvider zipkinExtensionProviders = new ZipkinTracingProvider();
        zipkinExtensionProviders.withService("zipkin.monitoring.svc.cluster.local")
            .withPort(9411);
        List<TracingExtensionProvider> listTracingExtensionProviders = new ArrayList<>();
        listTracingExtensionProviders.add(
            new TracingExtensionProvider()
                .withName("zipkin")
                .withZipkin(zipkinExtensionProviders)
        );
        List<String> listTracingDefaultProviders = new ArrayList<>();
        listTracingDefaultProviders.add("zipkin");
        Tracing tracingTelemetryConfig = new Tracing();
        tracingTelemetryConfig.withRandomSamplingPercentage(1f)
            .withDefaultProviders(listTracingDefaultProviders)
            .withExtensionProviders(listTracingExtensionProviders);
        List<LtsConfig> listAccessLoggingLts = new ArrayList<>();
        listAccessLoggingLts.add(
            new LtsConfig()
                .withLogGroupID("b884eaeb-xxxx-xxxx-xxxx-f442de73c392")
                .withLogStreamID("362e11e8-xxxx-xxxx-xxxx-0afdc68da7d2")
        );
        AccessLogging accessLoggingTelemetryConfig = new AccessLogging();
        accessLoggingTelemetryConfig.withLts(listAccessLoggingLts);
        List<Aom> listMetricsAom = new ArrayList<>();
        listMetricsAom.add(
            new Aom()
                .withInstanceID("602a5b7e-xxxx-xxxx-xxxx-4268c35b0424")
        );
        Metric metricsTelemetryConfig = new Metric();
        metricsTelemetryConfig.withAom(listMetricsAom);
        TelemetryConfig telemetryConfigConfig = new TelemetryConfig();
        telemetryConfigConfig.withMetrics(metricsTelemetryConfig)
            .withAccessLogging(accessLoggingTelemetryConfig)
            .withTracing(tracingTelemetryConfig);
        ProxyConfig proxyConfigConfig = new ProxyConfig();
        proxyConfigConfig.withIncludeIPRanges("10.247.0.0/16");
        MeshConfig configSpec = new MeshConfig();
        configSpec.withProxyConfig(proxyConfigConfig)
            .withTelemetryConfig(telemetryConfigConfig);
        List<String> listFieldSelectorValues = new ArrayList<>();
        listFieldSelectorValues.add("1c531b0c-xxxx-xxxx-xxxx-0255ac100b08");
        FieldSelector fieldSelectorNodes = new FieldSelector();
        fieldSelectorNodes.withKey("UID")
            .withOperator("In")
            .withValues(listFieldSelectorValues);
        Selector nodesInstallation = new Selector();
        nodesInstallation.withFieldSelector(fieldSelectorNodes);
        InstallationConfig installationClusters = new InstallationConfig();
        installationClusters.withNodes(nodesInstallation);
        List<String> listFieldSelectorValues1 = new ArrayList<>();
        listFieldSelectorValues1.add("default");
        FieldSelector fieldSelectorNamespaces = new FieldSelector();
        fieldSelectorNamespaces.withKey("Name")
            .withOperator("In")
            .withValues(listFieldSelectorValues1);
        Selector namespacesInjection = new Selector();
        namespacesInjection.withFieldSelector(fieldSelectorNamespaces);
        InjectionConfig injectionClusters = new InjectionConfig();
        injectionClusters.withNamespaces(namespacesInjection);
        List<MeshCluster> listExtendParamsClusters = new ArrayList<>();
        listExtendParamsClusters.add(
            new MeshCluster()
                .withClusterID("cb0ef541-xxxx-xxxx-xxxx-0255ac1001b7")
                .withInjection(injectionClusters)
                .withInstallation(installationClusters)
        );
        MeshExtendParams extendParamsSpec = new MeshExtendParams();
        extendParamsSpec.withClusters(listExtendParamsClusters);
        MeshSpec specbody = new MeshSpec();
        specbody.withType(MeshSpec.TypeEnum.fromValue("InCluster"))
            .withVersion("1.18.7-r5")
            .withExtendParams(extendParamsSpec)
            .withConfig(configSpec);
        MeshMetadata metadatabody = new MeshMetadata();
        metadatabody.withName("mesh-test-api");
        body.withSpec(specbody);
        body.withMetadata(metadatabody);
        body.withKind("Mesh");
        body.withApiVersion("v1");
        request.withBody(body);
        try {
            CreateMeshResponse response = client.createMesh(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.18.7-r5，且启用了可观测性配置的网格
```
# 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 = CreateMeshRequest()
        zipkinExtensionProviders = ZipkinTracingProvider(
            service="zipkin.monitoring.svc.cluster.local",
            port=9411
        )
        listExtensionProvidersTracing = [
            TracingExtensionProvider(
                name="zipkin",
                zipkin=zipkinExtensionProviders
            )
        ]
        listDefaultProvidersTracing = [
            "zipkin"
        ]
        tracingTelemetryConfig = Tracing(
            random_sampling_percentage=1,
            default_providers=listDefaultProvidersTracing,
            extension_providers=listExtensionProvidersTracing
        )
        listLtsAccessLogging = [
            LtsConfig(
                log_group_id="b884eaeb-xxxx-xxxx-xxxx-f442de73c392",
                log_stream_id="362e11e8-xxxx-xxxx-xxxx-0afdc68da7d2"
            )
        ]
        accessLoggingTelemetryConfig = AccessLogging(
            lts=listLtsAccessLogging
        )
        listAomMetrics = [
            Aom(
                instance_id="602a5b7e-xxxx-xxxx-xxxx-4268c35b0424"
            )
        ]
        metricsTelemetryConfig = Metric(
            aom=listAomMetrics
        )
        telemetryConfigConfig = TelemetryConfig(
            metrics=metricsTelemetryConfig,
            access_logging=accessLoggingTelemetryConfig,
            tracing=tracingTelemetryConfig
        )
        proxyConfigConfig = ProxyConfig(
            include_ip_ranges="10.247.0.0/16"
        )
        configSpec = MeshConfig(
            proxy_config=proxyConfigConfig,
            telemetry_config=telemetryConfigConfig
        )
        listValuesFieldSelector = [
            "1c531b0c-xxxx-xxxx-xxxx-0255ac100b08"
        ]
        fieldSelectorNodes = FieldSelector(
            key="UID",
            operator="In",
            values=listValuesFieldSelector
        )
        nodesInstallation = Selector(
            field_selector=fieldSelectorNodes
        )
        installationClusters = InstallationConfig(
            nodes=nodesInstallation
        )
        listValuesFieldSelector1 = [
            "default"
        ]
        fieldSelectorNamespaces = FieldSelector(
            key="Name",
            operator="In",
            values=listValuesFieldSelector1
        )
        namespacesInjection = Selector(
            field_selector=fieldSelectorNamespaces
        )
        injectionClusters = InjectionConfig(
            namespaces=namespacesInjection
        )
        listClustersExtendParams = [
            MeshCluster(
                cluster_id="cb0ef541-xxxx-xxxx-xxxx-0255ac1001b7",
                injection=injectionClusters,
                installation=installationClusters
            )
        ]
        extendParamsSpec = MeshExtendParams(
            clusters=listClustersExtendParams
        )
        specbody = MeshSpec(
            type="InCluster",
            version="1.18.7-r5",
            extend_params=extendParamsSpec,
            config=configSpec
        )
        metadatabody = MeshMetadata(
            name="mesh-test-api"
        )
        request.body = Mesh(
            spec=specbody,
            metadata=metadatabody,
            kind="Mesh",
            api_version="v1"
        )
        response = client.create_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.18.7-r5，且启用了可观测性配置的网格
```
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, err := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        SafeBuild()
    if err != nil {
        fmt.Println(err)
        return
    }
    hcClient, err := asm.AsmClientBuilder().
         WithRegion(region.ValueOf("<YOUR REGION>")).
         WithCredential(auth).
         SafeBuild()
    if err != nil {
        fmt.Println(err)
        return
    }
    client := asm.NewAsmClient(hcClient)
    request := &model.CreateMeshRequest{}
serviceZipkin:= "zipkin.monitoring.svc.cluster.local"
portZipkin:= int32(9411)
zipkinExtensionProviders := &model.ZipkinTracingProvider{
Service: &serviceZipkin,
Port: &portZipkin,
}
nameExtensionProviders:= "zipkin"
var listExtensionProvidersTracing = []model.TracingExtensionProvider{
        {
            Name: &nameExtensionProviders,
            Zipkin: zipkinExtensionProviders,
        },
    }
var listDefaultProvidersTracing = []string{
        "zipkin",
    }
randomSamplingPercentageTracing:= float32(1)
tracingTelemetryConfig := &model.Tracing{
RandomSamplingPercentage: &randomSamplingPercentageTracing,
DefaultProviders: &listDefaultProvidersTracing,
ExtensionProviders: &listExtensionProvidersTracing,
}
logGroupIDLts:= "b884eaeb-xxxx-xxxx-xxxx-f442de73c392"
logStreamIDLts:= "362e11e8-xxxx-xxxx-xxxx-0afdc68da7d2"
var listLtsAccessLogging = []model.LtsConfig{
        {
            LogGroupID: &logGroupIDLts,
            LogStreamID: &logStreamIDLts,
        },
    }
accessLoggingTelemetryConfig := &model.AccessLogging{
Lts: &listLtsAccessLogging,
}
var listAomMetrics = []model.Aom{
        {
            InstanceID: "602a5b7e-xxxx-xxxx-xxxx-4268c35b0424",
        },
    }
metricsTelemetryConfig := &model.Metric{
Aom: &listAomMetrics,
}
telemetryConfigConfig := &model.TelemetryConfig{
Metrics: metricsTelemetryConfig,
AccessLogging: accessLoggingTelemetryConfig,
Tracing: tracingTelemetryConfig,
}
includeIPRangesProxyConfig:= "10.247.0.0/16"
proxyConfigConfig := &model.ProxyConfig{
IncludeIPRanges: &includeIPRangesProxyConfig,
}
configSpec := &model.MeshConfig{
ProxyConfig: proxyConfigConfig,
TelemetryConfig: telemetryConfigConfig,
}
var listValuesFieldSelector = []string{
        "1c531b0c-xxxx-xxxx-xxxx-0255ac100b08",
    }
fieldSelectorNodes := &model.FieldSelector{
Key: "UID",
Operator: "In",
Values: listValuesFieldSelector,
}
nodesInstallation := &model.Selector{
FieldSelector: fieldSelectorNodes,
}
installationClusters := &model.InstallationConfig{
Nodes: nodesInstallation,
}
var listValuesFieldSelector1 = []string{
        "default",
    }
fieldSelectorNamespaces := &model.FieldSelector{
Key: "Name",
Operator: "In",
Values: listValuesFieldSelector1,
}
namespacesInjection := &model.Selector{
FieldSelector: fieldSelectorNamespaces,
}
injectionClusters := &model.InjectionConfig{
Namespaces: namespacesInjection,
}
var listClustersExtendParams = []model.MeshCluster{
        {
            ClusterID: "cb0ef541-xxxx-xxxx-xxxx-0255ac1001b7",
            Injection: injectionClusters,
            Installation: installationClusters,
        },
    }
extendParamsSpec := &model.MeshExtendParams{
Clusters: listClustersExtendParams,
}
specbody := &model.MeshSpec{
Type: model.GetMeshSpecTypeEnum().IN_CLUSTER,
Version: "1.18.7-r5",
ExtendParams: extendParamsSpec,
Config: configSpec,
}
metadatabody := &model.MeshMetadata{
Name: "mesh-test-api",
}
request.Body = &model.Mesh{
Spec: specbody,
Metadata: metadatabody,
Kind: "Mesh",
ApiVersion: "v1",
}
response, err := client.CreateMesh(request)
if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}
```
#### 更多
更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/ASM/sdk?api=CreateMesh)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述                   |
|:---|:---|
| 201 | 表示创建网格任务下发成功，开始创建网格  |
| 400 | 用户提供的网格创建参数有问题，未通过校验 |
| 409 | 需要创建的网格与现有网格冲突       |
| 500 | 创建过程中出现问题            |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-asm/ErrorCode.html)。
