Skip to content

Commit

Permalink
GCLOUD2-11796 manage servergroup
Browse files Browse the repository at this point in the history
  • Loading branch information
alexk53 committed Sep 12, 2024
1 parent aaec022 commit e46ea5c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
37 changes: 37 additions & 0 deletions gcore/instance/v1/instances/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,3 +728,40 @@ func ListInstanceLocation(client *gcorecloud.ServiceClient, opts ListInstanceLoc
_, r.Err = client.Get(url, &r.Body, nil)
return
}

type PutServerGroupOpts struct {
ServerGroupID string `json:"servergroup_id" required:"true" validate:"required,uuid4"`
}

func (opts PutServerGroupOpts) Validate() error {
return gcorecloud.ValidateStruct(opts)
}

func (opts PutServerGroupOpts) ToPutToServerGroupActionMap() (map[string]interface{}, error) {
if err := opts.Validate(); err != nil {
return nil, err
}
return gcorecloud.BuildRequestBody(opts, "")

}

type PutToServerGroupOptsBuilder interface {
ToPutToServerGroupActionMap() (map[string]interface{}, error)
}

// PutToServerGroup instance.
func PutToServerGroup(client *gcorecloud.ServiceClient, id string, opts PutToServerGroupOptsBuilder) (r tasks.Result) {
b, err := opts.ToPutToServerGroupActionMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(putServerToServerGroupURL(client, id), b, &r.Body, nil) // nolint
return
}

// RemoveFromServerGroup instance.
func RemoveFromServerGroup(client *gcorecloud.ServiceClient, id string) (r tasks.Result) {
_, r.Err = client.Post(removeServerFromServerGroupURL(client, id), nil, &r.Body, nil) // nolint
return
}
8 changes: 8 additions & 0 deletions gcore/instance/v1/instances/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,11 @@ func getInstanceConsoleURL(c *gcorecloud.ServiceClient, id string) string {
func listInstanceLocationURL(c *gcorecloud.ServiceClient) string {
return c.BaseServiceURL("instances", "search")
}

func putServerToServerGroupURL(c *gcorecloud.ServiceClient, id string) string {
return resourceActionURL(c, id, "put_from_servergroup")
}

func removeServerFromServerGroupURL(c *gcorecloud.ServiceClient, id string) string {
return resourceActionURL(c, id, "remove_from_servergroup")
}

0 comments on commit e46ea5c

Please sign in to comment.