This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Add CSBS service backup and policy management interfaces #51
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8bf13c5
add csbs backup management interfaces
Savasw 2506e11
add csbs backup policy management interfaces
Savasw 06680b3
update csbs backuppolicy operation def req and resp data type
Savasw 72574a3
fix cs backup policy parameter response type
Savasw cb5a61e
update csbs result structure for user ease
Savasw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Package backup enables management and retrieval of | ||
back up resources. | ||
|
||
Example to List Backup | ||
listbackup := backup.ListOpts{ID: "7b99acfd-18c3-4f26-9d39-b4ebd2ea3e12"} | ||
allbackups, err := backup.List(client,listbackup) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(allbackups) | ||
|
||
|
||
|
||
Example to Create a Backup | ||
createBackup:=backup.CreateOpts{BackupName: "c2c-backup", Description: "mybackup"} | ||
out,err:=backup.Create(client,"fc4d5750-22e7-4798-8a46-f48f62c4c1da", "f8ddc472-cf00-4384-851e-5f2a68c33762", | ||
createBackup).Extract() | ||
fmt.Println(out) | ||
fmt.Println(err) | ||
|
||
Example to Query if resources can be backed up | ||
createQuery:=backup.ResourceBackupCapOpts{CheckProtectable:[]backup.ResourceCapQueryParams{{ResourceId: "069e678a-f1d1-4a38-880b-459bde82fcc6", | ||
ResourceType: "OS::Nova::Server"}}} | ||
out,err:=backup.QueryResourceBackupCapability(client,"fc4d5750-22e7-4798-8a46-f48f62c4c1da", | ||
createQuery).ExtractQueryResponse() | ||
fmt.Println(out) | ||
fmt.Println(err) | ||
|
||
|
||
Example to Delete a Backup | ||
out:=backup.Delete(client,"fc4d5750-22e7-4798-8a46-f48f62c4c1da") | ||
fmt.Println(out) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
Example to Get Backup | ||
result:=backup.Get(client,"7b99acfd-18c3-4f26-9d39-b4ebd2ea3e12") | ||
out,err:=result.ExtractBackup() | ||
fmt.Println(out) | ||
|
||
*/ | ||
package backup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
package backup | ||
|
||
import ( | ||
"github.com/huaweicloud/golangsdk" | ||
"github.com/huaweicloud/golangsdk/pagination" | ||
) | ||
|
||
type ResourceTag struct { | ||
Key string `json:"key"` | ||
Value string `json:"value"` | ||
} | ||
|
||
// ListOpts allows the filtering and sorting of paginated collections through | ||
// the API. Filtering is achieved by passing in struct field values that map to | ||
// the attributes you want to see returned. Marker and Limit are used for pagination. | ||
type ListOpts struct { | ||
Status string `q:"status"` | ||
Limit string `q:"limit"` | ||
Marker string `q:"marker"` | ||
Sort string `q:"sort"` | ||
AllTenants string `q:"all_tenants"` | ||
Name string `q:"name"` | ||
ResourceId string `q:"resource_id"` | ||
ResourceName string `q:"resource_name"` | ||
PolicyId string `q:"policy_id"` | ||
VmIp string `q:"ip"` | ||
CheckpointId string `q:"checkpoint_id"` | ||
ID string | ||
ResourceType string `q:"resource_type"` | ||
} | ||
|
||
// List returns collection of | ||
// backups. It accepts a ListOpts struct, which allows you to filter and sort | ||
// the returned collection for greater efficiency. | ||
func List(c *golangsdk.ServiceClient, opts ListOpts) ([]Backup, error) { | ||
q, err := golangsdk.BuildQueryString(&opts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
u := listURL(c) + q.String() | ||
pages, err := pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page { | ||
return BackupPage{pagination.LinkedPageBase{PageResult: r}} | ||
}).AllPages() | ||
|
||
allBackups, err := ExtractBackups(pages) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if opts.ID != "" { | ||
return FilterBackupsById(allBackups, opts.ID) | ||
} | ||
|
||
return allBackups, nil | ||
|
||
} | ||
|
||
func FilterBackupsById(backups []Backup, filterId string) ([]Backup, error) { | ||
|
||
var refinedBackups []Backup | ||
|
||
for _, backup := range backups { | ||
|
||
if filterId == backup.Id { | ||
refinedBackups = append(refinedBackups, backup) | ||
} | ||
} | ||
|
||
return refinedBackups, nil | ||
} | ||
|
||
// CreateOptsBuilder allows extensions to add additional parameters to the | ||
// Create request. | ||
type CreateOptsBuilder interface { | ||
ToBackupCreateMap() (map[string]interface{}, error) | ||
} | ||
|
||
// CreateOpts contains the options for create a Backup. This object is | ||
// passed to backup.Create(). | ||
type CreateOpts struct { | ||
BackupName string `json:"backup_name,omitempty"` | ||
Description string `json:"description,omitempty"` | ||
ResourceType string `json:"resource_type,omitempty"` | ||
Tags []ResourceTag `json:"tags,omitempty"` | ||
ExtraInfo interface{} `json:"extra_info,omitempty"` | ||
} | ||
|
||
// ToBackupCreateMap assembles a request body based on the contents of a | ||
// CreateOpts. | ||
func (opts CreateOpts) ToBackupCreateMap() (map[string]interface{}, error) { | ||
return golangsdk.BuildRequestBody(opts, "protect") | ||
} | ||
|
||
// Create will create a new backup based on the values in CreateOpts. To extract | ||
// the checkpoint object from the response, call the Extract method on the | ||
// CreateResult. | ||
func Create(client *golangsdk.ServiceClient, resourceId string, opts CreateOptsBuilder) (r CreateResult) { | ||
b, err := opts.ToBackupCreateMap() | ||
if err != nil { | ||
r.Err = err | ||
return | ||
} | ||
_, r.Err = client.Post(rootURL(client, resourceId), b, &r.Body, &golangsdk.RequestOpts{ | ||
OkCodes: []int{200}, | ||
}) | ||
return | ||
} | ||
|
||
// ResourceBackupCapabilityOptsBuilder allows extensions to add additional parameters to the | ||
// QueryResourceBackupCapability request. | ||
type ResourceBackupCapabilityOptsBuilder interface { | ||
ToQueryResourceCreateMap() (map[string]interface{}, error) | ||
} | ||
|
||
// ResourceBackupCapOpts contains the options for querying whether resources can be backed up. This object is | ||
// passed to backup.QueryResourceBackupCapability(). | ||
type ResourceBackupCapOpts struct { | ||
CheckProtectable []ResourceCapQueryParams `json:"check_protectable" required:"true"` | ||
} | ||
|
||
type ResourceCapQueryParams struct { | ||
ResourceId string `json:"resource_id" required:"true"` | ||
ResourceType string `json:"resource_type" required:"true"` | ||
} | ||
|
||
// ToQueryResourceCreateMap assembles a request body based on the contents of a | ||
// ResourceBackupCapOpts. | ||
func (opts ResourceBackupCapOpts) ToQueryResourceCreateMap() (map[string]interface{}, error) { | ||
return golangsdk.BuildRequestBody(opts, "") | ||
} | ||
|
||
// QueryResourceBackupCapability will query whether resources can be backed up based on the values in ResourceBackupCapOpts. To extract | ||
// the ResourceCap object from the response, call the ExtractQueryResponse method on the | ||
// QueryResult. | ||
func QueryResourceBackupCapability(client *golangsdk.ServiceClient, opts ResourceBackupCapabilityOptsBuilder) (r QueryResult) { | ||
b, err := opts.ToQueryResourceCreateMap() | ||
if err != nil { | ||
r.Err = err | ||
|
||
return | ||
} | ||
_, r.Err = client.Post(resourceURL(client), b, &r.Body, &golangsdk.RequestOpts{ | ||
OkCodes: []int{200}, | ||
}) | ||
return | ||
} | ||
|
||
// Get will get a single backup with specific ID. To extract the Backup object from the response, | ||
// call the ExtractBackup method on the GetResult. | ||
func Get(client *golangsdk.ServiceClient, backupId string) (r GetResult) { | ||
_, r.Err = client.Get(getURL(client, backupId), &r.Body, nil) | ||
|
||
return | ||
|
||
} | ||
|
||
// Delete will delete an existing backup. | ||
func Delete(client *golangsdk.ServiceClient, checkpoint_id string) (r DeleteResult) { | ||
_, r.Err = client.Delete(deleteURL(client, checkpoint_id), &golangsdk.RequestOpts{ | ||
OkCodes: []int{200}, | ||
JSONResponse: nil, | ||
}) | ||
return | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.