github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/csbs/v1/resource/CreateRestorationTask.go (about) 1 package resource 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 RestoreOpts struct { 10 // Backup provider ID, which specifies whether the backup object is a server or disk. 11 // This parameter has a fixed value. For CSBS, the value is fc4d5750-22e7-4798-8a46-f48f62c4c1da. 12 ProviderId string `json:"provider_id"` 13 // Backup record ID 14 CheckpointId string `json:"checkpoint_id"` 15 // Restoration target 16 RestoreTarget string `json:"restore_target,omitempty"` 17 // Restoration parameters 18 Parameters RestoreParam `json:"parameters"` 19 } 20 21 type RestoreParam struct { 22 // Backup ID 23 CheckpointItemId string `json:"checkpoint_item_id"` 24 // Whether to instantly power on the VM after restoration 25 PowerOn bool `json:"power_on"` 26 // Restoration target 27 Targets RestoreTarget `json:"targets"` 28 } 29 30 type RestoreTarget struct { 31 // ID of the ECS to be restored 32 ServerId string `json:"server_id"` 33 // List of the mappings between disk backups and target disks 34 Volumes []RestoreVolumeMapping `json:"volumes"` 35 } 36 37 func CreateRestorationTask(client *golangsdk.ServiceClient, opts RestoreOpts) (*RestoreResp, error) { 38 b, err := build.RequestBody(opts, "restore") 39 if err != nil { 40 return nil, err 41 } 42 43 // POST https://{endpoint}/v1/{project_id}/restores 44 raw, err := client.Post(client.ServiceURL("restores"), b, nil, &golangsdk.RequestOpts{ 45 OkCodes: []int{200}, 46 }) 47 if err != nil { 48 return nil, err 49 } 50 51 var res RestoreResp 52 err = extract.IntoStructPtr(raw.Body, &res, "restore") 53 return &res, err 54 } 55 56 type RestoreResp struct { 57 // Restoration target 58 RestoreTarget string `json:"restore_target"` 59 // Status 60 Status string `json:"status"` 61 // Project ID 62 ProviderId string `json:"provider_id"` 63 // Resource status after the resource is restored, for example, available 64 ResourcesStatus interface{} `json:"resources_status"` 65 // Restoration parameters 66 Parameters RestoreParam `json:"parameters"` 67 // Backup record ID 68 CheckpointId string `json:"checkpoint_id"` 69 // Project ID 70 ProjectId string `json:"project_id"` 71 // Restoration ID 72 Id string `json:"id"` 73 // Cause of the resource restoration failure 74 ResourcesReason interface{} `json:"resources_reason"` 75 }