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