github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/csbs/v1/backup/Create.go (about) 1 package backup 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/internal/build" 6 "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" 7 "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" 8 ) 9 10 // CreateOpts contains the options for create a Backup. This object is passed to backup.Create(). 11 type CreateOpts struct { 12 // Backup name. The value consists of 1 to 255 characters and can contain only letters, digits, underscores (_), and hyphens (-). 13 BackupName string `json:"backup_name,omitempty"` 14 // Backup description. The value consists of 0 to 255 characters and must not contain a greater-than sign (>) or less-than sign (<). 15 Description string `json:"description,omitempty"` 16 // Entity object type of the backup object 17 // The current value is OS::Nova::Server indicating that the backup object is an ECS. 18 // If this parameter is not passed, the backup object type defaults to OS::Nova::Server. 19 ResourceType string `json:"resource_type,omitempty"` 20 // Backup type. Value True indicates incremental backup and value False indicates full backup. 21 // For the initial backup, full backup is always adopted, in spite of which value is set. 22 Incremental *bool `json:"incremental,omitempty"` 23 // Tag list 24 // This list cannot be an empty list. 25 // The list can contain up to 10 keys. 26 // Keys in this list must be unique. 27 Tags []tags.ResourceTag `json:"tags,omitempty"` 28 // Additional information about the backup object 29 ExtraInfo interface{} `json:"extra_info,omitempty"` 30 } 31 32 // Create will create a new backup based on the values in CreateOpts. To extract 33 // the checkpoint object from the response, call the Extract method on the CreateResult. 34 func Create(client *golangsdk.ServiceClient, resourceID string, opts CreateOpts) (*Checkpoint, error) { 35 b, err := build.RequestBody(opts, "protect") 36 if err != nil { 37 return nil, err 38 } 39 40 // POST https://{endpoint}/v1/{project_id}/providers/{provider_id}/resources/{resource_id}/action 41 raw, err := client.Post(client.ServiceURL("providers", ProviderID, "resources", resourceID, "action"), b, 42 nil, &golangsdk.RequestOpts{ 43 OkCodes: []int{200}, 44 }) 45 if err != nil { 46 return nil, err 47 } 48 49 var res Checkpoint 50 err = extract.IntoStructPtr(raw.Body, &res, "checkpoint") 51 return &res, err 52 } 53 54 type Checkpoint struct { 55 // Backup status 56 // Enum:[ waiting_protect, protecting, available, waiting_restore, restoring, error, waiting_delete, deleting,deleted] 57 Status string `json:"status"` 58 // Creation time, for example, 2017-04-18T01:21:52.701973 59 CreatedAt string `json:"created_at"` 60 // Backup record ID 61 Id string `json:"id"` 62 // Resource diagram, which displays the inclusion relationship between backups and sub-backups 63 ResourceGraph string `json:"resource_graph"` 64 // Project ID 65 ProjectId string `json:"project_id"` 66 // Backup plan information 67 ProtectionPlan ProtectionPlan `json:"protection_plan"` 68 // Additional information 69 ExtraInfo interface{} `json:"extra_info"` 70 } 71 72 type ProtectionPlan struct { 73 // Backup policy ID 74 Id string `json:"id"` 75 // Backup policy name 76 Name string `json:"name"` 77 // Backup object list 78 // For details, see Table 2-8. 79 BackupResources []СsbsBackupResource `json:"resources"` 80 } 81 82 type СsbsBackupResource struct { 83 // ID of the object to be backed up 84 ID string `json:"id"` 85 // Entity object type of the backup object. The value is fixed at OS::Nova::Server, indicating that the object type is ECSs. 86 Type string `json:"type"` 87 // Backup object name 88 Name string `json:"name"` 89 // Additional information about the backup object 90 ExtraInfo interface{} `json:"extra_info"` 91 }