Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Creating a Migration Task

Updated on 2025-01-24 GMT+08:00

Function

This API is used to create a migration task based on a source server.

Calling Method

For details, see Calling APIs.

URI

POST /v3/tasks

Request

Table 1 Request header parameter

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

The user token. The token can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token.

Minimum length: 1 character

Maximum length: 16,384 characters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

name

Yes

String

The task name.

Minimum length: 0 characters

Maximum length: 255 characters

type

Yes

String

The task type.

MIGRATE_FILE: file-level migration

MIGRATE_BLOCK: block-level migration

The value can be:

  • MIGRATE_FILE

  • MIGRATE_BLOCK

start_target_server

No

Boolean

Whether to start the target server after the migration is complete.

Default value: true

auto_start

No

Boolean

Whether to automatically start the migration.

os_type

Yes

String

The OS type.

Minimum length: 0 characters

Maximum length: 255 characters

source_server

Yes

SourceServerByTask object

The source server information.

target_server

Yes

TargetServerByTask object

The target server information.

migration_ip

No

String

The IP address used for migration. This parameter is not required if the target server is automatically created.

Minimum length: 0 characters

Maximum length: 255 characters

region_name

Yes

String

The region name.

Minimum length: 0 characters

Maximum length: 255 characters

region_id

Yes

String

The region ID.

Minimum length: 0 characters

Maximum length: 255 characters

project_name

Yes

String

The project name.

Minimum length: 0 characters

Maximum length: 255 characters

project_id

Yes

String

The project ID.

Minimum length: 0 characters

Maximum length: 255 characters

priority

No

Integer

The migration priority. The default value is 1.

Minimum value: 0

Maximum value: 65535

vm_template_id

No

String

The ID of the template used to create the target server automatically.

Minimum length: 0 characters

Maximum length: 255 characters

use_public_ip

No

Boolean

Specifies whether to use a public IP address for migration.

Default value: true

use_ipv6

No

Boolean

Whether IPv6 is used.

syncing

No

Boolean

Specifies whether to perform a continuous synchronization after the first replication. If this parameter is not specified, the default value false is used.

Default value: false

exist_server

No

Boolean

Checks whether the service exists. If it does, create the task.

start_network_check

No

Boolean

Whether to measure the network performance.

speed_limit

No

Integer

The migration speed limit.

Minimum value: 0

Maximum value: 10000

over_speed_threshold

No

Double

The overspeed threshold for stopping migration. This is a protection measure. If the migration speed exceeds the threshold, the task is stopped. It is used to control the consumption of resources (especially network bandwidth) during the migration to ensure that the overall system performance is not affected by a single migration task. The unit is percentage.

Minimum value: 0

Maximum value: 100

is_need_consistency_check

No

Boolean

Whether consistency verification is enabled.

Table 3 SourceServerByTask

Parameter

Mandatory

Type

Description

id

Yes

String

The source server ID.

Minimum length: 0 characters

Maximum length: 255 characters

Table 4 TargetServerByTask field description

Parameter

Mandatory

Type

Description

btrfs_list

No

Array of BtrfsFileSystem objects

The Btrfs information, which is obtained from the source server.

Array length: 0 to 65,535

disks

Yes

Array of TargetDisks objects

The disk information.

Array length: 0 to 65,535

name

Yes

String

The name.

Minimum length: 0 characters

Maximum length: 255 characters

vm_id

Yes

String

The target server ID.

Minimum length: 0 characters

Maximum length: 255 characters

volume_groups

No

Array of VolumeGroups objects

The volume group information, which is obtained from the source server.

Array length: 0 to 65,535

Table 5 BtrfsFileSystem field description

Parameter

Mandatory

Type

Description

name

Yes

String

The file system name.

Minimum length: 0 characters

Maximum length: 255 characters

label

Yes

String

The file system tag. If no tag exists, the value is an empty string.

Minimum length: 0 characters

Maximum length: 255 characters

uuid

Yes

String

The UUID of the file system.

Minimum length: 0 characters

Maximum length: 255 characters

device

Yes

String

The names of Btrfs devices.

Minimum length: 0 characters

Maximum length: 255 characters

size

Yes

Long

The space occupied by the file system.

Minimum value: 0

Maximum value: 9223372036854775807

nodesize

Yes

Long

The size of the Btrfs node.

Minimum value: 0

Maximum value: 9223372036854775807

sectorsize

Yes

Integer

The sector size.

