计算
弹性云服务器 ECS
Flexus云服务
裸金属服务器 BMS
弹性伸缩 AS
镜像服务 IMS
专属主机 DeH
函数工作流 FunctionGraph
云手机服务器 CPH
Huawei Cloud EulerOS
网络
虚拟私有云 VPC
弹性公网IP EIP
虚拟专用网络 VPN
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
VPC终端节点 VPCEP
云连接 CC
企业路由器 ER
企业交换机 ESW
全球加速 GA
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
边缘安全 EdgeSec
威胁检测服务 MTD
CDN与智能边缘
内容分发网络 CDN
CloudPond云服务
智能边缘云 IEC
迁移
主机迁移服务 SMS
对象存储迁移服务 OMS
云数据迁移 CDM
迁移中心 MGC
大数据
MapReduce服务 MRS
数据湖探索 DLI
表格存储服务 CloudTable
云搜索服务 CSS
数据接入服务 DIS
数据仓库服务 GaussDB(DWS)
数据治理中心 DataArts Studio
数据可视化 DLV
数据湖工厂 DLF
湖仓构建 LakeFormation
企业应用
云桌面 Workspace
应用与数据集成平台 ROMA Connect
云解析服务 DNS
专属云
专属计算集群 DCC
IoT物联网
IoT物联网
设备接入 IoTDA
智能边缘平台 IEF
用户服务
账号中心
费用中心
成本中心
资源中心
企业管理
工单管理
国际站常见问题
ICP备案
我的凭证
支持计划
客户运营能力
合作伙伴支持计划
专业服务
区块链
区块链服务 BCS
Web3节点引擎服务 NES
解决方案
SAP
高性能计算 HPC
视频
视频直播 Live
视频点播 VOD
媒体处理 MPC
实时音视频 SparkRTC
数字内容生产线 MetaStudio
存储
对象存储服务 OBS
云硬盘 EVS
云备份 CBR
存储容灾服务 SDRS
高性能弹性文件服务 SFS Turbo
弹性文件服务 SFS
云硬盘备份 VBS
云服务器备份 CSBS
数据快递服务 DES
专属分布式存储服务 DSS
容器
云容器引擎 CCE
容器镜像服务 SWR
应用服务网格 ASM
华为云UCS
云容器实例 CCI
管理与监管
云监控服务 CES
统一身份认证服务 IAM
资源编排服务 RFS
云审计服务 CTS
标签管理服务 TMS
云日志服务 LTS
配置审计 Config
资源访问管理 RAM
消息通知服务 SMN
应用运维管理 AOM
应用性能管理 APM
组织 Organizations
优化顾问 OA
IAM 身份中心
云运维中心 COC
资源治理中心 RGC
应用身份管理服务 OneAccess
数据库
云数据库 RDS
文档数据库服务 DDS
数据管理服务 DAS
数据复制服务 DRS
云数据库 GeminiDB
云数据库 GaussDB
分布式数据库中间件 DDM
数据库和应用迁移 UGO
云数据库 TaurusDB
人工智能
人脸识别服务 FRS
图引擎服务 GES
图像识别 Image
内容审核 Moderation
文字识别 OCR
AI开发平台ModelArts
图像搜索 ImageSearch
对话机器人服务 CBS
华为HiLens
视频智能分析服务 VIAS
语音交互服务 SIS
应用中间件
分布式缓存服务 DCS
API网关 APIG
微服务引擎 CSE
分布式消息服务Kafka版
分布式消息服务RabbitMQ版
分布式消息服务RocketMQ版
多活高可用服务 MAS
事件网格 EG
企业协同
华为云会议 Meeting
云通信
消息&短信 MSGSMS
云生态
合作伙伴中心
云商店
开发者工具
SDK开发指南
API签名指南
Terraform
华为云命令行工具服务 KooCLI
其他
产品价格详情
系统权限
管理控制台
客户关联华为云合作伙伴须知
消息中心
公共问题
开发与运维
应用管理与运维平台 ServiceStage
软件开发生产线 CodeArts
需求管理 CodeArts Req
部署 CodeArts Deploy
性能测试 CodeArts PerfTest
编译构建 CodeArts Build
流水线 CodeArts Pipeline
制品仓库 CodeArts Artifact
测试计划 CodeArts TestPlan
代码检查 CodeArts Check
代码托管 CodeArts Repo
云应用引擎 CAE
开天aPaaS
云消息服务 KooMessage
云手机服务 KooPhone
云空间服务 KooDrive

