Updated on 2024-07-08 GMT+08:00

Creating a Migration Task

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. It can be obtained by calling the IAM API (value of X-Subject-Token in the response header).

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.

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

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

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

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.

Table 3 SourceServerByTask field description

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 characters

disks

Yes

Array of TargetDisks objects

The disk information.

Array length: 0 to 65,535 characters

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 characters

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

The UUID.

Yes

String

The UUID of the file system.

Minimum length: 0 characters

Maximum length: 255 characters

device

Yes

String

The device name in the Btrfs.

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 characters

Table 6 BtrfsSubvolumn field description

Parameter

Mandatory

Type

Description

The UUID.

Yes

String

The UUID of the parent volume.

Minimum length: 0 characters

Maximum length: 255 characters

is_snapshot

Yes

String

Specifies 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.

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 characters

size

Yes

Long

The volume 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 type. The value can be NORMAL, BOOT, or OS.

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 volume 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

The 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 characters

name

No

String

The name.

Minimum length: 0 characters

Maximum length: 255 characters

size

No

Long

The volume 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: 4294967296

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: 4294967296

device_use

No

String

The partition type. The value can be NORMAL, BOOT, or OS.

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 volume 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

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" : "b276e6fb38c74aa2ba4598f049745ce9",
  "source_server" : {
    "id" : "16c03428-ff9a-4f36-84aa-583e41499bb2"
  },
  "target_server" : {
    "vm_id" : "1900aab8-90c4-462c-b4c5-acdafc8fbeca",
    "name" : "Auto-tar-name",
    "disks" : [ {
      "name" : "/dev/vda",
      "disk_id" : "76a59f9f-5901-4913-a9a5-f6742baa308c",
      "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" : [ ]
  }
}

Example Response

Status code: 200

OK

{
  "id" : "8abda8635e09d185015e09d188dd0001xx"
}

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("76a59f9f-5901-4913-a9a5-f6742baa308c")
                .withName("/dev/vda")
                .withPhysicalVolumes(listDisksPhysicalVolumes)
                .withSize(42949672960L)
                .withUsedSize(429496L)
        );
        TargetServerByTask targetServerbody = new TargetServerByTask();
        targetServerbody.withDisks(listTargetServerDisks)
            .withName("Auto-tar-name")
            .withVmId("1900aab8-90c4-462c-b4c5-acdafc8fbeca");
        SourceServerByTask sourceServerbody = new SourceServerByTask();
        sourceServerbody.withId("16c03428-ff9a-4f36-84aa-583e41499bb2");
        body.withUsePublicIp(true);
        body.withProjectId("b276e6fb38c74aa2ba4598f049745ce9");
        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="76a59f9f-5901-4913-a9a5-f6742baa308c",
                name="/dev/vda",
                physical_volumes=listPhysicalVolumesDisks,
                size=42949672960,
                used_size=429496
            )
        ]
        targetServerbody = TargetServerByTask(
            disks=listDisksTargetServer,
            name="Auto-tar-name",
            vm_id="1900aab8-90c4-462c-b4c5-acdafc8fbeca"
        )
        sourceServerbody = SourceServerByTask(
            id="16c03428-ff9a-4f36-84aa-583e41499bb2"
        )
        request.body = PostTask(
            use_public_ip=True,
            project_id="b276e6fb38c74aa2ba4598f049745ce9",
            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:= "76a59f9f-5901-4913-a9a5-f6742baa308c"
	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: "1900aab8-90c4-462c-b4c5-acdafc8fbeca",
	}
	sourceServerbody := &model.SourceServerByTask{
		Id: "16c03428-ff9a-4f36-84aa-583e41499bb2",
	}
	usePublicIpPostTask:= true
	migrationIpPostTask:= "192.168.0.1"
	startTargetServerPostTask:= true
	request.Body = &model.PostTask{
		UsePublicIp: &usePublicIpPostTask,
		ProjectId: "b276e6fb38c74aa2ba4598f049745ce9",
		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

Response returned.

Error Codes

For details, see Error Codes.