Updated on 2026-06-25 GMT+08:00

Creating a Mesh

Function

This API is used to create a mesh.

Calling Method

For details, see Calling APIs.

Authorization Information

Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.

  • If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
  • If you are using identity policy-based authorization, the following identity policy-based permissions are required.

    Action

    Access Level

    Resource Type (*: required)

    Condition Key

    Alias

    Dependencies

    asm:mesh:create

    Write

    mesh *

    -

    -

    -

    -

    • g:EnterpriseProjectId

    • g:TagKeys

    • g:RequestTag/<tag-key>

URI

POST /v1/{project_id}/meshes

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

Content-Type

Yes

String

Message body type (format)

Range:

  • application/json;charset=utf-8: The content is in JSON format and encoded using UTF-8.

  • application/json: The content is in JSON format.

X-Auth-Token

Yes

String

API calling can be authenticated using a token or AK/SK. If you use a token, this parameter is mandatory and must be set to the token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

apiVersion

Yes

String

API version. Fixed value: v1

kind

Yes

String

API type. Fixed value: Mesh or mesh

metadata

Yes

MeshMetadata object

Basic information about a mesh. Metadata is a collection of attributes.

spec

Yes

MeshSpec object

Detailed description of a mesh. ASM creates or updates the mesh based on spec.

Table 4 MeshMetadata

Parameter

Mandatory

Type

Description

name

Yes

String

Mesh name

Enter 4 to 64 characters. The name must start with a lowercase letter and not end with a hyphen (-). Only lowercase letters, digits, and hyphens (-) are allowed.

Table 5 MeshSpec

Parameter

Mandatory

Type

Description

type

Yes

String

Mesh type

Range:

  • InCluster: mesh with an in-cluster control plane. The value is InCluster for the Basic mesh. Currently, only this type is supported.

version

Yes

String

Mesh version

extendParams

Yes

MeshExtendParams object

Extensions of a mesh

ipv6Enable

No

Boolean

Whether a mesh supports IPv6

tags

No

Array of MeshTags objects

Resource tags of a mesh. If you need to configure resource tags, ensure that the TMS service has been brought online in the current region.

config

No

MeshConfig object

Mesh configuration

Table 6 MeshExtendParams

Parameter

Mandatory

Type

Description

clusters

Yes

Array of MeshCluster objects

Cluster information in a mesh

Table 7 MeshCluster

Parameter

Mandatory

Type

Description

clusterID

Yes

String

Cluster ID, which is unique and can be used to query the cluster to be added

injection

No

InjectionConfig object

Sidecar injection configuration

installation

Yes

InstallationConfig object

Installation configuration of a mesh component

Table 8 InjectionConfig

Parameter

Mandatory

Type

Description

namespaces

No

Selector object

Namespace to be injected.

Table 9 InstallationConfig

Parameter

Mandatory

Type

Description

nodes

Yes

Selector object

Node where the mesh component is installed.

Table 10 Selector

Parameter

Mandatory

Type

Description

fieldSelector

Yes

FieldSelector object

Field selector

Table 11 FieldSelector

Parameter

Mandatory

Type

Description

key

Yes

String

Key

operator

Yes

String

Operator. The value can only be In.

values

Yes

Array of strings

Value

Table 12 MeshTags

Parameter

Mandatory

Type

Description

key

No

String

Key

  • Cannot be empty and can contain a maximum of 128 characters.

  • Can be letters, digits, and spaces in UTF-8 format.

  • Can contain the following special characters: _.:/=+-@

  • Cannot start with sys

value

No

String

Value

  • Can contain a maximum of 255 characters and can be empty but not is mandatory.

  • Can be letters, digits, and spaces in UTF-8 format.

  • Can contain the following special characters: _.:/=+-@

Table 13 MeshConfig

Parameter

Mandatory

Type

Description

proxyConfig

No

ProxyConfig object

Data plane configuration of a mesh

telemetryConfig

No

TelemetryConfig object

Observability configuration of a mesh

Table 14 ProxyConfig

Parameter

Mandatory

Type

Description

includeIPRanges

No

String

IP address ranges that will be included for outbound traffic redirection. Use commas (,) to separate the IP address ranges.

excludeIPRanges

No

String

IP address ranges that will be excluded for outbound traffic redirection. Use commas (,) to separate the IP address ranges.

excludeOutboundPorts

No

String

Ports that will be excluded for outbound traffic redirection. Use commas (,) to separate the ports.

excludeInboundPorts

No

String

Ports that will be excluded for inbound traffic redirection. Use commas (,) to separate the ports.

includeOutboundPorts

No

String

Ports that will be included for outbound traffic redirection. Use commas (,) to separate the ports.