Minimum value: 0

Maximum value: 2147483647

data_profile

Yes

String

The data profile (RAD).

Minimum length: 0 characters

Maximum length: 255 characters

system_profile

Yes

String

The file system profile (RAD).

Minimum length: 0 characters

Maximum length: 255 characters

metadata_profile

Yes

String

The metadata profile (RAD).

Minimum length: 0 characters

Maximum length: 255 characters

global_reserve1

Yes

String

The Btrfs file system information.

Minimum length: 0 characters

Maximum length: 255 characters

g_vol_used_size

Yes

Long

The used space of the Btrfs volume.

Minimum value: 0

Maximum value: 9223372036854775807

default_subvolid

Yes

String

The ID of the default subvolume.

Minimum length: 0 characters

Maximum length: 255 characters

default_subvol_name

Yes

String

The name of the default subvolume.

Minimum length: 0 characters

Maximum length: 255 characters

default_subvol_mountpath

Yes

String

The mount path of the default subvolume or Btrfs file system.

Minimum length: 0 characters

Maximum length: 255 characters

subvolume

Yes

Array of BtrfsSubvolumn objects

The subvolume information.

Array length: 0 to 65,535

Table 6 BtrfsSubvolumn field description

Parameter

Mandatory

Type

Description

uuid

Yes

String

The UUID of the parent volume.

Minimum length: 0 characters

Maximum length: 255 characters

is_snapshot

Yes

String

Indicates whether the subvolume is a snapshot.

Minimum length: 0 characters

Maximum length: 255 characters

subvol_id

Yes

String

The subvolume ID.

Minimum length: 0 characters

Maximum length: 255 characters

parent_id

Yes

String

The parent volume ID.

Minimum length: 0 characters

Maximum length: 255 characters

subvol_name

Yes

String

The subvolume name.

Minimum length: 0 characters

Maximum length: 255 characters

subvol_mount_path

Yes

String

The mount path of the subvolume.

Minimum length: 0 characters

Maximum length: 255 characters

Table 7 TargetDisks field description

Parameter

Mandatory

Type

Description

device_use

No

String

The disk function. The disk can be a general, OS, or boot disk.

BOOT: boot device

OS: system device

NORMAL: general device

Default value: NORMAL

The value can be:

  • NORMAL

  • OS

  • BOOT

disk_id

No

String

The disk ID. This parameter is not required if the target server is automatically created.

Minimum length: 0 characters

Maximum length: 255 characters

name

Yes

String

The disk name. Set this parameter to Disk X based on the disk sequence.

Minimum length: 0 characters

Maximum length: 255 characters

physical_volumes

Yes

Array of PhysicalVolumes objects

The physical volume information.

Array length: 0 to 65,535

size

Yes

Long

The size.

Minimum value: 0

Maximum value: 9223372036854775807

used_size

Yes

Long

The used space.

Minimum value: 0

Maximum value: 9223372036854775807

Table 8 PhysicalVolumes field description

Parameter

Mandatory

Type

Description

device_use

No

String

The partition function. The partition can be a general, boot or OS partition.

Minimum length: 0 characters

Maximum length: 255 characters

file_system

No

String

The file system type.

Minimum length: 0 characters

Maximum length: 255 characters

index

No

Integer

The serial number of the volume.

Minimum value: 0

Maximum value: 2147483647

mount_point

No

String

The mount point.

Minimum length: 0 characters

Maximum length: 255 characters

name

No

String

The volume name. In Windows, it indicates the drive letter, and in Linux, it indicates the device ID.

Minimum length: 0 characters

Maximum length: 255 characters

size

No

Long

The size.

Minimum value: 0

Maximum value: 9223372036854775807

inode_size

No

Long

The number of inodes.

Minimum value: 0

Maximum value: 9223372036854775807

used_size

No

Long

The used space.

Minimum value: 0

Maximum value: 9223372036854775807

uuid

No

String

The GUID of the volume, which can be obtained from the source server.

Minimum length: 0 characters

Maximum length: 255 characters

Table 9 VolumeGroups field description

Parameter

Mandatory

Type

Description

components

No

String

The physical volume information.

Minimum length: 0 characters

Maximum length: 255 characters

free_size

No

Long

The available space.

Minimum value: 0

Maximum value: 9223372036854775807

logical_volumes

No

Array of LogicalVolumes objects

The logical volume information.

Array length: 0 to 255

name

No

String

The name.

