github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/sdrs/v1/replications/requests.go (about) 1 package replications 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 ) 6 7 var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{ 8 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 9 } 10 11 // CreateOptsBuilder allows extensions to add additional parameters to the 12 // Create request. 13 type CreateOptsBuilder interface { 14 ToReplicationCreateMap() (map[string]interface{}, error) 15 } 16 17 // CreateOpts contains all the values needed to create a new replication. 18 type CreateOpts struct { 19 //Protection Group ID 20 GroupID string `json:"server_group_id" required:"true"` 21 //Volume ID 22 VolumeID string `json:"volume_id" required:"true"` 23 //Replication Name 24 Name string `json:"name" required:"true"` 25 //Replication Description 26 Description string `json:"description,omitempty"` 27 } 28 29 // ToReplicationCreateMap builds a create request body from CreateOpts. 30 func (opts CreateOpts) ToReplicationCreateMap() (map[string]interface{}, error) { 31 return golangsdk.BuildRequestBody(opts, "replication") 32 } 33 34 // Create will create a new Replication based on the values in CreateOpts. 35 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r JobResult) { 36 b, err := opts.ToReplicationCreateMap() 37 if err != nil { 38 r.Err = err 39 return 40 } 41 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 42 _, r.Err = c.Post(rootURL(c), b, &r.Body, reqOpt) 43 return 44 } 45 46 // UpdateOptsBuilder allows extensions to add additional parameters to the 47 // Update request. 48 type UpdateOptsBuilder interface { 49 ToReplicationUpdateMap() (map[string]interface{}, error) 50 } 51 52 // UpdateOpts contains all the values needed to update a Replication. 53 type UpdateOpts struct { 54 //Replication name 55 Name string `json:"name" required:"true"` 56 } 57 58 // ToReplicationUpdateMap builds a update request body from UpdateOpts. 59 func (opts UpdateOpts) ToReplicationUpdateMap() (map[string]interface{}, error) { 60 return golangsdk.BuildRequestBody(opts, "replication") 61 } 62 63 // Update accepts a UpdateOpts struct and uses the values to update a Replication.The response code from api is 200 64 func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { 65 b, err := opts.ToReplicationUpdateMap() 66 if err != nil { 67 r.Err = err 68 return 69 } 70 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 71 _, r.Err = c.Put(resourceURL(c, id), b, nil, reqOpt) 72 return 73 } 74 75 // Get retrieves a particular Replication based on its unique ID. 76 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 77 _, r.Err = c.Get(resourceURL(c, id), &r.Body, &golangsdk.RequestOpts{ 78 MoreHeaders: RequestOpts.MoreHeaders, 79 }) 80 return 81 } 82 83 // DeleteOptsBuilder allows extensions to add additional parameters to the 84 // Delete request. 85 type DeleteOptsBuilder interface { 86 ToReplicationDeleteMap() (map[string]interface{}, error) 87 } 88 89 // DeleteOpts contains all the values needed to delete a Replication. 90 type DeleteOpts struct { 91 //Group ID 92 GroupID string `json:"server_group_id,omitempty"` 93 //Delete Target Volume 94 DeleteVolume bool `json:"delete_target_volume,omitempty"` 95 } 96 97 // ToReplicationDeleteMap builds a update request body from DeleteOpts. 98 func (opts DeleteOpts) ToReplicationDeleteMap() (map[string]interface{}, error) { 99 return golangsdk.BuildRequestBody(opts, "replication") 100 } 101 102 // Delete will permanently delete a particular Replication based on its unique ID. 103 func Delete(c *golangsdk.ServiceClient, id string, opts DeleteOptsBuilder) (r JobResult) { 104 b, err := opts.ToReplicationDeleteMap() 105 if err != nil { 106 r.Err = err 107 return 108 } 109 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 110 _, r.Err = c.DeleteWithBodyResp(resourceURL(c, id), b, &r.Body, reqOpt) 111 return 112 }