github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/sdrs/v1/drill/requests.go (about) 1 package drill 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 ToDrillCreateMap() (map[string]interface{}, error) 12 } 13 14 // CreateOpts contains all the values needed to create a new dr-drill. 15 type CreateOpts struct { 16 // Protection Group ID 17 GroupID string `json:"server_group_id" required:"true"` 18 // Drill vpc id 19 DrillVpcID string `json:"drill_vpc_id" required:"true"` 20 // DR-Drill Name 21 Name string `json:"name" required:"true"` 22 } 23 24 // ToDrillCreateMap builds a create request body from CreateOpts. 25 func (opts CreateOpts) ToDrillCreateMap() (map[string]interface{}, error) { 26 return golangsdk.BuildRequestBody(opts, "disaster_recovery_drill") 27 } 28 29 // Create will create a new DR-Drill based on the values in CreateOpts. 30 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r JobResult) { 31 b, err := opts.ToDrillCreateMap() 32 if err != nil { 33 r.Err = err 34 return 35 } 36 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 37 _, r.Err = c.Post(rootURL(c), b, &r.Body, reqOpt) 38 return 39 } 40 41 // UpdateOptsBuilder allows extensions to add additional parameters to the 42 // Update request. 43 type UpdateOptsBuilder interface { 44 ToDrillUpdateMap() (map[string]interface{}, error) 45 } 46 47 // UpdateOpts contains all the values needed to update a dr-drill. 48 type UpdateOpts struct { 49 // DR-Drill name 50 Name string `json:"name" required:"true"` 51 } 52 53 // ToDrillUpdateMap builds a update request body from UpdateOpts. 54 func (opts UpdateOpts) ToDrillUpdateMap() (map[string]interface{}, error) { 55 return golangsdk.BuildRequestBody(opts, "disaster_recovery_drill") 56 } 57 58 // Update accepts a UpdateOpts struct and uses the values to update a dr-drill. 59 // The response code from api is 200 60 func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { 61 b, err := opts.ToDrillUpdateMap() 62 if err != nil { 63 r.Err = err 64 return 65 } 66 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 67 _, r.Err = c.Put(resourceURL(c, id), b, nil, reqOpt) 68 return 69 } 70 71 // Get retrieves a particular dr-drill based on its unique ID. 72 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 73 _, r.Err = c.Get(resourceURL(c, id), &r.Body, openstack.StdRequestOpts()) 74 return 75 } 76 77 // Delete will permanently delete a particular dr-drill based on its unique ID. 78 func Delete(c *golangsdk.ServiceClient, id string) (r JobResult) { 79 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 80 _, r.Err = c.DeleteWithResponse(resourceURL(c, id), &r.Body, reqOpt) 81 return 82 }