github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/cbr/v3/checkpoints/requests.go (about) 1 package checkpoints 2 3 import "github.com/chnsz/golangsdk" 4 5 // CreateOpts is the structure that used to create a checkpoint and backup some resources. 6 type CreateOpts struct { 7 // The vault ID. 8 VaultId string `json:"vault_id" required:"true"` 9 // Parameters. 10 Parameters CheckpointParameter `json:"parameters,omitempty"` 11 } 12 13 // CheckpointParameter is the structure that represents the backup configuration. 14 type CheckpointParameter struct { 15 // Whether automatic triggering is enabled. 16 // Possible values are true (yes) and false (no). 17 // Defaults to false. 18 AutoTrigger *bool `json:"auto_trigger,omitempty"` 19 // Backup description. 20 Description string `json:"description,omitempty"` 21 // Whether the backup is an incremental backup. 22 // Possible values are true (yes) and false (no). 23 // Defaults to true. 24 Incremental *bool `json:"incremental,omitempty"` 25 // Backup name, which can contain only digits, letters, underscores (_), and hyphens (-). 26 Name string `json:"name,omitempty"` 27 // The UUID list of resources to be backed up. 28 Resources []string `json:"resources,omitempty"` 29 // Resource details. 30 ResourceDetails []Resource `json:"resource_details,omitempty"` 31 } 32 33 // Resource is the structure that represents the backup resource detail. 34 type Resource struct { 35 // ID of the vault resource type. 36 ID string `json:"id" required:"true"` 37 // The type of the resource to be backed up, which can be: 38 // + OS::Nova::Server 39 // + OS::Cinder::Volume 40 // + OS::Ironic::BareMetalServer 41 // + OS::Native::Server 42 // + OS::Sfs::Turbo 43 // + OS::Workspace::DesktopV2 44 Type string `json:"type" required:"true"` 45 // The vaule 46 Name string `json:"name,omitempty"` 47 // The extra volume configuration. 48 ExtraInfo ResourceExtraInfo `json:"extra_info,omitempty"` 49 } 50 51 // ResourceExtraInfo is the structure that represents the configuration of the backup volume. 52 type ResourceExtraInfo struct { 53 // The IDs of the disks that will not be backed up. This parameter is used when servers are added to a vault, 54 // which include all server disks. But some disks do not need to be backed up. Or in case that a server was 55 // previously added and some disks on this server do not need to be backed up. 56 ExcludeVolumes []string `json:"exclude_volumes,omitempty"` 57 } 58 59 var requestOpts = golangsdk.RequestOpts{ 60 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 61 } 62 63 // Create is a method used to create a new checkpoint using given parameters. 64 func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*Checkpoint, error) { 65 b, err := golangsdk.BuildRequestBody(opts, "checkpoint") 66 if err != nil { 67 return nil, err 68 } 69 70 var r struct { 71 Checkpoint Checkpoint `json:"checkpoint"` 72 } 73 _, err = client.Post(rootURL(client), b, &r, &golangsdk.RequestOpts{ 74 MoreHeaders: requestOpts.MoreHeaders, 75 }) 76 return &r.Checkpoint, err 77 } 78 79 // Get is a method to obtain an existing checkpoint by its ID. 80 func Get(client *golangsdk.ServiceClient, checkpointId string) (*Checkpoint, error) { 81 var r struct { 82 Checkpoint Checkpoint `json:"checkpoint"` 83 } 84 _, err := client.Get(resourceURL(client, checkpointId), &r, &golangsdk.RequestOpts{ 85 MoreHeaders: requestOpts.MoreHeaders, 86 }) 87 return &r.Checkpoint, err 88 }