diff --git a/gcore/instance/v1/instances/requests.go b/gcore/instance/v1/instances/requests.go index 2acde64..4902c1a 100644 --- a/gcore/instance/v1/instances/requests.go +++ b/gcore/instance/v1/instances/requests.go @@ -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 +} diff --git a/gcore/instance/v1/instances/urls.go b/gcore/instance/v1/instances/urls.go index bbdb232..7394b8f 100644 --- a/gcore/instance/v1/instances/urls.go +++ b/gcore/instance/v1/instances/urls.go @@ -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") +}