includeInboundPorts

No

String

Ports that will be included for inbound traffic redirection. Use commas (,) to separate the ports.

Table 15 TelemetryConfig

Parameter

Mandatory

Type

Description

metrics

No

Metric object

Application metric configuration, which is used to report mesh metrics. To enable this configuration, you need to install the Cloud Native Cluster Monitoring add-on in the cluster.

accessLogging

No

AccessLogging object

Access log configuration, which is used to report access logs of Istio proxies in a mesh. To enable this configuration, you need to install the Cloud Native Log Collection add-on in the cluster.

tracing

No

Tracing object

Tracing configuration, which is used to report traces in a mesh.

Table 16 Metric

Parameter

Mandatory

Type

Description

aom

No

Array of Aom objects

AOM instance configuration

Table 17 Aom

Parameter

Mandatory

Type

Description

instanceID

Yes

String

AOM instance ID

Table 18 AccessLogging

Parameter

Mandatory

Type

Description

lts

No

Array of LtsConfig objects

LTS configuration

Table 19 LtsConfig

Parameter

Mandatory

Type

Description

logGroupID

No

String

Log group ID of access logs

logStreamID

No

String

Log stream ID of access logs

Table 20 Tracing

Parameter

Mandatory

Type

Description

randomSamplingPercentage

No

Float

Tracing sampling rate

defaultProviders

No

Array of strings

Name of the default provider that tracing reports data to, which must match the name field in extensionProviders or use the preset provider apm-otel of ASM.

If apm-otel is used, ensure that APM 2.0 is supported in the current region and the mesh version is later than 1.18.

extensionProviders

No

Array of TracingExtensionProvider objects

User-defined provider. Currently, Zipkin is supported.

If Zipkin is used, ensure that the mesh version is 1.15 or later.

Table 21 TracingExtensionProvider

Parameter

Mandatory

Type

Description

name

No

String

Provider instance name

zipkin

No

ZipkinTracingProvider object

Provider's Zipkin configuration

Table 22 ZipkinTracingProvider

Parameter

Mandatory

Type

Description

service

No

String

Service address of Zipkin

port

No

Integer

Service port of Zipkin

Response Parameters

Status code: 201

Table 23 Response body parameters

Parameter

Type

Description

apiVersion

String

API version. Fixed value: v1

kind

String

API type. Fixed value: Mesh or mesh

metadata

MeshMetadata object

Basic information about a mesh. Metadata is a collection of attributes.

spec

MeshSpec object

Detailed description of a mesh. ASM creates or updates the mesh based on spec.

status

MeshStatus object

Mesh status,

which is generated by ASM.

Table 24 MeshMetadata

Parameter

Type

Description

name

String

Mesh name

Enter 4 to 64 characters. The name must start with a lowercase letter and not end with a hyphen (-). Only lowercase letters, digits, and hyphens (-) are allowed.

uid

String

Mesh ID, which uniquely identifies a resource. The value is automatically generated after the mesh is created and cannot be specified.

creationTimestamp

String

Time when a mesh is created

Table 25 MeshSpec

Parameter

Type

Description

type

String

Mesh type

Range:

  • InCluster: mesh with an in-cluster control plane. The value is InCluster for the Basic mesh. Currently, only this type is supported.

version

String

Mesh version

extendParams

MeshExtendParams object

Extensions of a mesh

ipv6Enable

Boolean

Whether a mesh supports IPv6

tags

Array of MeshTags objects

Resource tags of a mesh. If you need to configure resource tags, ensure that the TMS service has been brought online in the current region.

config

MeshConfig object

Mesh configuration

Table 26 MeshExtendParams

Parameter

Type

Description

clusters

Array of MeshCluster objects

Cluster information in a mesh

Table 27 MeshCluster

Parameter

Type

Description

clusterID

String

Cluster ID, which is unique and can be used to query the cluster to be added

injection

InjectionConfig object

Sidecar injection configuration

installation

InstallationConfig object

Installation configuration of a mesh component

Table 28 InjectionConfig

Parameter

Type

Description

namespaces

Selector object

Namespace to be injected.

Table 29 InstallationConfig

Parameter

Type

Description

nodes

Selector object

Node where the mesh component is installed.

Table 30 Selector

Parameter

Type

Description

fieldSelector

FieldSelector object

Field selector

Table 31 FieldSelector

Parameter

Type

Description

key

String

Key

operator

String

Operator. The value can only be In.

values

Array of strings

Value

Table 32 MeshTags

Parameter

Type

Description

key

String