创建迁移任务

功能介绍

根据源端服务器创建一个迁移任务。

调用方法

请参见如何调用API

URI

POST /v3/tasks

请求参数

表1 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。

最小长度:1

最大长度:16384

表2 请求Body参数

参数

是否必选

参数类型

描述

name

String

任务名称

最小长度:0

最大长度:255

type

String

任务类型

MIGRATE_FILE:文件级迁移

MIGRATE_BLOCK:块级迁移

枚举值:

  • MIGRATE_FILE

  • MIGRATE_BLOCK

start_target_server

Boolean

迁移后是否启动目的端虚拟机

缺省值:true

auto_start

Boolean

是否自动启动

os_type

String

操作系统类型

最小长度:0

最大长度:255

source_server

SourceServerByTask object

源端服务器信息

target_server

TargetServerByTask object

目的端虚拟机信息

migration_ip

String

迁移IP,如果是自动创建虚拟机,不需要此参数

最小长度:0

最大长度:255

region_name

String

region的名称

最小长度:0

最大长度:255

region_id

String

region ID

最小长度:0

最大长度:255

project_name

String

项目名称

最小长度:0

最大长度:255

project_id

String

项目ID

最小长度:0

最大长度:255

priority

Integer

优先级。默认为1

最小值:0

最大值:65535

vm_template_id

String

自动创建虚拟机使用模板

最小长度:0

最大长度:255

use_public_ip

Boolean

是否使用公网ip

缺省值:true

use_ipv6

Boolean

是否使用ipv6

syncing

Boolean

复制或者同步后是否会继续持续同步,不添加则默认是false

缺省值:false

exist_server

Boolean

是否存在服务,如果存在,则创建任务

start_network_check

Boolean

是否开启网络检测

speed_limit

Integer

迁移速率限制值

最小值:0

最大值:10000

over_speed_threshold

Double

停止迁移的超速阈值。 是一个迁移速率的保护机制,超出该阈值会停止任务。它主要用于控制迁移过程中资源(特别是网络带宽)的消耗,确保系统的整体性能不受单一迁移任务影响 单位是百分比

最小值:0

最大值:100

is_need_consistency_check

Boolean

是否进行一致性校验

表3 SourceServerByTask

参数

是否必选

参数类型

描述

id

String

源端服务器ID

最小长度:0

最大长度:255

表4 TargetServerByTask

参数

是否必选

参数类型

描述

btrfs_list

Array of BtrfsFileSystem objects

btrfs信息,数据从源端获取

数组长度:0 - 65535

disks

Array of TargetDisks objects

磁盘信息

数组长度:0 - 65535

name

String

名称

最小长度:0

最大长度:255

vm_id

String

虚拟机ID

最小长度:0

最大长度:255

volume_groups

Array of VolumeGroups objects

卷组,数据从源端获取

数组长度:0 - 65535

表5 BtrfsFileSystem

参数

是否必选

参数类型

描述

name

String

文件系统名称

最小长度:0

最大长度:255

label

String

文件系统标签,若无标签为空字符串

最小长度:0

最大长度:255

uuid

String

文件系统的uuid

最小长度:0

最大长度:255

device

String

btrfs包含的设备名称

最小长度:0

最大长度:255

size

Long

文件系统数据占用大小

最小值:0

最大值:9223372036854775807

nodesize

Long

btrfs节点大小

最小值:0

最大值:9223372036854775807

sectorsize

Integer

扇区大小

最小值:0

最大值:2147483647

data_profile

String

数据配置(RAD)

最小长度:0

最大长度:255

system_profile

String

文件系统配置(RAD)

最小长度:0

最大长度:255

metadata_profile

String

元数据配置(RAD)

最小长度:0

最大长度:255

global_reserve1

String

Btrfs文件系统信息

最小长度:0

最大长度:255

g_vol_used_size

Long

Btrfs卷已使用空间大小

最小值:0

最大值:9223372036854775807

default_subvolid

String

默认子卷ID

最小长度:0

