更新时间:2024-03-12 GMT+08:00

节点迁移

功能介绍

该API用于在指定集群下迁移节点到另一集群。

集群管理的URL格式为:https://Endpoint/uri。其中uri为资源路径,也即API访问的路径。

接口约束

  • 仅支持在同一VPC、同一项目下的不同集群间进行迁移。

  • CCE Turbo集群和CCE Standard集群间不支持互迁。

  • DEC集群和非DEC集群间不支持互迁。

  • 开启IPv6开关和未开启IPv6开关的集群间不支持互迁。

  • 只支持迁移到目标集群的默认节点池内。

  • CCE Turbo集群下弹性云服务器-物理机类型节点不支持迁移。

调用方法

请参见如何调用API

URI

PUT /api/v3/projects/{project_id}/clusters/{cluster_id}/nodes/operation/migrateto/{target_cluster_id}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID,获取方式请参见如何获取接口URI中参数

cluster_id

String

集群ID,获取方式请参见如何获取接口URI中参数

target_cluster_id

String

集群ID,获取方式请参见如何获取接口URI中参数

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

Content-Type

String

消息体的类型(格式)

X-Auth-Token

String

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

表3 请求Body参数

参数

是否必选

参数类型

描述

apiVersion

String

API版本,固定值“v3”。

kind

String

API类型,固定值“MigrateNodesTask”。

spec

MigrateNodesSpec object

配置信息

status

TaskStatus object

任务状态

表4 MigrateNodesSpec

参数

是否必选

参数类型

描述

os

String

操作系统类型,须精确到版本号。 当指定“alpha.cce/NodeImageID”参数时,“os”参数必须和用户自定义镜像的操作系统一致。

extendParam

MigrateNodeExtendParam object

迁移节点时的扩展参数

login

Login object

节点的登录方式。密钥对和密码登录方式二者必选其一。

runtime

Runtime object

容器运行时

nodes

Array of NodeItem objects

待操作节点列表

表5 MigrateNodeExtendParam

参数

是否必选

参数类型

描述

maxPods

Integer

节点最大允许创建的实例数(Pod),该数量包含系统默认实例,取值范围为16~256。 该设置的目的为防止节点因管理过多实例而负载过重,请根据您的业务需要进行设置。

DockerLVMConfigOverride

String

Docker数据盘配置项。

待迁移节点的磁盘类型须和创建时一致(即“DockerLVMConfigOverride”参数中“diskType”字段的值须和创建时一致),请确保单次接口调用时批量选择的节点磁盘类型一致。

默认配置示例如下:

"DockerLVMConfigOverride":"dockerThinpool=vgpaas/90%VG;kubernetesLV=vgpaas/10%VG;diskType=evs;lvType=linear"

包含如下字段:

  • userLV(可选):用户空间的大小,示例格式:vgpaas/20%VG

  • userPath(可选):用户空间挂载路径,示例格式:/home/wqt-test

  • diskType:磁盘类型,目前只有evs、hdd和ssd三种格式

  • lvType:逻辑卷的类型,目前支持linear和striped两种,示例格式:striped

  • dockerThinpool:Docker盘的空间大小,示例格式:vgpaas/60%VG

  • kubernetesLV:Kubelet空间大小,示例格式:vgpaas/20%VG

alpha.cce/preInstall

String

安装前执行脚本

说明:

输入的值需要经过Base64编码,方法为echo -n "待编码内容" | base64。

alpha.cce/postInstall

String

安装后执行脚本

说明:

输入的值需要经过Base64编码,方法为echo -n "待编码内容" | base64。

alpha.cce/NodeImageID

String

指定待切换目标操作系统所使用的用户镜像ID。 当指定“alpha.cce/NodeImageID”参数时,“os”参数必须和用户自定义镜像的操作系统一致。

表6 Login

参数

是否必选

参数类型

描述

sshKey

String

选择密钥对方式登录时的密钥对名称。

userPassword

UserPassword object

选择密码方式登录时的帐号密码信息,之后可通过此帐号密码登录节点。

表7 UserPassword

参数

是否必选

参数类型

描述

username

String

登录帐号,默认为“root”

password

String