Key

  • Cannot be empty and can contain a maximum of 128 characters.

  • Can be letters, digits, and spaces in UTF-8 format.

  • Can contain the following special characters: _.:/=+-@

  • Cannot start with sys

value

String

Value

  • Can contain a maximum of 255 characters and can be empty but not is mandatory.

  • Can be letters, digits, and spaces in UTF-8 format.

  • Can contain the following special characters: _.:/=+-@

Table 33 MeshConfig

Parameter

Type

Description

proxyConfig

ProxyConfig object

Data plane configuration of a mesh

telemetryConfig

TelemetryConfig object

Observability configuration of a mesh

Table 34 ProxyConfig

Parameter

Type

Description

includeIPRanges

String

IP address ranges that will be included for outbound traffic redirection. Use commas (,) to separate the IP address ranges.

excludeIPRanges

String

IP address ranges that will be excluded for outbound traffic redirection. Use commas (,) to separate the IP address ranges.

excludeOutboundPorts

String

Ports that will be excluded for outbound traffic redirection. Use commas (,) to separate the ports.

excludeInboundPorts

String

Ports that will be excluded for inbound traffic redirection. Use commas (,) to separate the ports.

includeOutboundPorts

String

Ports that will be included for outbound traffic redirection. Use commas (,) to separate the ports.

includeInboundPorts

String

Ports that will be included for inbound traffic redirection. Use commas (,) to separate the ports.

Table 35 TelemetryConfig

Parameter

Type

Description

metrics

Metric object

Application metric configuration, which is used to report mesh metrics. To enable this configuration, you need to install the Cloud Native Cluster Monitoring add-on in the cluster.

accessLogging

AccessLogging object

Access log configuration, which is used to report access logs of Istio proxies in a mesh. To enable this configuration, you need to install the Cloud Native Log Collection add-on in the cluster.

tracing

Tracing object

Tracing configuration, which is used to report traces in a mesh.

Table 36 Metric

Parameter

Type

Description

aom

Array of Aom objects

AOM instance configuration

Table 37 Aom

Parameter

Type

Description

instanceID

String

AOM instance ID

Table 38 AccessLogging

Parameter

Type

Description

lts

Array of LtsConfig objects

LTS configuration

Table 39 LtsConfig

Parameter

Type

Description

logGroupID

String

Log group ID of access logs

logStreamID

String

Log stream ID of access logs

Table 40 Tracing

Parameter

Type

Description

randomSamplingPercentage

Float

Tracing sampling rate

defaultProviders

Array of strings

Name of the default provider that tracing reports data to, which must match the name field in extensionProviders or use the preset provider apm-otel of ASM.

If apm-otel is used, ensure that APM 2.0 is supported in the current region and the mesh version is later than 1.18.

extensionProviders

Array of TracingExtensionProvider objects

User-defined provider. Currently, Zipkin is supported.

If Zipkin is used, ensure that the mesh version is 1.15 or later.

Table 41 TracingExtensionProvider

Parameter

Type

Description

name

String

Provider instance name

zipkin

ZipkinTracingProvider object

Provider's Zipkin configuration

Table 42 ZipkinTracingProvider

Parameter

Type

Description

service

String

Service address of Zipkin

port

Integer

Service port of Zipkin

Table 43 MeshStatus

Parameter

Type

Description

phase

String

Mesh status.

  • Running: The mesh is running.

  • Creating: The mesh is being created.

  • CreateFailed: The mesh fails to be created.

  • Deleting: The mesh is being deleted.

  • DeleteFailed: The mesh fails to be deleted.

  • Upgrading: The mesh is being upgraded.

  • UpgradeFailed: The mesh fails to be upgraded.

  • RollingBack: The mesh is being rolled back.

  • RollbackFailed: The mesh fails to be rolled back.

updateTimestamp

String

Time when a mesh is updated

Status code: 400

Table 44 Response body parameters

Parameter

Type

Description

errorCode

String

Error code

Status code: 409

Table 45 Response body parameters

Parameter

Type

Description

errorCode

String

Error code

Status code: 500

Table 46 Response body parameters

Parameter

Type

Description

errorCode

String

Error code

Example Requests

Creating a mesh

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
            }
          } ]
        }
      }
    }
  }
}

Example Responses

Status code: 201

The mesh creation task is delivered, and the mesh creation starts.

{
  "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 Sample Code

The SDK sample code is as follows.

Java

Creating a mesh

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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

Creating a mesh

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# 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

Creating a mesh

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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)
    }
}

More

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

201

The mesh creation task is delivered, and the mesh creation starts.

400

Verification failed due to incorrect parameters for mesh creation.

409

The mesh to be created conflicts with an existing mesh.

500

An error occurred during the creation.

Error Codes

See Error Codes.