最大长度:255

default_subvol_name

String

默认子卷名称

最小长度:0

最大长度:255

default_subvol_mountpath

String

默认子卷挂载路径/BTRFS文件系统的挂载路径

最小长度:0

最大长度:255

subvolumn

Array of BtrfsSubvolumn objects

子卷信息

数组长度:0 - 65535

表6 BtrfsSubvolumn

参数

是否必选

参数类型

描述

uuid

String

父卷的uuid

最小长度:0

最大长度:255

is_snapshot

String

子卷是否为快照

最小长度:0

最大长度:255

subvol_id

String

子卷的ID

最小长度:0

最大长度:255

parent_id

String

父卷ID

最小长度:0

最大长度:255

subvol_name

String

子卷的名称

最小长度:0

最大长度:255

subvol_mount_path

String

子卷的挂载路径

最小长度:0

最大长度:255

表7 TargetDisks

参数

是否必选

参数类型

描述

device_use

String

磁盘类型,普通磁盘,OS所在磁盘,BOOT所在磁盘

BOOT:BOOT设备

OS:系统设备

NORMAL:平常

缺省值:NORMAL

枚举值:

  • NORMAL

  • OS

  • BOOT

disk_id

String

磁盘ID,自动创建虚拟机不用设置

最小长度:0

最大长度:255

name

String

名称,根据磁盘顺序设置为disk X

最小长度:0

最大长度:255

physical_volumes

Array of PhysicalVolumes objects

物理卷信息

数组长度:0 - 65535

size

Long

大小

最小值:0

最大值:9223372036854775807

used_size

Long

使用大小

最小值:0

最大值:9223372036854775807

表8 PhysicalVolumes

参数

是否必选

参数类型

描述

device_use

String

分区类型,普通分区,启动分区,系统分区

最小长度:0

最大长度:255

file_system

String

文件系统类型

最小长度:0

最大长度:255

index

Integer

顺序

最小值:0

最大值:2147483647

mount_point

String

挂载点

最小长度:0

最大长度:255

name

String

名称,windows表示盘符,Linux表示设备号

最小长度:0

最大长度:255

size

Long

大小

最小值:0

最大值:9223372036854775807

inode_size

Long

inode数量

最小值:0

最大值:9223372036854775807

used_size

Long

使用大小

最小值:0

最大值:9223372036854775807

uuid

String

GUID,可从源端查询

最小长度:0

最大长度:255

表9 VolumeGroups

参数

是否必选

参数类型

描述

components

String

Pv信息

最小长度:0

最大长度:255

free_size

Long

剩余空间

最小值:0

最大值:9223372036854775807

logical_volumes

Array of LogicalVolumes objects

lv信息

数组长度:0 - 255

name

String

名称

最小长度:0

最大长度:255

size

Long

大小

最小值:0

最大值:9223372036854775807

表10 LogicalVolumes

参数

是否必选

参数类型

描述

block_count

Integer

块数量

最小值:0

最大值:2147483647

缺省值:0

block_size

Long

块大小

最小值:0

最大值:1048576

缺省值:0

file_system

String

文件系统

最小长度:0

最大长度:255

inode_size

Integer

inode数量

最小值:0

最大值:2147483647

inode_nums

Long

inode节点数量

最小值:0

最大值:9223372036854775807

device_use

String

分区类型,普通分区,启动分区,系统分区

最小长度:0

最大长度:255

mount_point

String

挂载点

最小长度:0

最大长度:256

name

String

名称

最小长度:0

最大长度:1024

size

Long

大小

最小值:0

最大值:9223372036854775807

used_size

Long

使用大小

最小值:0

最大值:9223372036854775807

free_size

Long

剩余空间

最小值:0

最大值:9223372036854775807

响应参数

状态码: 200

表11 响应Body参数

参数

参数类型

描述

id

String

创建成功返回的任务ID

最小长度:0

最大长度:255

状态码: 403

表12 响应Body参数

参数

参数类型

描述

error_code

String

错误代码

最小长度:0

最大长度:255

error_msg

String

错误信息

最小长度:0

最大长度:255

encoded_authorization_message

String

加密授权信息

最小长度:0

最大长度:65535

error_param

Array of strings

错误参数

最小长度:0

