github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/drs/v2/replications/requests.go (about) 1 package replications 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // CreateOpsBuilder is used for creating replication parameters. 9 // any struct providing the parameters should implement this interface 10 type CreateOpsBuilder interface { 11 ToReplicationCreateMap() (map[string]interface{}, error) 12 } 13 14 // CreateOps is a struct that contains all the parameters. 15 type CreateOps struct { 16 // The name of the EVS replication pair. 17 // The name can contain a maximum of 255 bytes. 18 Name string `json:"name,omitempty"` 19 20 // The description of the EVS replication pair. 21 // The description can contain a maximum of 255 bytes. 22 Description string `json:"description,omitempty"` 23 24 // The IDs of the EVS disks used to create the EVS replication pair. 25 VolumeIDs []string `json:"volume_ids" required:"true"` 26 27 // The primary AZ of the EVS replication pair. 28 // That is the AZ where the production disk belongs. 29 PriorityStation string `json:"priority_station" required:"true"` 30 31 // The type of the EVS replication pair. 32 // Currently only type hypermetro is supported. 33 ReplicationModel string `json:"replication_model" required:"true"` 34 } 35 36 // ToReplicationCreateMap is used for type convert 37 func (ops CreateOps) ToReplicationCreateMap() (map[string]interface{}, error) { 38 return golangsdk.BuildRequestBody(ops, "replication") 39 } 40 41 // Create a replication with given parameters. 42 func Create(client *golangsdk.ServiceClient, ops CreateOpsBuilder) (r CreateResult) { 43 b, err := ops.ToReplicationCreateMap() 44 if err != nil { 45 r.Err = err 46 return 47 } 48 49 _, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{ 50 OkCodes: []int{202}, 51 }) 52 53 return 54 } 55 56 // Delete a replication by id 57 func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { 58 _, r.Err = client.Delete(deleteURL(client, id), nil) 59 return 60 } 61 62 // Get a replication with detailed information by id 63 func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { 64 _, r.Err = client.Get(getURL(client, id), &r.Body, nil) 65 return 66 } 67 68 // ListOptsBuilder is an interface by which can be able to 69 // build the query string of the list function 70 type ListOptsBuilder interface { 71 ToReplicationListQuery() (string, error) 72 } 73 74 // ListOpts is a struct that contains all the parameters. 75 type ListOpts struct { 76 Marker string `q:"marker"` 77 Limit int `q:"limit"` 78 SortKey string `q:"sort_key"` 79 SortDir string `q:"sort_dir"` 80 Offset int `q:"offset"` 81 ChangesSince string `q:"changes-since"` 82 Name string `q:"name"` 83 Status string `q:"status"` 84 ReplicationConsistencyGroupID string `q:"replication_consistency_group_id"` 85 VolumeIDs string `q:"volume_ids"` 86 VolumeID string `q:"volume_id"` 87 PriorityStation string `q:"priority_station"` 88 } 89 90 // ToReplicationListQuery formats a ListOpts into a query string. 91 func (opts ListOpts) ToReplicationListQuery() (string, error) { 92 q, err := golangsdk.BuildQueryString(opts) 93 return q.String(), err 94 } 95 96 // List all the replications 97 func List(client *golangsdk.ServiceClient, ops ListOptsBuilder) pagination.Pager { 98 url := listURL(client) 99 if ops != nil { 100 q, err := ops.ToReplicationListQuery() 101 if err != nil { 102 return pagination.Pager{Err: err} 103 } 104 url += q 105 } 106 107 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 108 return ReplicationPage{pagination.SinglePageBase(r)} 109 }) 110 }