github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/sms/v3/tasks/requests.go (about)

     1  package tasks
     2  
     3  import "github.com/chnsz/golangsdk"
     4  
     5  // CreateOpts 创建任务的参数
     6  type CreateOpts struct {
     7  	// 任务名称
     8  	Name string `json:"name" required:"true"`
     9  	// 任务类型: MIGRATE_FILE, MIGRATE_BLOCK
    10  	Type string `json:"type" required:"true"`
    11  	// 操作系统类型: WINDOWS, LINUX
    12  	OsType string `json:"os_type" required:"true"`
    13  	// region的名称
    14  	Region string `json:"region_name" required:"true"`
    15  	// region id
    16  	RegionID string `json:"region_id" required:"true"`
    17  	// 项目名称
    18  	Project string `json:"project_name" required:"true"`
    19  	// 项目id
    20  	ProjectID string `json:"project_id" required:"true"`
    21  	// 源端服务器信息
    22  	SourceServer SourceServerRequest `json:"source_server" required:"true"`
    23  	// 目的端虚拟机信息
    24  	TargetServer TargetServerRequest `json:"target_server" required:"true"`
    25  	// 进程优先级, 0:低, 1:标准, 2:高
    26  	Priority int `json:"priority,omitempty"`
    27  	// 迁移ip,如果是自动创建虚拟机,不需要此参数
    28  	MigrationIp string `json:"migration_ip,omitempty"`
    29  	// 自动创建虚拟机使用模板
    30  	VmTemplateId string `json:"vm_template_id,omitempty"`
    31  	// 是否使用已有虚拟机
    32  	ExistServer *bool `json:"exist_server,omitempty"`
    33  	// 迁移后是否启动目的端虚拟机
    34  	StartServer *bool `json:"start_target_server,omitempty"`
    35  	// 是否使用公网ip
    36  	UsePublicIp *bool `json:"use_public_ip,omitempty"`
    37  	// 复制或者同步后是否会继续持续同步,不添加则默认是false
    38  	Syncing *bool `json:"syncing,omitempty"`
    39  }
    40  
    41  // SourceServerRequest 源端服务器信息
    42  type SourceServerRequest struct {
    43  	// 源端服务器id
    44  	Id string `json:"id" required:"true"`
    45  }
    46  
    47  // TargetServerRequest 目的端虚拟机信息
    48  type TargetServerRequest struct {
    49  	// 虚拟机名称
    50  	Name string `json:"name,omitempty"`
    51  	// 虚拟机id, 如果是自动创建虚拟机,不需要此参数
    52  	VMID string `json:"vm_id,omitempty"`
    53  	// 磁盘信息
    54  	Disks []DiskRequest `json:"disks,omitempty"`
    55  	// 卷组,数据从源端获取
    56  	VolumeGroups []VGRequest `json:"volume_groups,omitempty"`
    57  	// btrfs信息,数据从源端获取
    58  	Btrfs []BtrfsFileSystem `json:"btrfs_list,omitempty"`
    59  }
    60  
    61  // DiskRequest 目的端磁盘信息
    62  type DiskRequest struct {
    63  	// 名称,根据磁盘顺序设置为disk X
    64  	Name string `json:"name" required:"true"`
    65  	// 大小
    66  	Size int64 `json:"size" required:"true"`
    67  	// 磁盘类型,普通磁盘,OS所在磁盘,BOOT所在磁盘
    68  	DeviceType string `json:"device_use,omitempty"`
    69  	// 磁盘id,自动创建虚拟机不用设置
    70  	DiskId string `json:"disk_id,omitempty"`
    71  	// 物理卷信息
    72  	PhysicalVolumes []PVRequest `json:"physical_volumes,omitempty"`
    73  	// 使用大小
    74  	UsedSize int64 `json:"used_size,omitempty"`
    75  }
    76  
    77  // PVRequest 使用大小
    78  type PVRequest struct {
    79  	// 分区类型,普通分区,启动分区,系统分区
    80  	DeviceType string `json:"device_use,omitempty"`
    81  	// 文件系统类型
    82  	FileSystem string `json:"file_system,omitempty"`
    83  	// 顺序
    84  	Index *int `json:"index,omitempty"`
    85  	// 挂载点
    86  	MountPoint string `json:"mount_point,omitempty"`
    87  	// 名称,windows表示盘符,Linux表示设备号
    88  	Name string `json:"name,omitempty"`
    89  	// 大小
    90  	Size int64 `json:"size,omitempty"`
    91  	// 使用大小
    92  	UsedSize int64 `json:"used_size,omitempty"`
    93  	// GUID,可从源端查询
    94  	UUID string `json:"uuid,omitempty"`
    95  }
    96  
    97  // VGRequest 逻辑卷组信息
    98  type VGRequest struct {
    99  	// 名称
   100  	Name string `json:"name" required:"true"`
   101  	// 大小
   102  	Size int64 `json:"size,omitempty"`
   103  	// Pv信息
   104  	Components string `json:"components,omitempty"`
   105  	// 剩余空间
   106  	FreeSize int64 `json:"free_size,omitempty"`
   107  	// lv信息
   108  	LogicalVolumes []LVRequest `json:"logical_volumes,omitempty"`
   109  }
   110  
   111  // LVRequest 逻辑卷信息
   112  type LVRequest struct {
   113  	// 名称
   114  	Name string `json:"name" required:"true"`
   115  	// 大小
   116  	Size int64 `json:"size" required:"true"`
   117  	// 块数量
   118  	BlockCount int `json:"block_count,omitempty"`
   119  	// 块大小
   120  	BlockSize int `json:"block_size,omitempty"`
   121  	// 文件系统
   122  	FileSystem string `json:"file_system"`
   123  	// 挂载点
   124  	MountPoint string `json:"mount_point"`
   125  	// inode数量
   126  	InodeSize int `json:"inode_size,omitempty"`
   127  	// 使用大小
   128  	UsedSize int64 `json:"used_size,omitempty"`
   129  	// 剩余空间
   130  	FreeSize int `json:"free_size,omitempty"`
   131  }
   132  
   133  // Create 创建迁移任务
   134  func Create(c *golangsdk.ServiceClient, opts *CreateOpts) (string, error) {
   135  	b, err := golangsdk.BuildRequestBody(opts, "")
   136  	if err != nil {
   137  		return "", err
   138  	}
   139  
   140  	var rst golangsdk.Result
   141  	_, rst.Err = c.Post(rootURL(c), b, &rst.Body, nil)
   142  
   143  	var r CreateResp
   144  	if err := rst.ExtractInto(&r); err != nil {
   145  		return "", err
   146  	}
   147  
   148  	return r.ID, nil
   149  }
   150  
   151  // ActionOpts is an object to manage migration tasks
   152  type ActionOpts struct {
   153  	// Operation specifies the operation to be performed on the task. The value can be:
   154  	// start, stop, collect_log, test, clone_test, restart, sync_failed_rollback
   155  	Operation string `json:"operation" required:"true"`
   156  	// Param specifies the operation parameters
   157  	Param map[string]string `json:"param,omitempty"`
   158  }
   159  
   160  // Action is the method to manage migration tasks
   161  func Action(c *golangsdk.ServiceClient, id string, opts ActionOpts) error {
   162  	b, err := golangsdk.BuildRequestBody(opts, "")
   163  	if err != nil {
   164  		return err
   165  	}
   166  
   167  	_, err = c.Post(actionURL(c, id), b, nil, nil)
   168  	return err
   169  }
   170  
   171  // Get 查询指定ID模板信息
   172  func Get(c *golangsdk.ServiceClient, id string) (*MigrateTask, error) {
   173  	var rst golangsdk.Result
   174  	_, rst.Err = c.Get(taskURL(c, id), &rst.Body, nil)
   175  
   176  	var r MigrateTask
   177  	err := rst.ExtractInto(&r)
   178  	if err != nil {
   179  		return nil, err
   180  	}
   181  
   182  	return &r, nil
   183  }
   184  
   185  // Delete 删除指定ID的迁移任务
   186  func Delete(c *golangsdk.ServiceClient, id string) *golangsdk.ErrResult {
   187  	var r golangsdk.ErrResult
   188  	_, r.Err = c.Delete(taskURL(c, id), nil)
   189  	return &r
   190  }