最大长度:65535

数组长度:1 - 20

details

Array of details objects

详细错误信息

数组长度:1 - 20

表13 details

参数

参数类型

描述

error_code

String

SMS错误代码

最小长度:0

最大长度:65535

error_msg

String

SMS错误信息

最小长度:0

最大长度:65535

请求示例

创建一个迁移任务,迁移任务名称是MigrationTask,迁移类型是MIGRATE_FILE文件级迁移,源端操作系统类型是LINUX,使用公网迁移是true,迁移region名称是region_name,迁移region的ID是region_id。

POST https://{endpoint}/v3/tasks

{
  "name" : "MigrationTask",
  "type" : "MIGRATE_FILE",
  "os_type" : "LINUX",
  "start_target_server" : true,
  "use_public_ip" : true,
  "migration_ip" : "192.168.0.1",
  "region_name" : "region_name",
  "region_id" : "region_id",
  "project_name" : "project_name",
  "project_id" : "xxxxxxxxxxxxxxxxxxxxxxxx00000001",
  "source_server" : {
    "id" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001"
  },
  "target_server" : {
    "vm_id" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
    "name" : "Auto-tar-name",
    "disks" : [ {
      "name" : "/dev/vda",
      "disk_id" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "size" : 42949672960,
      "used_size" : 429496,
      "device_use" : "BOOT",
      "physical_volumes" : [ {
        "uuid" : null,
        "index" : 0,
        "name" : "/dev/vda1",
        "device_use" : "OS",
        "file_system" : "ext4",
        "mount_point" : "/",
        "size" : 42947575808,
        "used_size" : 5346484224
      } ]
    } ],
    "volume_groups" : [ ]
  },
  "is_need_consistency_result" : true
}

响应示例

状态码: 200

创建迁移任务成功

{
  "id" : "xxxxxxxxxxxxxxxxxxxxxxxx00000001"
}

状态码: 403

鉴权失败

{
  "error_code" : "SMS.9004",
  "error_msg" : "The current account does not have the permission to execute policy You do not have permission to perform action XXX on resource XXX.",
  "encoded_authorization_message" : "XXXXXX",
  "error_param" : [ "You do not have permission to perform action XXX on resource XXX." ],
  "details" : [ {
    "error_code" : "SMS.9004",
    "error_msg" : "You do not have permission to perform action XXX on resource XXX."
  } ]
}

SDK代码示例

SDK代码示例如下。

创建一个迁移任务,迁移任务名称是MigrationTask,迁移类型是MIGRATE_FILE文件级迁移,源端操作系统类型是LINUX,使用公网迁移是true,迁移region名称是region_name,迁移region的ID是region_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.GlobalCredentials;
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.sms.v3.region.SmsRegion;
import com.huaweicloud.sdk.sms.v3.*;
import com.huaweicloud.sdk.sms.v3.model.*;

import java.util.List;
import java.util.ArrayList;

public class CreateTaskSolution {

    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 GlobalCredentials()
                .withAk(ak)
                .withSk(sk);

        SmsClient client = SmsClient.newBuilder()
                .withCredential(auth)
                .withRegion(SmsRegion.valueOf("<YOUR REGION>"))
                .build();
        CreateTaskRequest request = new CreateTaskRequest();
        PostTask body = new PostTask();
        List<PhysicalVolumes> listDisksPhysicalVolumes = new ArrayList<>();
        listDisksPhysicalVolumes.add(
            new PhysicalVolumes()
                .withDeviceUse("OS")
                .withFileSystem("ext4")
                .withIndex(0)
                .withMountPoint("/")
                .withName("/dev/vda1")
                .withSize(42947575808L)
                .withUsedSize(5346484224L)
        );
        List<TargetDisks> listTargetServerDisks = new ArrayList<>();
        listTargetServerDisks.add(
            new TargetDisks()
                .withDeviceUse(TargetDisks.DeviceUseEnum.fromValue("BOOT"))
                .withDiskId("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withName("/dev/vda")
                .withPhysicalVolumes(listDisksPhysicalVolumes)
                .withSize(42949672960L)
                .withUsedSize(429496L)
        );
        TargetServerByTask targetServerbody = new TargetServerByTask();
        targetServerbody.withDisks(listTargetServerDisks)
            .withName("Auto-tar-name")
            .withVmId("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001");
        SourceServerByTask sourceServerbody = new SourceServerByTask();
        sourceServerbody.withId("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001");
        body.withUsePublicIp(true);
        body.withProjectId("xxxxxxxxxxxxxxxxxxxxxxxx00000001");
        body.withProjectName("project_name");
        body.withRegionId("region_id");
        body.withRegionName("region_name");
        body.withMigrationIp("192.168.0.1");
        body.withTargetServer(targetServerbody);
        body.withSourceServer(sourceServerbody);
        body.withOsType("LINUX");
        body.withStartTargetServer(true);
        body.withType(PostTask.TypeEnum.fromValue("MIGRATE_FILE"));
        body.withName("MigrationTask");
        request.withBody(body);
        try {
            CreateTaskResponse response = client.createTask(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());
        }
    }
}

