github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/sdrs/v1/attachreplication/requests.go (about) 1 package attachreplication 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 parameters to the Create request. 12 type CreateOptsBuilder interface { 13 ToReplicationAttachmentCreateMap() (map[string]interface{}, error) 14 } 15 16 // CreateOpts specifies replication attachment creation or import parameters. 17 type CreateOpts struct { 18 // Device is the device that the volume will attach to the instance as. 19 // Omit for "auto". 20 Device string `json:"device" required:"true"` 21 22 // ReplicationID is the ID of the volume to attach to the instance. 23 ReplicationID string `json:"replication_id" required:"true"` 24 } 25 26 // ToReplicationAttachmentCreateMap constructs a request body from CreateOpts. 27 func (opts CreateOpts) ToReplicationAttachmentCreateMap() (map[string]interface{}, error) { 28 return golangsdk.BuildRequestBody(opts, "replicationAttachment") 29 } 30 31 // Create requests the creation of a new replication attachment on the instance. 32 func Create(client *golangsdk.ServiceClient, instanceID string, opts CreateOptsBuilder) (r JobResult) { 33 b, err := opts.ToReplicationAttachmentCreateMap() 34 if err != nil { 35 r.Err = err 36 return 37 } 38 _, r.Err = client.Post(createURL(client, instanceID), b, &r.Body, &golangsdk.RequestOpts{ 39 OkCodes: []int{200}, 40 }) 41 return 42 } 43 44 // Delete requests the deletion of a previous stored ReplicationAttachment from 45 // the instance. 46 func Delete(client *golangsdk.ServiceClient, instanceID, replicationID string) (r JobResult) { 47 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}, 48 MoreHeaders: RequestOpts.MoreHeaders} 49 _, r.Err = client.DeleteWithResponse(deleteURL(client, instanceID, replicationID), &r.Body, reqOpt) 50 return 51 }