github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/dcs/v1/migration/CreateMigrationTask.go (about) 1 package migration 2 3 import ( 4 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/internal/build" 6 "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" 7 ) 8 9 type CreateMigrationTaskOpts struct { 10 // Name of the migration task. 11 TaskName string `json:"task_name" required:"true"` 12 // Description of the migration task. 13 Description string `json:"description,omitempty"` 14 // Mode of the migration. 15 // Options: 16 // backupfile_import: indicates importing backup files. 17 // online_migration: indicates migrating data online. 18 MigrationType string `json:"migration_type" required:"true"` 19 // Type of the migration. 20 // Options: 21 // full_amount_migration: indicates a full migration. 22 // incremental_migration: indicates an incremental migration. 23 MigrationMethod string `json:"migration_method" required:"true"` 24 // Backup files to be imported when the migration mode is importing backup files. 25 BackupFiles BackupFilesBody `json:"backup_files,omitempty"` 26 // Type of the network for communication between the source and 27 // destination Redis when the migration mode is online data migration. 28 // Options: 29 // vpc 30 // vpn 31 NetworkType string `json:"network_type,omitempty"` 32 // Source Redis information. This parameter is mandatory when the migration mode is online data migration. 33 SourceInstance SourceInstanceBody `json:"source_instance,omitempty"` 34 // Destination Redis instance information. 35 TargetInstance TargetInstanceBody `json:"target_instance" required:"true"` 36 } 37 38 type BackupFilesBody struct { 39 // Data source. Currently, only OBS buckets are supported. The value is self_build_obs. 40 FileSource string `json:"file_source,omitempty"` 41 // OBS bucket name. 42 BucketName string `json:"bucket_name" required:"true"` 43 // List of backup files to be imported. 44 Files []Files `json:"files" required:"true"` 45 } 46 47 type Files struct { 48 // Name of a backup file. 49 FileName string `json:"file_name" required:"true"` 50 // File size in bytes. 51 Size string `json:"size,omitempty"` 52 // Time when the file is last modified. The format is YYYY-MM-DD HH:MM:SS. 53 UpdateAt string `json:"update_at,omitempty"` 54 } 55 56 type SourceInstanceBody struct { 57 // Source Redis name (specified in the source_instance parameter). 58 Addrs string `json:"addrs" required:"true"` 59 // Redis password. If a password is set, this parameter is mandatory. 60 Password string `json:"password,omitempty"` 61 } 62 63 type TargetInstanceBody struct { 64 // Destination Redis instance ID (mandatory in the target_instance parameter). 65 Id string `json:"id" required:"true"` 66 // Destination Redis instance name (specified in the target_instance parameter). 67 Name string `json:"name,omitempty"` 68 // Redis password. If a password is set, this parameter is mandatory. 69 Password string `json:"password,omitempty"` 70 } 71 72 func CreateMigrationTask(client *golangsdk.ServiceClient, opts CreateMigrationTaskOpts) (*CreateMigrationTaskResponse, error) { 73 b, err := build.RequestBody(opts, "") 74 if err != nil { 75 return nil, err 76 } 77 78 // POST /v2/{project_id}/migration-task 79 raw, err := client.Post(client.ServiceURL("migration-task"), b, nil, &golangsdk.RequestOpts{ 80 OkCodes: []int{200}, 81 }) 82 if err != nil { 83 return nil, err 84 } 85 86 var res CreateMigrationTaskResponse 87 err = extract.Into(raw.Body, &res) 88 return &res, err 89 } 90 91 type CreateMigrationTaskResponse struct { 92 // ID of the migration task. 93 Id string `json:"id"` 94 // Name of the migration task. 95 Name string `json:"name"` 96 // Migration task status. The value can be: 97 // SUCCESS: Migration succeeded. 98 // FAILED: Migration failed. 99 // MIGRATING: Migration is in progress. 100 // TERMINATED: Migration has been stopped. 101 // TERMINATING: Migration is being stopped. 102 // RUNNING: The migration task has been created and is waiting to be executed. 103 // CREATING: The migration task is being created. 104 // FULLMIGRATING: Full migration is in progress. 105 // INCRMIGEATING: Incremental migration is in progress. 106 // ERROR: faulty 107 // DELETED: faulty 108 // RELEASED: automatically released 109 // MIGRATION_SUCCESS: The migration is successful, and resources are to be cleared. 110 // MIGRATION_FAILED: The migration failed, and resources are to be cleared. 111 Status string `json:"status"` 112 }