创建一个迁移任务,迁移任务名称是MigrationTask,迁移类型是MIGRATE_FILE文件级迁移,源端操作系统类型是LINUX,使用公网迁移是true,迁移region名称是region_name,迁移region的ID是region_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
69
70
71
72
73
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import GlobalCredentials
from huaweicloudsdksms.v3.region.sms_region import SmsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdksms.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 = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]

    credentials = GlobalCredentials(ak, sk)

    client = SmsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(SmsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = CreateTaskRequest()
        listPhysicalVolumesDisks = [
            PhysicalVolumes(
                device_use="OS",
                file_system="ext4",
                index=0,
                mount_point="/",
                name="/dev/vda1",
                size=42947575808,
                used_size=5346484224
            )
        ]
        listDisksTargetServer = [
            TargetDisks(
                device_use="BOOT",
                disk_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                name="/dev/vda",
                physical_volumes=listPhysicalVolumesDisks,
                size=42949672960,
                used_size=429496
            )
        ]
        targetServerbody = TargetServerByTask(
            disks=listDisksTargetServer,
            name="Auto-tar-name",
            vm_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001"
        )
        sourceServerbody = SourceServerByTask(
            id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001"
        )
        request.body = PostTask(
            use_public_ip=True,
            project_id="xxxxxxxxxxxxxxxxxxxxxxxx00000001",
            project_name="project_name",
            region_id="region_id",
            region_name="region_name",
            migration_ip="192.168.0.1",
            target_server=targetServerbody,
            source_server=sourceServerbody,
            os_type="LINUX",
            start_target_server=True,
            type="MIGRATE_FILE",
            name="MigrationTask"
        )
        response = client.create_task(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

创建一个迁移任务,迁移任务名称是MigrationTask,迁移类型是MIGRATE_FILE文件级迁移,源端操作系统类型是LINUX,使用公网迁移是true,迁移region名称是region_name,迁移region的ID是region_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
    sms "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/sms/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/sms/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/sms/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 := global.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := sms.NewSmsClient(
        sms.SmsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.CreateTaskRequest{}
	deviceUsePhysicalVolumes:= "OS"
	fileSystemPhysicalVolumes:= "ext4"
	indexPhysicalVolumes:= int32(0)
	mountPointPhysicalVolumes:= "/"
	namePhysicalVolumes:= "/dev/vda1"
	sizePhysicalVolumes:= int64(42947575808)
	usedSizePhysicalVolumes:= int64(5346484224)
	var listPhysicalVolumesDisks = []model.PhysicalVolumes{
        {
            DeviceUse: &deviceUsePhysicalVolumes,
            FileSystem: &fileSystemPhysicalVolumes,
            Index: &indexPhysicalVolumes,
            MountPoint: &mountPointPhysicalVolumes,
            Name: &namePhysicalVolumes,
            Size: &sizePhysicalVolumes,
            UsedSize: &usedSizePhysicalVolumes,
        },
    }
	deviceUseDisks:= model.GetTargetDisksDeviceUseEnum().BOOT
	diskIdDisks:= "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001"
	var listDisksTargetServer = []model.TargetDisks{
        {
            DeviceUse: &deviceUseDisks,
            DiskId: &diskIdDisks,
            Name: "/dev/vda",
            PhysicalVolumes: listPhysicalVolumesDisks,
            Size: int64(42949672960),
            UsedSize: int64(429496),
        },
    }
	targetServerbody := &model.TargetServerByTask{
		Disks: listDisksTargetServer,
		Name: "Auto-tar-name",
		VmId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
	}
	sourceServerbody := &model.SourceServerByTask{
		Id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
	}
	usePublicIpPostTask:= true
	migrationIpPostTask:= "192.168.0.1"
	startTargetServerPostTask:= true
	request.Body = &model.PostTask{
		UsePublicIp: &usePublicIpPostTask,
		ProjectId: "xxxxxxxxxxxxxxxxxxxxxxxx00000001",
		ProjectName: "project_name",
		RegionId: "region_id",
		RegionName: "region_name",
		MigrationIp: &migrationIpPostTask,
		TargetServer: targetServerbody,
		SourceServer: sourceServerbody,
		OsType: "LINUX",
		StartTargetServer: &startTargetServerPostTask,
		Type: model.GetPostTaskTypeEnum().MIGRATE_FILE,
		Name: "MigrationTask",
	}
	response, err := client.CreateTask(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

创建一个迁移任务,迁移任务名称是MigrationTask,迁移类型是MIGRATE_FILE文件级迁移,源端操作系统类型是LINUX,使用公网迁移是true,迁移region名称是region_name,迁移region的ID是region_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.GlobalCredentials;
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.sms.v3.region.SmsRegion;
import com.huaweicloud.sdk.sms.v3.*;
import com.huaweicloud.sdk.sms.v3.model.*;

import java.util.List;
import java.util.ArrayList;

public class CreateTaskSolution {

    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 GlobalCredentials()
                .withAk(ak)
                .withSk(sk);

        SmsClient client = SmsClient.newBuilder()
                .withCredential(auth)
                .withRegion(SmsRegion.valueOf("<YOUR REGION>"))
                .build();
        CreateTaskRequest request = new CreateTaskRequest();
        PostTask body = new PostTask();
        List<PhysicalVolumes> listDisksPhysicalVolumes = new ArrayList<>();
        listDisksPhysicalVolumes.add(
            new PhysicalVolumes()
                .withDeviceUse("OS")
                .withFileSystem("ext4")
                .withIndex(0)
                .withMountPoint("/")
                .withName("/dev/vda1")
                .withSize(42947575808L)
                .withUsedSize(5346484224L)
        );
        List<TargetDisks> listTargetServerDisks = new ArrayList<>();
        listTargetServerDisks.add(
            new TargetDisks()
                .withDeviceUse(TargetDisks.DeviceUseEnum.fromValue("BOOT"))
                .withDiskId("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withName("/dev/vda")
                .withPhysicalVolumes(listDisksPhysicalVolumes)
                .withSize(42949672960L)
                .withUsedSize(429496L)
        );
        TargetServerByTask targetServerbody = new TargetServerByTask();
        targetServerbody.withDisks(listTargetServerDisks)
            .withName("Auto-tar-name")
            .withVmId("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001");
        SourceServerByTask sourceServerbody = new SourceServerByTask();
        sourceServerbody.withId("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001");
        body.withUsePublicIp(true);
        body.withProjectId("xxxxxxxxxxxxxxxxxxxxxxxx00000001");
        body.withProjectName("project_name");
        body.withRegionId("region_id");
        body.withRegionName("region_name");
        body.withMigrationIp("192.168.0.1");
        body.withTargetServer(targetServerbody);
        body.withSourceServer(sourceServerbody);
        body.withOsType("LINUX");
        body.withStartTargetServer(true);
        body.withType(PostTask.TypeEnum.fromValue("MIGRATE_FILE"));
        body.withName("MigrationTask");
        request.withBody(body);
        try {
            CreateTaskResponse response = client.createTask(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());
        }
    }
}

创建一个迁移任务,迁移任务名称是MigrationTask,迁移类型是MIGRATE_FILE文件级迁移,源端操作系统类型是LINUX,使用公网迁移是true,迁移region名称是region_name,迁移region的ID是region_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
69
70
71
72
73
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import GlobalCredentials
from huaweicloudsdksms.v3.region.sms_region import SmsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdksms.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 = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]

    credentials = GlobalCredentials(ak, sk)

    client = SmsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(SmsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = CreateTaskRequest()
        listPhysicalVolumesDisks = [
            PhysicalVolumes(
                device_use="OS",
                file_system="ext4",
                index=0,
                mount_point="/",
                name="/dev/vda1",
                size=42947575808,
                used_size=5346484224
            )
        ]
        listDisksTargetServer = [
            TargetDisks(
                device_use="BOOT",
                disk_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                name="/dev/vda",
                physical_volumes=listPhysicalVolumesDisks,
                size=42949672960,
                used_size=429496
            )
        ]
        targetServerbody = TargetServerByTask(
            disks=listDisksTargetServer,
            name="Auto-tar-name",
            vm_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001"
        )
        sourceServerbody = SourceServerByTask(
            id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001"
        )
        request.body = PostTask(
            use_public_ip=True,
            project_id="xxxxxxxxxxxxxxxxxxxxxxxx00000001",
            project_name="project_name",
            region_id="region_id",
            region_name="region_name",
            migration_ip="192.168.0.1",
            target_server=targetServerbody,
            source_server=sourceServerbody,
            os_type="LINUX",
            start_target_server=True,
            type="MIGRATE_FILE",
            name="MigrationTask"
        )
        response = client.create_task(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

创建一个迁移任务,迁移任务名称是MigrationTask,迁移类型是MIGRATE_FILE文件级迁移,源端操作系统类型是LINUX,使用公网迁移是true,迁移region名称是region_name,迁移region的ID是region_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
    sms "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/sms/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/sms/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/sms/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 := global.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := sms.NewSmsClient(
        sms.SmsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.CreateTaskRequest{}
	deviceUsePhysicalVolumes:= "OS"
	fileSystemPhysicalVolumes:= "ext4"
	indexPhysicalVolumes:= int32(0)
	mountPointPhysicalVolumes:= "/"
	namePhysicalVolumes:= "/dev/vda1"
	sizePhysicalVolumes:= int64(42947575808)
	usedSizePhysicalVolumes:= int64(5346484224)
	var listPhysicalVolumesDisks = []model.PhysicalVolumes{
        {
            DeviceUse: &deviceUsePhysicalVolumes,
            FileSystem: &fileSystemPhysicalVolumes,
            Index: &indexPhysicalVolumes,
            MountPoint: &mountPointPhysicalVolumes,
            Name: &namePhysicalVolumes,
            Size: &sizePhysicalVolumes,
            UsedSize: &usedSizePhysicalVolumes,
        },
    }
	deviceUseDisks:= model.GetTargetDisksDeviceUseEnum().BOOT
	diskIdDisks:= "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001"
	var listDisksTargetServer = []model.TargetDisks{
        {
            DeviceUse: &deviceUseDisks,
            DiskId: &diskIdDisks,
            Name: "/dev/vda",
            PhysicalVolumes: listPhysicalVolumesDisks,
            Size: int64(42949672960),
            UsedSize: int64(429496),
        },
    }
	targetServerbody := &model.TargetServerByTask{
		Disks: listDisksTargetServer,
		Name: "Auto-tar-name",
		VmId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
	}
	sourceServerbody := &model.SourceServerByTask{
		Id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
	}
	usePublicIpPostTask:= true
	migrationIpPostTask:= "192.168.0.1"
	startTargetServerPostTask:= true
	request.Body = &model.PostTask{
		UsePublicIp: &usePublicIpPostTask,
		ProjectId: "xxxxxxxxxxxxxxxxxxxxxxxx00000001",
		ProjectName: "project_name",
		RegionId: "region_id",
		RegionName: "region_name",
		MigrationIp: &migrationIpPostTask,
		TargetServer: targetServerbody,
		SourceServer: sourceServerbody,
		OsType: "LINUX",
		StartTargetServer: &startTargetServerPostTask,
		Type: model.GetPostTaskTypeEnum().MIGRATE_FILE,
		Name: "MigrationTask",
	}
	response, err := client.CreateTask(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

创建迁移任务成功

403

鉴权失败

错误码

请参见错误码

我们使用cookie来确保您的高速浏览体验。继续浏览本站,即表示您同意我们使用cookie。 详情

文档反馈

文档反馈

意见反馈

0/500

标记内容

同时提交标记内容