This commit is contained in:
stSolo
2022-12-22 17:56:47 +03:00
parent 8712561853
commit d4b1ab7133
672 changed files with 28509 additions and 4419 deletions

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for set compute CI
type ComputeCISetRequest struct {
ImageID uint64 `url:"imageId"`
// ID of the image
// Required: true
ImageID uint64 `url:"imageId"`
// ID of the compute CI
// Required: true
ComputeCIID uint64 `url:"computeciId"`
}
func (irq ComputeCISetRequest) Validate() error {
func (irq ComputeCISetRequest) validate() error {
if irq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
@@ -23,8 +29,9 @@ func (irq ComputeCISetRequest) Validate() error {
return nil
}
// ComputeCISet set compute CI ID for image
func (i Image) ComputeCISet(ctx context.Context, req ComputeCISetRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for unset compute CI
type ComputeCIUnsetRequest struct {
// ID of the image
// Required: true
ImageID uint64 `url:"imageId"`
}
func (irq ComputeCIUnsetRequest) Validate() error {
func (irq ComputeCIUnsetRequest) validate() error {
if irq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
@@ -19,8 +22,9 @@ func (irq ComputeCIUnsetRequest) Validate() error {
return nil
}
// ComputeCIUnset unset compute CI ID from image
func (i Image) ComputeCIUnset(ctx context.Context, req ComputeCIUnsetRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -3,25 +3,60 @@ package image
import (
"context"
"errors"
"github.com/rudecs/decort-sdk/internal/validators"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for create CD-ROM image
type CreateCDROMImageRequest struct {
Name string `url:"name"`
URL string `url:"url"`
GID uint64 `url:"gid"`
AccountID uint64 `url:"accountId,omitempty"`
SepID uint64 `url:"sep_id,omitempty"`
PoolName string `url:"pool_name,omitempty"`
UsernameDL string `url:"usernameDL,omitempty"`
PasswordDl string `url:"passwordDL,omitempty"`
Architecture string `url:"architecture,omitempty"`
Drivers []string `url:"drivers"`
// Name of the rescue disk
// Required: true
Name string `url:"name"`
// URL where to download ISO from
// Required: true
URL string `url:"url"`
// Grid (platform) ID where this CD-ROM image should be create in
// Required: true
GID uint64 `url:"gid"`
// Account ID to make the image exclusive
// Required: false
AccountID uint64 `url:"accountId,omitempty"`
// Storage endpoint provider ID for place rescue CD
// Required: false
SEPID uint64 `url:"sep_id,omitempty"`
// Pool for place rescue CD
// Required: false
PoolName string `url:"pool_name,omitempty"`
// Username for remote media download
// Required: false
UsernameDL string `url:"usernameDL,omitempty"`
// Password for remote media download
// Required: false
PasswordDl string `url:"passwordDL,omitempty"`
// Binary architecture of this image
// Should be one of:
// - X86_64
// - PPC64_LE
// Required: false
Architecture string `url:"architecture,omitempty"`
// List of types of compute suitable for image.
// Example: [ "KVM_X86" ]
// Required: true
Drivers []string `url:"drivers"`
}
func (irq CreateCDROMImageRequest) Validate() error {
func (irq CreateCDROMImageRequest) validate() error {
if irq.Name == "" {
return errors.New("validation-error: field Name must be set")
}
@@ -31,11 +66,9 @@ func (irq CreateCDROMImageRequest) Validate() error {
if irq.GID == 0 {
return errors.New("validation-error: field GID must be set")
}
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 {
@@ -46,8 +79,9 @@ func (irq CreateCDROMImageRequest) Validate() error {
return nil
}
// CreateCDROMImage creates CD-ROM image from an ISO identified by URL
func (i Image) CreateCDROMImage(ctx context.Context, req CreateCDROMImageRequest) (uint64, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return 0, err
}

View File

@@ -3,31 +3,91 @@ package image
import (
"context"
"errors"
"github.com/rudecs/decort-sdk/internal/validators"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for create image
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"`
PoolName string `url:"poolName,omitempty"`
Architecture string `url:"architecture,omitempty"`
Drivers []string `url:"drivers,omitempty"`
Bootable bool `url:"bootable,omitempty"`
// Name of the rescue disk
// Required: true
Name string `url:"name"`
// URL where to download media from
// Required: true
URL string `url:"url"`
// Grid (platform) ID where this template should be create in
// Required: true
GID uint64 `url:"gid"`
// Boot type of image
// Should be one of:
// - bios
// - UEFI
// Required: true
BootType string `url:"boottype"`
// Image type
// Should be one of:
// - linux
// - windows
// - or other
// Required: true
ImageType string `url:"imagetype"`
// Does this machine supports hot resize
// Required: false
HotResize bool `url:"hotresize,omitempty"`
// Optional username for the image
// Required: false
Username string `url:"username,omitempty"`
// Optional 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"`
// Username for upload binary media
// Required: false
UsernameDL string `url:"usernameDL,omitempty"`
// Password for upload binary media
// Required: false
PasswordDL string `url:"passwordDL,omitempty"`
// Storage endpoint provider ID
// Required: false
SEPID uint64 `url:"sepId,omitempty"`
// Pool for image create
// Required: false
PoolName string `url:"poolName,omitempty"`
// Binary architecture of this image
// Should be one of:
// - X86_64
// - PPC64_LE
// Required: false
Architecture string `url:"architecture,omitempty"`
// List of types of compute suitable for image
// Example: [ "KVM_X86" ]
// Required: true
Drivers []string `url:"drivers"`
// Bootable image or not
// Required: false
Bootable bool `url:"bootable,omitempty"`
}
func (irq CreateRequest) Validate() error {
func (irq CreateRequest) validate() error {
if irq.Name == "" {
return errors.New("validation-error: field Name must be set")
}
@@ -43,7 +103,6 @@ func (irq CreateRequest) Validate() error {
if irq.ImageType == "" {
return errors.New("validation-error: field ImageType must be set")
}
validate := validators.StringInSlice(irq.BootType, []string{"bios", "uefi"})
if !validate {
return errors.New("validation-error: field BootType can be bios or uefi")
@@ -56,8 +115,9 @@ func (irq CreateRequest) Validate() error {
return nil
}
// CreateImage creates image from a media identified by URL
func (i Image) CreateImage(ctx context.Context, req CreateRequest) (uint64, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return 0, err
}

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for create virtual image
type CreateVirtualRequest struct {
Name string `url:"name"`
// Name of the virtual image to create
// Required: true
Name string `url:"name"`
// ID of real image to link this virtual image to upon creation
// Required: true
TargetID uint64 `url:"targetId"`
}
func (irq CreateVirtualRequest) Validate() error {
func (irq CreateVirtualRequest) validate() error {
if irq.Name == "" {
return errors.New("validation-error: field Name must be set")
}
@@ -23,8 +29,9 @@ func (irq CreateVirtualRequest) Validate() error {
return nil
}
// CreateVirtual creates virtual image
func (i Image) CreateVirtual(ctx context.Context, req CreateVirtualRequest) (uint64, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return 0, err
}

View File

@@ -7,13 +7,22 @@ import (
"strconv"
)
// Request struct for delete image
type DeleteRequest struct {
ImageID uint64 `url:"imageId"`
Reason string `url:"reason"`
Permanently bool `url:"permanently,omitempty"`
// ID of the image to delete
// Required: true
ImageID uint64 `url:"imageId"`
// Reason for action
// Required: true
Reason string `url:"reason"`
// Whether to completely delete the image
// Required: false
Permanently bool `url:"permanently,omitempty"`
}
func (irq DeleteRequest) Validate() error {
func (irq DeleteRequest) validate() error {
if irq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
@@ -24,8 +33,9 @@ func (irq DeleteRequest) Validate() error {
return nil
}
// Delete deletes image by ID
func (i Image) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for delete CD-ROM image
type DeleteCDROMImageRequest struct {
ImageID uint64 `url:"imageId"`
Permanently bool `url:"permanently"`
// ID of the CD-ROM image to delete
// Required: true
ImageID uint64 `url:"imageId"`
// Whether to completely delete the CD-ROM image, needs to be unused
// Required: true
Permanently bool `url:"permanently"`
}
func (irq DeleteCDROMImageRequest) Validate() error {
func (irq DeleteCDROMImageRequest) validate() error {
if irq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
@@ -20,8 +26,9 @@ func (irq DeleteCDROMImageRequest) Validate() error {
return nil
}
// DeleteCDROMImage delete a CD-ROM image
func (i Image) DeleteCDROMImage(ctx context.Context, req DeleteCDROMImageRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,25 +7,32 @@ import (
"strconv"
)
// Request struct for delete images
type DeleteImagesRequest struct {
ImageIDs []uint64 `url:"imageIds"`
Reason string `url:"reason"`
Permanently bool `url:"permanently"`
// List of images to be deleted
// Required: true
ImageIDs []uint64 `url:"imageIds"`
// Reason for action
// Required: true
Reason string `url:"reason,omitempty"`
// Whether to completely delete the images
// Required: true
Permanently bool `url:"permanently,omitempty"`
}
func (irq DeleteImagesRequest) Validate() error {
func (irq DeleteImagesRequest) validate() error {
if len(irq.ImageIDs) == 0 {
return errors.New("validation-error: field ImageIDs must be set")
}
if irq.Reason == "" {
return errors.New("validation-error: field Reason must be set")
}
return nil
}
// DeleteImages deletes images
func (i Image) DeleteImages(ctx context.Context, req DeleteImagesRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for disable image
type DisableRequest struct {
// ID of image to be disabled
// Required: true
ImageID uint64 `url:"imageId"`
}
func (irq DisableRequest) Validate() error {
func (irq DisableRequest) validate() error {
if irq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
@@ -19,8 +22,9 @@ func (irq DisableRequest) Validate() error {
return nil
}
// Disable disables image
func (i Image) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,17 +7,38 @@ import (
"strconv"
)
// Request struct for edit image
type EditRequest struct {
ImageID uint64 `url:"imageId"`
Name string `url:"name,omitempty"`
Username string `url:"username,omitempty"`
Password string `url:"password,omitempty"`
// 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"`
HotResize bool `url:"hotresize,omitempty"`
Bootable bool `url:"bootable,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 {
func (irq EditRequest) validate() error {
if irq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
@@ -25,8 +46,9 @@ func (irq EditRequest) Validate() error {
return nil
}
// Edit edits an existing image
func (i Image) Edit(ctx context.Context, req EditRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for enable image
type EnableRequest struct {
// ID of image to be enabled
// Required: true
ImageID uint64 `url:"imageId"`
}
func (irq EnableRequest) Validate() error {
func (irq EnableRequest) validate() error {
if irq.ImageID == 0 {
return errors.New("validation-error: field ImageID must br set")
}
@@ -19,8 +22,9 @@ func (irq EnableRequest) Validate() error {
return nil
}
// Enable enables image
func (i Image) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -38,4 +42,4 @@ func (i Image) Enable(ctx context.Context, req EnableRequest) (bool, error) {
}
return result, nil
}
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get image details
type GetRequest struct {
// ID of image
// Required: true
ImageID uint64 `url:"imageId"`
}
func (irq GetRequest) Validate() error {
func (irq GetRequest) validate() error {
if irq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
@@ -19,25 +22,26 @@ func (irq GetRequest) Validate() error {
return nil
}
func (i Image) Get(ctx context.Context, req GetRequest) (*ImageRecord, error) {
err := req.Validate()
// Get get image details by ID
func (i Image) Get(ctx context.Context, req GetRequest) (*RecordImage, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/image/get"
result := ImageRecord{}
info := RecordImage{}
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
err = json.Unmarshal(res, &result)
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &result, nil
return &info, nil
}

View File

@@ -1,11 +1,14 @@
// Lists all the images. A image is a template which can be used to deploy machines
package image
import "github.com/rudecs/decort-sdk/interfaces"
// Structure for creating request to image
type Image struct {
client interfaces.Caller
}
// Builder for image endpoint
func New(client interfaces.Caller) *Image {
return &Image{
client: client,

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for link virtual image to another image
type LinkRequest struct {
ImageID uint64 `url:"imageId"`
// ID of the virtual image
// Required: true
ImageID uint64 `url:"imageId"`
// ID of real image to link this virtual image to
// Required: true
TargetID uint64 `url:"targetId"`
}
func (irq LinkRequest) Validate() error {
func (irq LinkRequest) validate() error {
if irq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
@@ -23,8 +29,9 @@ func (irq LinkRequest) Validate() error {
return nil
}
// Link links virtual image to another image in the platform
func (i Image) Link(ctx context.Context, req LinkRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -42,4 +49,4 @@ func (i Image) Link(ctx context.Context, req LinkRequest) (bool, error) {
}
return result, nil
}
}

View File

@@ -6,13 +6,26 @@ import (
"net/http"
)
// Request struct for get list available images
type ListRequest struct {
SepID uint64 `url:"sepId,omitempty"`
// Filter images by storage endpoint provider ID
// Required: false
SepID uint64 `url:"sepId,omitempty"`
// Filter images by account ID availability
// Required: false
SharedWith uint64 `url:"sharedWith,omitempty"`
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty"`
}
// List gets list of information about images
func (i Image) List(ctx context.Context, req ListRequest) (ListImages, error) {
url := "/cloudbroker/image/list"

View File

@@ -7,13 +7,22 @@ import (
"net/http"
)
// Request struct for get list stack
type ListStacksRequest struct {
// Image ID
// Required: true
ImageID uint64 `url:"imageId"`
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty"`
}
func (irq ListStacksRequest) Validate() error {
func (irq ListStacksRequest) validate() error {
if irq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
@@ -21,8 +30,9 @@ func (irq ListStacksRequest) Validate() error {
return nil
}
// ListStacks gets list stack by image ID
func (i Image) ListStacks(ctx context.Context, req ListStacksRequest) (ListStacks, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return nil, err
}

View File

@@ -1,82 +1,226 @@
package image
type ImageRecord struct {
UNCPath string `json:"UNCPath"`
CKey string `json:"_ckey"`
Meta []interface{} `json:"_meta"`
AccountID uint64 `json:"accountId"`
ACL []ACL `json:"acl"`
Architecture string `json:"architecture"`
BootType string `json:"bootType"`
Bootable bool `json:"bootable"`
ComputeCIID uint64 `json:"computeciId"`
DeletedTime uint64 `json:"deletedTime"`
Desc 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"`
ReferenceID string `json:"referenceId"`
ResID string `json:"resId"`
ResName string `json:"resName"`
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"`
URL string `json:"url"`
Username string `json:"username"`
Version string `json:"version"`
Virtual bool `json:"virtual"`
// Detailed information about image
type RecordImage struct {
// UNC path
UNCPath string `json:"UNCPath"`
// CKey
CKey string `json:"_ckey"`
// Meta
Meta []interface{} `json:"_meta"`
// Account ID
AccountID uint64 `json:"accountId"`
// Access Control List
ACL ListACL `json:"acl"`
// Architecture
Architecture string `json:"architecture"`
// Boot type
BootType string `json:"bootType"`
// Bootable
Bootable bool `json:"bootable"`
// Compute CI ID
ComputeCIID uint64 `json:"computeciId"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"desc"`
// Drivers
Drivers []string `json:"drivers"`
// Enabled
Enabled bool `json:"enabled"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// List history
History ListHistory `json:"history"`
// Hot resize
HotResize bool `json:"hotResize"`
// ID
ID uint64 `json:"id"`
// Last modified
LastModified uint64 `json:"lastModified"`
// Link to
LinkTo uint64 `json:"linkTo"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// Password
Password string `json:"password"`
// Pool
Pool string `json:"pool"`
// Provider name
ProviderName string `json:"provider_name"`
// Purge attempts
PurgeAttempts uint64 `json:"purgeAttempts"`
// Reference ID
ReferenceID string `json:"referenceId"`
// Resource ID
ResID string `json:"resId"`
// Resource name
ResName string `json:"resName"`
// Rescue CD
RescueCD bool `json:"rescuecd"`
// SEP ID
SEPID uint64 `json:"sepId"`
// List shared with
SharedWith []uint64 `json:"sharedWith"`
// Size
Size uint64 `json:"size"`
// Status
Status string `json:"status"`
// Tech status
TechStatus string `json:"techStatus"`
// Type
Type string `json:"type"`
// URL
URL string `json:"url"`
// Username
Username string `json:"username"`
// Version
Version string `json:"version"`
// Virtual
Virtual bool `json:"virtual"`
}
type ListImages []ImageRecord
// List images
type ListImages []RecordImage
// Access Control List
type ACL struct {
Explicit bool `json:"explicit"`
GUID string `json:"guid"`
Right string `json:"right"`
Status string `json:"status"`
Type string `json:"type"`
// Explicit
Explicit bool `json:"explicit"`
// GUID
GUID string `json:"guid"`
// Right
Right string `json:"right"`
// Status
Status string `json:"status"`
// Type
Type string `json:"type"`
// User group ID
UserGroupID string `json:"userGroupId"`
}
// List ACL
type ListACL []ACL
// History information
type History struct {
GUID string `json:"guid"`
ID uint64 `json:"id"`
// GUID
GUID string `json:"guid"`
// ID
ID uint64 `json:"id"`
// Timestamp
Timestamp uint64 `json:"timestamp"`
}
// List history
type ListHistory []History
// List stacks
type ListStacks []struct {
CKey string `json:"_ckey"`
Meta []interface{} `json:"_meta"`
APIURL string `json:"apiUrl"`
APIKey string `json:"apikey"`
AppID string `json:"appId"`
Desc string `json:"desc"`
Drivers []string `json:"drivers"`
Eco interface{} `json:"eco"`
Error uint64 `json:"error"`
GID uint64 `json:"gid"`
GUID uint64 `json:"guid"`
ID uint64 `json:"id"`
Images []uint64 `json:"images"`
Login string `json:"login"`
Name string `json:"name"`
Passwd string `json:"passwd"`
ReferenceID string `json:"referenceId"`
Status string `json:"status"`
Type string `json:"type"`
// CKey
CKey string `json:"_ckey"`
// Meta
Meta []interface{} `json:"_meta"`
// API URL
APIURL string `json:"apiUrl"`
// API key
APIKey string `json:"apikey"`
// App ID
AppID string `json:"appId"`
// Description
Description string `json:"desc"`
// Drivers
Drivers []string `json:"drivers"`
// Eco
Eco interface{} `json:"eco"`
// Error
Error uint64 `json:"error"`
// Grid ID
GID uint64 `json:"gid"`
// GID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// List image IDs
Images []uint64 `json:"images"`
// Login
Login string `json:"login"`
// Name
Name string `json:"name"`
// Password
Password string `json:"passwd"`
// Reference ID
ReferenceID string `json:"referenceId"`
// Status
Status string `json:"status"`
// Type
Type string `json:"type"`
}

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for rename image
type RenameRequest struct {
// ID of the virtual image to rename
// Required: true
ImageID uint64 `url:"imageId"`
Name string `url:"name"`
// New name
// Required: true
Name string `url:"name"`
}
func (irq RenameRequest) Validate() error {
func (irq RenameRequest) validate() error {
if irq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
@@ -23,8 +29,9 @@ func (irq RenameRequest) Validate() error {
return nil
}
// Rename renames image by ID
func (i Image) Rename(ctx context.Context, req RenameRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -42,4 +49,4 @@ func (i Image) Rename(ctx context.Context, req RenameRequest) (bool, error) {
}
return result, nil
}
}

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for share image
type ShareRequest struct {
ImageId uint64 `url:"imageId"`
// ID of the image to share
// Required: true
ImageId uint64 `url:"imageId"`
// List of account IDs
// Required: true
AccountIDs []uint64 `url:"accounts"`
}
func (irq ShareRequest) Validate() error {
func (irq ShareRequest) validate() error {
if irq.ImageId == 0 {
return errors.New("validation-error: field ImageID must be set")
}
@@ -23,8 +29,9 @@ func (irq ShareRequest) Validate() error {
return nil
}
// Share shares image with accounts
func (i Image) Share(ctx context.Context, req ShareRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -3,31 +3,91 @@ package image
import (
"context"
"errors"
"github.com/rudecs/decort-sdk/internal/validators"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for sync create image
type SyncCreateRequest 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"`
PoolName string `url:"poolName,omitempty"`
Architecture string `url:"architecture,omitempty"`
Drivers []string `url:"drivers"`
Bootable bool `url:"bootable,omitempty"`
// Name of the rescue disk
// Required: true
Name string `url:"name"`
// URL where to download media from
// Required: true
URL string `url:"url"`
// Grid (platform) ID where this template should be create in
// Required: true
GID uint64 `url:"gid"`
// Boot type of image
// Should be one of:
// - bios
// - UEFI
// Required: true
BootType string `url:"boottype"`
// Image type
// Should be one of:
// - linux
// - windows
// - or other
// Required: true
ImageType string `url:"imagetype"`
// Does this machine supports hot resize
// Required: false
HotResize bool `url:"hotresize,omitempty"`
// Optional username for the image
// Required: false
Username string `url:"username,omitempty"`
// Optional 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"`
// Username for upload binary media
// Required: false
UsernameDL string `url:"usernameDL,omitempty"`
// Password for upload binary media
// Required: false
PasswordDL string `url:"passwordDL,omitempty"`
// Storage endpoint provider ID
// Required: false
SEPID uint64 `url:"sepId,omitempty"`
// Pool for image create
// Required: false
PoolName string `url:"poolName,omitempty"`
// Binary architecture of this image
// Should be one of:
// - X86_64
// - PPC64_LE
// Required: false
Architecture string `url:"architecture,omitempty"`
// List of types of compute suitable for image
// Example: [ "KVM_X86" ]
// Required: true
Drivers []string `url:"drivers"`
// Bootable image or not
// Required: false
Bootable bool `url:"bootable,omitempty"`
}
func (irq SyncCreateRequest) Validate() error {
func (irq SyncCreateRequest) validate() error {
if irq.Name == "" {
return errors.New("validation-error: field Name must be set")
}
@@ -43,7 +103,6 @@ func (irq SyncCreateRequest) Validate() error {
if irq.ImageType == "" {
return errors.New("validation-error: field ImageType must be set")
}
validate := validators.StringInSlice(irq.BootType, []string{"bios", "uefi"})
if !validate {
return errors.New("validation-error: field BootType can be bios or uefi")
@@ -52,11 +111,9 @@ func (irq SyncCreateRequest) Validate() error {
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 {
@@ -67,8 +124,9 @@ func (irq SyncCreateRequest) Validate() error {
return nil
}
// SyncCreate creates image from a media identified by URL (in synchronous mode)
func (i Image) SyncCreate(ctx context.Context, req SyncCreateRequest) (uint64, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return 0, err
}
@@ -86,4 +144,4 @@ func (i Image) SyncCreate(ctx context.Context, req SyncCreateRequest) (uint64, e
}
return result, nil
}
}

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for update nodes
type UpdateNodesRequest struct {
ImageID uint64 `url:"imageId"`
// Image ID
// Required: true
ImageID uint64 `url:"imageId"`
// List of stacks
// Required: false
EnabledStacks []uint64 `url:"enabledStacks,omitempty"`
}
func (irq UpdateNodesRequest) Validate() error {
func (irq UpdateNodesRequest) validate() error {
if irq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
@@ -20,8 +26,9 @@ func (irq UpdateNodesRequest) Validate() error {
return nil
}
// UpdateNodes udates image availability on nodes
func (i Image) UpdateNodes(ctx context.Context, req UpdateNodesRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}