github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/sdrs/v1/protectiongroups/requests.go (about) 1 package protectiongroups 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 ToGroupCreateMap() (map[string]interface{}, error) 12 } 13 14 // CreateOpts contains all the values needed to create a new group. 15 type CreateOpts struct { 16 // Group Name 17 Name string `json:"name" required:"true"` 18 // Group Description 19 Description string `json:"description,omitempty"` 20 // The source AZ of a protection group 21 SourceAZ string `json:"source_availability_zone" required:"true"` 22 // The target AZ of a protection group 23 TargetAZ string `json:"target_availability_zone" required:"true"` 24 // An active-active domain 25 DomainID string `json:"domain_id" required:"true"` 26 // ID of the source VPC 27 SourceVpcID string `json:"source_vpc_id" required:"true"` 28 // Deployment model 29 DrType string `json:"dr_type,omitempty"` 30 } 31 32 // ToGroupCreateMap builds a create request body from CreateOpts. 33 func (opts CreateOpts) ToGroupCreateMap() (map[string]interface{}, error) { 34 return golangsdk.BuildRequestBody(opts, "server_group") 35 } 36 37 // Create will create a new Group based on the values in CreateOpts. 38 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r JobResult) { 39 b, err := opts.ToGroupCreateMap() 40 if err != nil { 41 r.Err = err 42 return 43 } 44 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 45 _, r.Err = c.Post(rootURL(c), b, &r.Body, reqOpt) 46 return 47 } 48 49 // UpdateOptsBuilder allows extensions to add additional parameters to the 50 // Update request. 51 type UpdateOptsBuilder interface { 52 ToGroupUpdateMap() (map[string]interface{}, error) 53 } 54 55 // UpdateOpts contains all the values needed to update a Group. 56 type UpdateOpts struct { 57 // Group name 58 Name string `json:"name" required:"true"` 59 } 60 61 // ToGroupUpdateMap builds a update request body from UpdateOpts. 62 func (opts UpdateOpts) ToGroupUpdateMap() (map[string]interface{}, error) { 63 return golangsdk.BuildRequestBody(opts, "server_group") 64 } 65 66 // Update accepts a UpdateOpts struct and uses the values to update a Group.The response code from api is 200 67 func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { 68 b, err := opts.ToGroupUpdateMap() 69 if err != nil { 70 r.Err = err 71 return 72 } 73 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 74 _, r.Err = c.Put(resourceURL(c, id), b, nil, reqOpt) 75 return 76 } 77 78 // Get retrieves a particular Group based on its unique ID. 79 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 80 _, r.Err = c.Get(resourceURL(c, id), &r.Body, openstack.StdRequestOpts()) 81 return 82 } 83 84 // Delete will permanently delete a particular Group based on its unique ID. 85 func Delete(c *golangsdk.ServiceClient, id string) (r JobResult) { 86 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}, MoreHeaders: openstack.StdRequestOpts().MoreHeaders} 87 _, r.Err = c.DeleteWithResponse(resourceURL(c, id), &r.Body, reqOpt) 88 return 89 } 90 91 // EnableOpts contains all the values needed to enable protection for a Group. 92 type EnableOpts struct { 93 // Empty 94 } 95 96 // ToGroupEnableMap builds a create request body from EnableOpts. 97 func (opts EnableOpts) ToGroupEnableMap() (map[string]interface{}, error) { 98 return golangsdk.BuildRequestBody(opts, "start-server-group") 99 } 100 101 // Enable will enable protection for a protection Group. 102 func Enable(c *golangsdk.ServiceClient, id string) (r JobResult) { 103 opts := EnableOpts{} 104 b, err := opts.ToGroupEnableMap() 105 if err != nil { 106 r.Err = err 107 return 108 } 109 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 110 _, r.Err = c.Post(actionURL(c, id), b, &r.Body, reqOpt) 111 return 112 } 113 114 // DisableOpts contains all the values needed to disable protection for a Group. 115 type DisableOpts struct { 116 // Empty 117 } 118 119 // ToGroupDisableMap builds a create request body from DisableOpts. 120 func (opts DisableOpts) ToGroupDisableMap() (map[string]interface{}, error) { 121 return golangsdk.BuildRequestBody(opts, "stop-server-group") 122 } 123 124 // Disable will disable protection for a protection Group. 125 func Disable(c *golangsdk.ServiceClient, id string) (r JobResult) { 126 opts := DisableOpts{} 127 b, err := opts.ToGroupDisableMap() 128 if err != nil { 129 r.Err = err 130 return 131 } 132 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 133 _, r.Err = c.Post(actionURL(c, id), b, &r.Body, reqOpt) 134 return 135 }