v1.0.0
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user