登录密码,若创建节点通过用户名密码方式,即使用该字段,则响应体中该字段作屏蔽展示。 密码复杂度要求:

  • 长度为8-26位。

  • 密码至少必须包含大写字母、小写字母、数字和特殊字符(!@$%^-_=+[{}]:,./?~#*)中的三种。

  • 密码不能包含用户名或用户名的逆序。 创建节点时password字段需要加盐加密,具体方法请参见创建节点时password字段加盐加密

表8 Runtime

参数

是否必选

参数类型

描述

name

String

容器运行时,默认场景:

  • v1.25以下集群:默认为"docker"

  • v1.25及以上集群,随操作系统变化,默认的容器运行时不同:操作系统为EulerOS 2.5、EulerOS 2.8的节点默认为"docker",其余操作系统的节点默认为"containerd"

表9 NodeItem

参数

是否必选

参数类型

描述

uid

String

节点ID

表10 TaskStatus

参数

是否必选

参数类型

描述

jobID

String

任务ID,供调用者查询任务进度。

响应参数

状态码: 200

表11 响应Body参数

参数

参数类型

描述

apiVersion

String

API版本,固定值“v3”。

kind

String

API类型,固定值“MigrateNodesTask”。

spec

MigrateNodesSpec object

配置信息

status

TaskStatus object

任务状态

表12 MigrateNodesSpec

参数

参数类型

描述

os

String

操作系统类型,须精确到版本号。 当指定“alpha.cce/NodeImageID”参数时,“os”参数必须和用户自定义镜像的操作系统一致。

extendParam

MigrateNodeExtendParam object

迁移节点时的扩展参数

login

Login object

节点的登录方式。密钥对和密码登录方式二者必选其一。

runtime

Runtime object

容器运行时

nodes

Array of NodeItem objects

待操作节点列表

表13 MigrateNodeExtendParam

参数

参数类型

描述

maxPods

Integer

节点最大允许创建的实例数(Pod),该数量包含系统默认实例,取值范围为16~256。 该设置的目的为防止节点因管理过多实例而负载过重,请根据您的业务需要进行设置。

DockerLVMConfigOverride

String

Docker数据盘配置项。

待迁移节点的磁盘类型须和创建时一致(即“DockerLVMConfigOverride”参数中“diskType”字段的值须和创建时一致),请确保单次接口调用时批量选择的节点磁盘类型一致。

默认配置示例如下:

"DockerLVMConfigOverride":"dockerThinpool=vgpaas/90%VG;kubernetesLV=vgpaas/10%VG;diskType=evs;lvType=linear"

包含如下字段:

  • userLV(可选):用户空间的大小,示例格式:vgpaas/20%VG

  • userPath(可选):用户空间挂载路径,示例格式:/home/wqt-test

  • diskType:磁盘类型,目前只有evs、hdd和ssd三种格式

  • lvType:逻辑卷的类型,目前支持linear和striped两种,示例格式:striped

  • dockerThinpool:Docker盘的空间大小,示例格式:vgpaas/60%VG

  • kubernetesLV:Kubelet空间大小,示例格式:vgpaas/20%VG

alpha.cce/preInstall

String

安装前执行脚本

说明:

输入的值需要经过Base64编码,方法为echo -n "待编码内容" | base64。

alpha.cce/postInstall

String

安装后执行脚本

说明:

输入的值需要经过Base64编码,方法为echo -n "待编码内容" | base64。

alpha.cce/NodeImageID

String

指定待切换目标操作系统所使用的用户镜像ID。 当指定“alpha.cce/NodeImageID”参数时,“os”参数必须和用户自定义镜像的操作系统一致。

表14 Login

参数

参数类型

描述

sshKey

String

选择密钥对方式登录时的密钥对名称。

userPassword

UserPassword object

选择密码方式登录时的帐号密码信息,之后可通过此帐号密码登录节点。

表15 UserPassword

参数

参数类型

描述

username

String

登录帐号,默认为“root”

password

String

登录密码,若创建节点通过用户名密码方式,即使用该字段,则响应体中该字段作屏蔽展示。 密码复杂度要求:

  • 长度为8-26位。

  • 密码至少必须包含大写字母、小写字母、数字和特殊字符(!@$%^-_=+[{}]:,./?~#*)中的三种。

  • 密码不能包含用户名或用户名的逆序。 创建节点时password字段需要加盐加密,具体方法请参见创建节点时password字段加盐加密

表16 Runtime

参数

参数类型

描述

name

String

容器运行时,默认场景:

  • v1.25以下集群:默认为"docker"

  • v1.25及以上集群,随操作系统变化,默认的容器运行时不同:操作系统为EulerOS 2.5、EulerOS 2.8的节点默认为"docker",其余操作系统的节点默认为"containerd"

表17 NodeItem

参数

参数类型

描述

uid

String

节点ID

表18 TaskStatus

参数

参数类型

描述

jobID

String

任务ID,供调用者查询任务进度。

请求示例

  • 迁移一个节点到另一个集群中,且节点操作系统为EulerOS 2.5。

    PUT /api/v3/projects/{project_id}/clusters/{cluster_id}/nodes/operation/migrateto/{target_cluster_id}
    
    {
      "spec" : {
        "os" : "EulerOS 2.5",
        "login" : {
          "sshKey" : "KeyPair-001"
        },
        "nodes" : [ {
          "uid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
        }, {
          "uid" : "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"
        } ]
      }
    }
  • 迁移一个节点到另一个集群中,且节点操作系统为EulerOS 2.5,并指定用户镜像ID。

    PUT /api/v3/projects/{project_id}/clusters/{cluster_id}/nodes/operation/migrateto/{target_cluster_id}
    
    {
      "spec" : {
        "os" : "EulerOS 2.5",
        "extendParam" : {
          "alpha.cce/NodeImageID" : "cc697ad7-9563-11e8-8ea7-0255ac106311"
        },
        "login" : {
          "sshKey" : "KeyPair-001"
        },
        "nodes" : [ {
          "uid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
        }, {
          "uid" : "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"
        } ]
      }
    }

响应示例

状态码: 200

表示在指定集群下迁移节点至另一集群的作业下发成功。

{
  "spec" : {
    "os" : "EulerOS 2.5",
    "login" : {
      "sshKey" : "KeyPair-001"
    },
    "runtime" : {
      "name" : "docker"
    },
    "nodes" : [ {
      "uid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    }, {
      "uid" : "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"
    } ]
  },
  "status" : {
    "jobID" : "2ec9b78d-9368-46f3-8f29-d1a95622a568"
  }
}

SDK代码示例

SDK代码示例如下。

  • 迁移一个节点到另一个集群中,且节点操作系统为EulerOS 2.5。

     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
    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.cce.v3.region.CceRegion;
    import com.huaweicloud.sdk.cce.v3.*;
    import com.huaweicloud.sdk.cce.v3.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class MigrateNodeSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            CceClient client = CceClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(CceRegion.valueOf("<YOUR REGION>"))
                    .build();
            MigrateNodeRequest request = new MigrateNodeRequest();
            MigrateNodesTask body = new MigrateNodesTask();
            List<NodeItem> listSpecNodes = new ArrayList<>();
            listSpecNodes.add(
                new NodeItem()
                    .withUid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
            );
            listSpecNodes.add(
                new NodeItem()
                    .withUid("yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy")
            );
            Login loginSpec = new Login();
            loginSpec.withSshKey("KeyPair-001");
            MigrateNodesSpec specbody = new MigrateNodesSpec();
            specbody.withOs("EulerOS 2.5")
                .withLogin(loginSpec)
                .withNodes(listSpecNodes);
            body.withSpec(specbody);
            request.withBody(body);
            try {
                MigrateNodeResponse response = client.migrateNode(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());
            }
        }
    }
    
  • 迁移一个节点到另一个集群中,且节点操作系统为EulerOS 2.5,并指定用户镜像ID。

     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
    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.cce.v3.region.CceRegion;
    import com.huaweicloud.sdk.cce.v3.*;
    import com.huaweicloud.sdk.cce.v3.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class MigrateNodeSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            CceClient client = CceClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(CceRegion.valueOf("<YOUR REGION>"))
                    .build();
            MigrateNodeRequest request = new MigrateNodeRequest();
            MigrateNodesTask body = new MigrateNodesTask();
            [](model.NodeItem) listSpecNodes = new ArrayList<>();
            listSpecNodes.add(
                new NodeItem()
                    .withUid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
            );
            listSpecNodes.add(
                new NodeItem()
                    .withUid("yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy")
            );
            Login loginSpec = new Login();
            loginSpec.withSshKey("KeyPair-001");
            MigrateNodeExtendParam extendParamSpec = new MigrateNodeExtendParam();
            extendParamSpec.withAlphaCceNodeImageID("cc697ad7-9563-11e8-8ea7-0255ac106311");
            MigrateNodesSpec specbody = new MigrateNodesSpec();
            specbody.withOs("EulerOS 2.5")
                .withExtendParam(extendParamSpec)
                .withLogin(loginSpec)
                .withNodes(listSpecNodes);
            body.withSpec(specbody);
            request.withBody(body);
            try {
                MigrateNodeResponse response = client.migrateNode(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());
            }
        }
    }
    
  • 迁移一个节点到另一个集群中,且节点操作系统为EulerOS 2.5。

     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
    # coding: utf-8
    
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkcce.v3.region.cce_region import CceRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkcce.v3 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 = __import__('os').getenv("CLOUD_SDK_AK")
        sk = __import__('os').getenv("CLOUD_SDK_SK")
    
        credentials = BasicCredentials(ak, sk) \
    
        client = CceClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(CceRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = MigrateNodeRequest()
            listNodesSpec = [
                NodeItem(
                    uid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
                ),
                NodeItem(
                    uid="yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"
                )
            ]
            loginSpec = Login(
                ssh_key="KeyPair-001"
            )
            specbody = MigrateNodesSpec(
                os="EulerOS 2.5",
                login=loginSpec,
                nodes=listNodesSpec
            )
            request.body = MigrateNodesTask(
                spec=specbody
            )
            response = client.migrate_node(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 迁移一个节点到另一个集群中,且节点操作系统为EulerOS 2.5,并指定用户镜像ID。

     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
    # coding: utf-8
    
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkcce.v3.region.cce_region import CceRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkcce.v3 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 = __import__('os').getenv("CLOUD_SDK_AK")
        sk = __import__('os').getenv("CLOUD_SDK_SK")
    
        credentials = BasicCredentials(ak, sk) \
    
        client = CceClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(CceRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = MigrateNodeRequest()
            listNodesSpec = [
                NodeItem(
                    uid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
                ),
                NodeItem(
                    uid="yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"
                )
            ]
            loginSpec = Login(
                ssh_key="KeyPair-001"
            )
            extendParamSpec = MigrateNodeExtendParam(
                alpha_cce_node_image_id="cc697ad7-9563-11e8-8ea7-0255ac106311"
            )
            specbody = MigrateNodesSpec(
                os="EulerOS 2.5",
                extend_param=extendParamSpec,
                login=loginSpec,
                nodes=listNodesSpec
            )
            request.body = MigrateNodesTask(
                spec=specbody
            )
            response = client.migrate_node(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 迁移一个节点到另一个集群中,且节点操作系统为EulerOS 2.5。

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        cce "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := cce.NewCceClient(
            cce.CceClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.MigrateNodeRequest{}
    	var listNodesSpec = []model.NodeItem{
            {
                Uid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            },
            {
                Uid: "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy",
            },
        }
    	sshKeyLogin:= "KeyPair-001"
    	loginSpec := &model.Login{
    		SshKey: &sshKeyLogin,
    	}
    	specbody := &model.MigrateNodesSpec{
    		Os: "EulerOS 2.5",
    		Login: loginSpec,
    		Nodes: listNodesSpec,
    	}
    	request.Body = &model.MigrateNodesTask{
    		Spec: specbody,
    	}
    	response, err := client.MigrateNode(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 迁移一个节点到另一个集群中,且节点操作系统为EulerOS 2.5,并指定用户镜像ID。

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        cce "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := cce.NewCceClient(
            cce.CceClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.MigrateNodeRequest{}
    	var listNodesSpec = []model.NodeItem{
            {
                Uid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            },
            {
                Uid: "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy",
            },
        }
    	sshKeyLogin:= "KeyPair-001"
    	loginSpec := &model.Login{
    		SshKey: &sshKeyLogin,
    	}
    	alphaCceNodeImageIDExtendParam:= "cc697ad7-9563-11e8-8ea7-0255ac106311"
    	extendParamSpec := &model.MigrateNodeExtendParam{
    		AlphaCceNodeImageID: &alphaCceNodeImageIDExtendParam,
    	}
    	specbody := &model.MigrateNodesSpec{
    		Os: "EulerOS 2.5",
    		ExtendParam: extendParamSpec,
    		Login: loginSpec,
    		Nodes: listNodesSpec,
    	}
    	request.Body = &model.MigrateNodesTask{
    		Spec: specbody,
    	}
    	response, err := client.MigrateNode(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

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

状态码

状态码

描述

200

表示在指定集群下迁移节点至另一集群的作业下发成功。

错误码

请参见错误码