You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
decort-golang-sdk/pkg/cloudbroker/image/edit.go

70 lines
1.3 KiB

package image
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for edit image
type EditRequest struct {
// ID of the image to edit
// Required: true
ImageID uint64 `url:"imageId"`
// Name for the image
// Required: false
Name string `url:"name,omitempty"`
// Username for the image
// Required: false
Username string `url:"username,omitempty"`
// Password for the image
// Required: false
Password string `url:"password,omitempty"`
// Account ID to make the image exclusive
// Required: false
AccountID uint64 `url:"accountId,omitempty"`
// Does this machine supports hot resize
// Required: false
HotResize bool `url:"hotresize,omitempty"`
// Does this image boot OS
// Required: false
Bootable bool `url:"bootable,omitempty"`
}
func (irq EditRequest) validate() error {
if irq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
return nil
}
// Edit edits an existing image
func (i Image) Edit(ctx context.Context, req EditRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/image/edit"
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}