Merge 'dev' into 'main'
This commit is contained in:
@@ -1,102 +1,92 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CreateRequest struct {
|
||||
Name string `url:"name"`
|
||||
URL string `url:"url"`
|
||||
GID uint64 `url:"gid"`
|
||||
BootType string `url:"boottype"`
|
||||
ImageType string `url:"imagetype"`
|
||||
Hotresize bool `url:"hotresize,omitempty"`
|
||||
Username string `url:"username,omitempty"`
|
||||
Password string `url:"password,omitempty"`
|
||||
AccountId uint64 `url:"accountId,omitempty"`
|
||||
UsernameDL string `url:"usernameDL,omitempty"`
|
||||
PasswordDL string `url:"passwordDL,omitempty"`
|
||||
SepId uint64 `url:"sepId,omitempty"`
|
||||
Pool string `url:"poolName,omitempty"`
|
||||
Architecture string `url:"architecture,omitempty"`
|
||||
Drivers []string `url:"drivers"`
|
||||
}
|
||||
|
||||
func (irq CreateRequest) Validate() error {
|
||||
if irq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
if irq.URL == "" {
|
||||
return errors.New("validation-error: field URL can not be empty")
|
||||
}
|
||||
|
||||
if irq.GID == 0 {
|
||||
return errors.New("validation-error: field GID can not be empty or equal to 0")
|
||||
}
|
||||
if irq.BootType == "" {
|
||||
return errors.New("validation-error: field BootType can not be empty")
|
||||
}
|
||||
|
||||
validate := validators.StringInSlice(irq.BootType, []string{"bios", "uefi"})
|
||||
if !validate {
|
||||
return errors.New("validation-error: field BootType can be bios or uefi")
|
||||
}
|
||||
if irq.ImageType == "" {
|
||||
return errors.New("validation-error: field ImageType can not be empty")
|
||||
}
|
||||
|
||||
validate = validators.StringInSlice(irq.ImageType, []string{"bios", "uefi"})
|
||||
if !validate {
|
||||
return errors.New("validation-error: field ImageType can be windows, linux or other")
|
||||
}
|
||||
|
||||
if len(irq.Drivers) == 0 || len(irq.Drivers) > 1 {
|
||||
return errors.New("validation-error: field Drivers can not be empty or have 2 or more elements")
|
||||
}
|
||||
|
||||
for _, v := range irq.Drivers {
|
||||
validate := validators.StringInSlice(v, []string{"KVM_X86"})
|
||||
if !validate {
|
||||
return errors.New("validation-error: field Drivers can be KVM_X86 only")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/image/create"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := i.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type CreateRequest struct {
|
||||
Name string `url:"name"`
|
||||
URL string `url:"url"`
|
||||
GID uint64 `url:"gid"`
|
||||
BootType string `url:"boottype"`
|
||||
ImageType string `url:"imagetype"`
|
||||
Hotresize bool `url:"hotresize,omitempty"`
|
||||
Username string `url:"username,omitempty"`
|
||||
Password string `url:"password,omitempty"`
|
||||
AccountID uint64 `url:"accountId,omitempty"`
|
||||
UsernameDL string `url:"usernameDL,omitempty"`
|
||||
PasswordDL string `url:"passwordDL,omitempty"`
|
||||
SepID uint64 `url:"sepId,omitempty"`
|
||||
Pool string `url:"poolName,omitempty"`
|
||||
Architecture string `url:"architecture,omitempty"`
|
||||
Drivers []string `url:"drivers"`
|
||||
}
|
||||
|
||||
func (irq CreateRequest) Validate() error {
|
||||
if irq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
if irq.URL == "" {
|
||||
return errors.New("validation-error: field URL can not be empty")
|
||||
}
|
||||
|
||||
if irq.GID == 0 {
|
||||
return errors.New("validation-error: field GID can not be empty or equal to 0")
|
||||
}
|
||||
if irq.BootType == "" {
|
||||
return errors.New("validation-error: field BootType can not be empty")
|
||||
}
|
||||
|
||||
validate := validators.StringInSlice(irq.BootType, []string{"bios", "uefi"})
|
||||
if !validate {
|
||||
return errors.New("validation-error: field BootType can be bios or uefi")
|
||||
}
|
||||
if irq.ImageType == "" {
|
||||
return errors.New("validation-error: field ImageType can not be empty")
|
||||
}
|
||||
|
||||
validate = validators.StringInSlice(irq.ImageType, []string{"windows", "linux", "other"})
|
||||
if !validate {
|
||||
return errors.New("validation-error: field ImageType can be windows, linux or other")
|
||||
}
|
||||
|
||||
if len(irq.Drivers) == 0 || len(irq.Drivers) > 1 {
|
||||
return errors.New("validation-error: field Drivers can not be empty or have 2 or more elements")
|
||||
}
|
||||
|
||||
for _, v := range irq.Drivers {
|
||||
validate := validators.StringInSlice(v, []string{"KVM_X86"})
|
||||
if !validate {
|
||||
return errors.New("validation-error: field Drivers can be KVM_X86 only")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/image/create"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -1,58 +1,47 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CreateVirtualRequest struct {
|
||||
Name string `url:"name"`
|
||||
TargetId uint64 `url:"targetId"`
|
||||
}
|
||||
|
||||
func (irq CreateVirtualRequest) Validate() error {
|
||||
if irq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
|
||||
if irq.TargetId == 0 {
|
||||
return errors.New("validation-error: field TargetId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) CreateVirtual(ctx context.Context, req CreateVirtualRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/image/createVirtual"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := i.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type CreateVirtualRequest struct {
|
||||
Name string `url:"name"`
|
||||
TargetID uint64 `url:"targetId"`
|
||||
}
|
||||
|
||||
func (irq CreateVirtualRequest) Validate() error {
|
||||
if irq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
|
||||
if irq.TargetID == 0 {
|
||||
return errors.New("validation-error: field TargetID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) CreateVirtual(ctx context.Context, req CreateVirtualRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/image/createVirtual"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -1,54 +1,43 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
ImageId uint64 `url:"imageId"`
|
||||
Permanently bool `url:"permanently"`
|
||||
}
|
||||
|
||||
func (irq DeleteRequest) Validate() error {
|
||||
if irq.ImageId == 0 {
|
||||
return errors.New("validation-error: field ImageId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/image/delete"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := i.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
Permanently bool `url:"permanently"`
|
||||
}
|
||||
|
||||
func (irq DeleteRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/image/delete"
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
@@ -1,54 +1,44 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
ImageId uint64 `url:"imageId"`
|
||||
ShowAll bool `url:"show_all,omitempty"`
|
||||
}
|
||||
|
||||
func (irq GetRequest) Validate() error {
|
||||
if irq.ImageId == 0 {
|
||||
return errors.New("validation-error: field ImageId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*ImageExtend, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/image/get"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := i.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
imageInfo := &ImageExtend{}
|
||||
|
||||
err = json.Unmarshal(res, imageInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return imageInfo, nil
|
||||
}
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
ShowAll bool `url:"show_all,omitempty"`
|
||||
}
|
||||
|
||||
func (irq GetRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Get(ctx context.Context, req GetRequest) (*ImageExtend, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/image/get"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
imageInfo := &ImageExtend{}
|
||||
|
||||
err = json.Unmarshal(res, imageInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return imageInfo, nil
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
)
|
||||
|
||||
type Image struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *Image {
|
||||
return &Image{
|
||||
client,
|
||||
}
|
||||
}
|
||||
package image
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
)
|
||||
|
||||
type Image struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *Image {
|
||||
return &Image{
|
||||
client,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,46 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type LinkRequest struct {
|
||||
ImageId uint64 `url:"imageId"`
|
||||
TargetId uint64 `url:"targetId"`
|
||||
}
|
||||
|
||||
func (irq LinkRequest) Validate() error {
|
||||
if irq.ImageId == 0 {
|
||||
return errors.New("validation-error: field ImageId can not be empty or equal to 0")
|
||||
}
|
||||
if irq.TargetId == 0 {
|
||||
return errors.New("validation-error: field TargetId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Link(ctx context.Context, req LinkRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/image/link"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := i.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type LinkRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
TargetID uint64 `url:"targetId"`
|
||||
}
|
||||
|
||||
func (irq LinkRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID can not be empty or equal to 0")
|
||||
}
|
||||
if irq.TargetID == 0 {
|
||||
return errors.New("validation-error: field TargetID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Link(ctx context.Context, req LinkRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/image/link"
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
@@ -1,42 +1,32 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
AccountId uint64 `json:"accountId"`
|
||||
Page uint64 `json:"page"`
|
||||
Size uint64 `json:"size"`
|
||||
}
|
||||
|
||||
func (i Image) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (ImageList, error) {
|
||||
|
||||
url := "/image/list"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := i.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
imageList := ImageList{}
|
||||
|
||||
err = json.Unmarshal(res, &imageList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return imageList, nil
|
||||
}
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
Page uint64 `json:"page"`
|
||||
Size uint64 `json:"size"`
|
||||
}
|
||||
|
||||
func (i Image) List(ctx context.Context, req ListRequest) (ImageList, error) {
|
||||
|
||||
url := "/cloudapi/image/list"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
imageList := ImageList{}
|
||||
|
||||
err = json.Unmarshal(res, &imageList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return imageList, nil
|
||||
}
|
||||
|
||||
@@ -1,68 +1,68 @@
|
||||
package image
|
||||
|
||||
type ImageRecord struct {
|
||||
AccountId uint64 `json:"accountId"`
|
||||
Architecture string `json:"architecture"`
|
||||
BootType string `json:"bootType"`
|
||||
Bootable bool `json:"bootable"`
|
||||
CDROM bool `json:"cdrom"`
|
||||
Description string `json:"desc"`
|
||||
Drivers []string `json:"drivers"`
|
||||
HotResize bool `json:"hotResize"`
|
||||
ID uint64 `json:"id"`
|
||||
LinkTo uint64 `json:"linkTo"`
|
||||
Name string `json:"name"`
|
||||
Pool string `json:"pool"`
|
||||
SepId uint64 `json:"sepId"`
|
||||
Size uint64 `json:"size"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
Username string `json:"username"`
|
||||
Virtual bool `json:"virtual"`
|
||||
}
|
||||
|
||||
type ImageList []ImageRecord
|
||||
|
||||
type History struct {
|
||||
GUID string `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
type ImageExtend struct {
|
||||
UNCPath string `json:"UNCPath"`
|
||||
CKey string `json:"_ckey"`
|
||||
AccountId uint64 `json:"accountId"`
|
||||
Acl interface{} `json:"acl"`
|
||||
Architecture string `json:"architecture"`
|
||||
BootType string `json:"bootType"`
|
||||
Bootable bool `json:"bootable"`
|
||||
ComputeCiId uint64 `json:"computeciId"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Description string `json:"desc"`
|
||||
Drivers []string `json:"drivers"`
|
||||
Enabled bool `json:"enabled"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
History []History `json:"history"`
|
||||
HotResize bool `json:"hotResize"`
|
||||
ID uint64 `json:"id"`
|
||||
LastModified uint64 `json:"lastModified"`
|
||||
LinkTo uint64 `json:"linkTo"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
Password string `json:"password"`
|
||||
Pool string `json:"pool"`
|
||||
ProviderName string `json:"provider_name"`
|
||||
PurgeAttempts int `json:"purgeAttempts"`
|
||||
ResId string `json:"resId"`
|
||||
RescueCD bool `json:"rescuecd"`
|
||||
SepId uint64 `json:"sepId"`
|
||||
SharedWith []int `json:"sharedWith"`
|
||||
Size uint64 `json:"size"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
Type string `json:"type"`
|
||||
Username string `json:"username"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
package image
|
||||
|
||||
type ImageRecord struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
Architecture string `json:"architecture"`
|
||||
BootType string `json:"bootType"`
|
||||
Bootable bool `json:"bootable"`
|
||||
CDROM bool `json:"cdrom"`
|
||||
Description string `json:"desc"`
|
||||
Drivers []string `json:"drivers"`
|
||||
HotResize bool `json:"hotResize"`
|
||||
ID uint64 `json:"id"`
|
||||
LinkTo uint64 `json:"linkTo"`
|
||||
Name string `json:"name"`
|
||||
Pool string `json:"pool"`
|
||||
SepID uint64 `json:"sepId"`
|
||||
Size uint64 `json:"size"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
Username string `json:"username"`
|
||||
Virtual bool `json:"virtual"`
|
||||
}
|
||||
|
||||
type ImageList []ImageRecord
|
||||
|
||||
type History struct {
|
||||
GUID string `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
type ImageExtend struct {
|
||||
UNCPath string `json:"UNCPath"`
|
||||
CKey string `json:"_ckey"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
ACL interface{} `json:"acl"`
|
||||
Architecture string `json:"architecture"`
|
||||
BootType string `json:"bootType"`
|
||||
Bootable bool `json:"bootable"`
|
||||
ComputeCiID uint64 `json:"computeciId"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Description string `json:"desc"`
|
||||
Drivers []string `json:"drivers"`
|
||||
Enabled bool `json:"enabled"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
History []History `json:"history"`
|
||||
HotResize bool `json:"hotResize"`
|
||||
ID uint64 `json:"id"`
|
||||
LastModified uint64 `json:"lastModified"`
|
||||
LinkTo uint64 `json:"linkTo"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
Password string `json:"password"`
|
||||
Pool string `json:"pool"`
|
||||
ProviderName string `json:"provider_name"`
|
||||
PurgeAttempts uint64 `json:"purgeAttempts"`
|
||||
ResID string `json:"resId"`
|
||||
RescueCD bool `json:"rescuecd"`
|
||||
SepID uint64 `json:"sepId"`
|
||||
SharedWith []uint64 `json:"sharedWith"`
|
||||
Size uint64 `json:"size"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
Type string `json:"type"`
|
||||
Username string `json:"username"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
@@ -1,58 +1,47 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type RenameRequest struct {
|
||||
ImageId uint64 `url:"imageId"`
|
||||
Name string `url:"name"`
|
||||
}
|
||||
|
||||
func (irq RenameRequest) Validate() error {
|
||||
if irq.ImageId == 0 {
|
||||
return errors.New("validation-error: field ImageId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if irq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Rename(ctx context.Context, req RenameRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/image/rename"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := i.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type RenameRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
Name string `url:"name"`
|
||||
}
|
||||
|
||||
func (irq RenameRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if irq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Rename(ctx context.Context, req RenameRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/image/rename"
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user