Minimum length: 0 characters

Maximum length: 255 characters

size

No

Long

The size.

Minimum value: 0

Maximum value: 9223372036854775807

Table 10 LogicalVolumes field description

Parameter

Mandatory

Type

Description

block_count

No

Integer

The number of blocks.

Minimum value: 0

Maximum value: 2147483647

Default value: 0

block_size

No

Long

The block size.

Minimum value: 0

Maximum value: 1048576

Default value: 0

file_system

Yes

String

The file system.

Minimum length: 0 characters

Maximum length: 255 characters

inode_size

Yes

Integer

The number of inodes.

Minimum value: 0

Maximum value: 2147483647

inode_nums

No

Long

The number of inodes.

Minimum value: 0

Maximum value: 9223372036854775807

device_use

No

String

The partition function. The partition can be a general, boot or OS partition.

Minimum length: 0 characters

Maximum length: 255 characters

mount_point

Yes

String

The mount point.

Minimum length: 0 characters

Maximum length: 256 characters

name

Yes

String

The name.

Minimum length: 0 characters

Maximum length: 1,024 characters

size

Yes

Long

The size.

Minimum value: 0

Maximum value: 9223372036854775807

used_size

Yes

Long

The used space.

Minimum value: 0

Maximum value: 9223372036854775807

free_size

Yes

Long

The available space.

Minimum value: 0

Maximum value: 9223372036854775807

Response

Status code: 200

Table 11 Response body parameters

Parameter

Type

Description

id

String

The task ID returned when the task is created successfully.

Minimum length: 0 characters

Maximum length: 255 characters

Status code: 403

Table 12 Response body parameters

Parameter

Type

Description

error_code

String

The error code.

Minimum length: 0 characters

Maximum length: 255 characters

error_msg

String

The error message.

Minimum length: 0 characters

Maximum length: 255 characters

encoded_authorization_message

String

Encrypted authorization information.

Minimum length: 0 characters

Maximum length: 65,535 characters

error_param

Array of strings

Invalid parameter.

Minimum length: 0 characters

Maximum length: 65,535 characters

Array length: 1 to 20

details

Array of details objects

The error message.

Array length: 1 to 20

Table 13 details field description

Parameter

Type

Description

error_code

String

The SMS error code.

Minimum length: 0 characters

Maximum length: 65,535 characters

error_msg

String

The SMS error message.

Minimum length: 0 characters

Maximum length: 65,535 characters

Example Request

This example creates a migration task whose name is MigrationTask. The migration type is MIGRATE_FILE, the source server runs Linux, the migration uses the public network, the migration region name is region_name, and the migration region ID is 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
}

Example Response

Status code: 200

The migration task was successfully created.

{
  "id" : "xxxxxxxxxxxxxxxxxxxxxxxx00000001"
}

Status code: 403

Authentication failed.

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

The sample code is as follows.

This example creates a migration task whose name is MigrationTask. The migration type is MIGRATE_FILE, the source server runs Linux, the migration uses the public network, the migration region name is region_name, and the migration region ID is 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());
        }
    }
}

This example creates a migration task whose name is MigrationTask. The migration type is MIGRATE_FILE, the source server runs Linux, the migration uses the public network, the migration region name is region_name, and the migration region ID is 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)

This example creates a migration task whose name is MigrationTask. The migration type is MIGRATE_FILE, the source server runs Linux, the migration uses the public network, the migration region name is region_name, and the migration region ID is 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)
    }
}

For more SDK sample code of programming languages, visit API Explorer and click the Sample Code tab. Example code can be automatically generated.

This example creates a migration task whose name is MigrationTask. The migration type is MIGRATE_FILE, the source server runs Linux, the migration uses the public network, the migration region name is region_name, and the migration region ID is 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());
        }
    }
}

This example creates a migration task whose name is MigrationTask. The migration type is MIGRATE_FILE, the source server runs Linux, the migration uses the public network, the migration region name is region_name, and the migration region ID is 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)

This example creates a migration task whose name is MigrationTask. The migration type is MIGRATE_FILE, the source server runs Linux, the migration uses the public network, the migration region name is region_name, and the migration region ID is 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)
    }
}

For more SDK sample code of programming languages, visit API Explorer and click the Sample Code tab. Example code can be automatically generated.

Status Codes

Status Code

Description

200

The migration task was successfully created.

403

Authentication failed.

Error Codes

For details, see Error Codes.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback