github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/cbr/v3/backups/requests.go (about) 1 package backups 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 var requestOpts = golangsdk.RequestOpts{ 9 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 10 } 11 12 // Get is a method to obtain an specified backup by its ID. 13 func Get(client *golangsdk.ServiceClient, backupId string) (*BackupResp, error) { 14 var r getResp 15 _, err := client.Get(resourceURL(client, backupId), &r, &golangsdk.RequestOpts{ 16 MoreHeaders: requestOpts.MoreHeaders, 17 }) 18 return &r.Backup, err 19 } 20 21 // ListOpts is the structure that used to query backup list using given parameters. 22 type ListOpts struct { 23 // Restore point ID. 24 CheckpointId string `q:"checkpoint_id"` 25 // Dedicated cloud tag, which only takes effect in dedicated cloud scenarios. 26 Dec bool `q:"dec"` 27 // Time when the backup ends, in %YYYY-%mm-%ddT%HH:%MM:%SSZ format. For example, 2018-02-01T12:00:00Z. 28 EndTime string `q:"end_time"` 29 // Enterprise project ID or all_granted_eps. all_granted_eps indicates querying the IDs of all enterprise projects 30 // on which the user has permissions. 31 EnterpriseProjectId string `q:"enterprise_project_id"` 32 // Backup type, which can be backup or replication. 33 ImageType string `q:"image_type"` 34 // Whether incremental backup is used. 35 // Default: false 36 Incremental bool `q:"incremental"` 37 // Number of records displayed per page. 38 // The value must be a positive integer. 39 Limit int `q:"limit"` 40 // ID of the last record displayed on the previous page. 41 Marker string `q:"marker"` 42 // Backup sharing status 43 // Enumeration values: 44 // + pending 45 // + accepted 46 // + rejected 47 MemberStatus string `q:"member_status"` 48 // Backup name. 49 Name string `q:"name"` 50 // Offset value. The value must be a positive integer. 51 Offset int `q:"offset"` 52 // Owning type of a backup. private backups are queried by default. 53 // Enumeration values: 54 // + all_granted 55 // + private 56 // + shared 57 // Default: private 58 OwnType string `q:"own_type"` 59 // Parent backup ID. 60 ParentId string `q:"parent_id"` 61 // AZ-based filtering is supported. 62 ResourceAZ string `q:"resource_az"` 63 // Resource ID. 64 ResourceId string `q:"resource_id"` 65 // Resource name. 66 ResourceName string `q:"resource_name"` 67 // Resource type, which can be: 68 // + OS::Nova::Server 69 // + OS::Cinder::Volume 70 // + OS::Ironic::BareMetalServer 71 // + OS::Native::Server 72 // + OS::Sfs::Turbo 73 // + OS::Workspace::DesktopV2 74 ResourceType string `q:"resource_type"` 75 // Whether to show replication records. 76 // Default: false 77 ShowReplication bool `q:"show_replication"` 78 // A group of properties separated by commas (,) and sorting directions. 79 // The value is in the format of <key1>[:<direction>],<key2>[:<direction>], where the value of direction is 80 // asc (ascending order) or desc (descending order). 81 // If a direction is not specified, the default sorting direction is desc. 82 // The value of sort can contain a maximum of 255 characters. 83 // The key can be as follows: created_at, updated_at, name, status, protected_at, id 84 Sort string `q:"sort"` 85 // Time when the backup starts, in %YYYY-%mm-%ddT%HH:%MM:%SSZ format. 86 // For example, 2018-02-01T12:00:00Z. 87 StartTime string `q:"start_time"` 88 // Status When the API is called, multiple statuses can be transferred for filtering. 89 // for example, status=available&status=error. 90 // Enumeration values: 91 // + available 92 // + protecting 93 // + deleting 94 // + restoring 95 // + error 96 // + waiting_protect 97 // + waiting_delete 98 // + waiting_restore 99 Status string `q:"status"` 100 // Backups are filtered based on the occupied vault capacity. 101 // The value ranges from 1 to 100. 102 // For example, if used_percent is set to 80, all backups who occupied 80% or more of the vault capacity are 103 // displayed. 104 UsedPercent string `q:"used_percent"` 105 // Vault ID. 106 VaultId string `q:"vault_id"` 107 } 108 109 // List is a method used to query backup list under specified checkpoint using given parameters. 110 func List(client *golangsdk.ServiceClient, opts ListOpts) ([]BackupResp, error) { 111 url := rootURL(client) 112 query, err := golangsdk.BuildQueryString(opts) 113 if err != nil { 114 return nil, err 115 } 116 url += query.String() 117 118 pages, err := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 119 p := BackupPage{pagination.OffsetPageBase{PageResult: r}} 120 return p 121 }).AllPages() 122 123 if err != nil { 124 return nil, err 125 } 126 return ExtractBackups(pages) 127 } 128 129 // Delete is a method to delete an specified backup by its ID. 130 func Delete(client *golangsdk.ServiceClient, backupId string) error { 131 _, err := client.Delete(resourceURL(client, backupId), &golangsdk.RequestOpts{ 132 MoreHeaders: requestOpts.MoreHeaders, 133 }) 134 return err 135 }