Skip to content

Commit

Permalink
[Refactor] Refactor Disable protection groups
Browse files Browse the repository at this point in the history
  • Loading branch information
muneeb-jan committed Sep 19, 2024
1 parent 55974f5 commit 7c34dcf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
44 changes: 44 additions & 0 deletions openstack/sdrs/v1/protectiongroups/Disable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package protectiongroups

import (
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

// DisableOpts contains all the values needed to disable protection for a Group.
type DisableOpts struct {
// Disables protection for a protection group. The StopServerGroup is an empty object.
StopServerGroup StopServerGroupInfo `json:"stop-server-group" required:"true"`
}

type StopServerGroupInfo struct {
// Empty
}

// Disable will Disable protection for a protection Group.
func Disable(client *golangsdk.ServiceClient, ServerGroupId string) (*DisableResponse, error) {
opts := DisableOpts{
StopServerGroup: StopServerGroupInfo{},
}
b, err := build.RequestBody(opts, "")
if err != nil {
return nil, err
}
// POST /v1/{project_id}/server-groups/{server_group_id}/action
raw, err := client.Post(client.ServiceURL("server-groups", ServerGroupId, "action"), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
if err != nil {
return nil, err
}

var res DisableResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type DisableResponse struct {
// Specifies the job ID.
JobID string `json:"job_id"`
}
23 changes: 0 additions & 23 deletions openstack/sdrs/v1/protectiongroups/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,3 @@ func Delete(c *golangsdk.ServiceClient, id string) (r JobResult) {
_, r.Err = c.DeleteWithResponse(resourceURL(c, id), &r.Body, reqOpt)
return
}

// DisableOpts contains all the values needed to disable protection for a Group.
type DisableOpts struct {
// Empty
}

// ToGroupDisableMap builds a create request body from DisableOpts.
func (opts DisableOpts) ToGroupDisableMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "stop-server-group")
}

// Disable will disable protection for a protection Group.
func Disable(c *golangsdk.ServiceClient, id string) (r JobResult) {
opts := DisableOpts{}
b, err := opts.ToGroupDisableMap()
if err != nil {
r.Err = err
return
}
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
_, r.Err = c.Post(actionURL(c, id), b, &r.Body, reqOpt)
return
}

0 comments on commit 7c34dcf

Please sign in to comment.