v9.0.0
This commit is contained in:
104
pkg/cloudapi/image/create.go
Normal file
104
pkg/cloudapi/image/create.go
Normal file
@@ -0,0 +1,104 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// CreateRequest struct to create image
|
||||
type CreateRequest struct {
|
||||
// Name of the rescue disk
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// URL where to download media from
|
||||
// Required: true
|
||||
URL string `url:"url" json:"url" validate:"required,url"`
|
||||
|
||||
// Boot type of image bios or UEFI
|
||||
// Required: true
|
||||
BootType string `url:"boottype" json:"boottype" validate:"required,imageBootType"`
|
||||
|
||||
// Image type
|
||||
// Should be:
|
||||
// - linux
|
||||
// - windows
|
||||
// - or other
|
||||
// Required: true
|
||||
ImageType string `url:"imagetype" json:"imagetype" validate:"required,imageType"`
|
||||
|
||||
// Account ID to make the image exclusive
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// Select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming
|
||||
// Should be:
|
||||
// - eth
|
||||
// - ens (default value)
|
||||
// Required: false
|
||||
NetworkInterfaceNaming string `url:"networkInterfaceNaming,omitempty" json:"networkInterfaceNaming,omitempty" validate:"omitempty,networkInterfaceNaming"`
|
||||
|
||||
// Does this machine supports hot resize
|
||||
// Required: false
|
||||
HotResize bool `url:"hotresize,omitempty" json:"hotresize,omitempty"`
|
||||
|
||||
// Optional username for the image
|
||||
// Required: false
|
||||
Username string `url:"username,omitempty" json:"username,omitempty"`
|
||||
|
||||
// Optional password for the image
|
||||
// Required: false
|
||||
Password string `url:"password,omitempty" json:"password,omitempty"`
|
||||
|
||||
// Username for upload binary media
|
||||
// Required: false
|
||||
UsernameDL string `url:"usernameDL,omitempty" json:"usernameDL,omitempty"`
|
||||
|
||||
// Password for upload binary media
|
||||
// Required: false
|
||||
PasswordDL string `url:"passwordDL,omitempty" json:"passwordDL,omitempty"`
|
||||
|
||||
// Storage endpoint provider ID
|
||||
// Required: false
|
||||
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||
|
||||
// Pool for image create
|
||||
// Required: false
|
||||
Pool string `url:"poolName,omitempty" json:"poolName,omitempty"`
|
||||
|
||||
// Binary architecture of this image
|
||||
// Should be:
|
||||
// - X86_64
|
||||
// Required: false
|
||||
Architecture string `url:"architecture,omitempty" json:"architecture,omitempty" validate:"omitempty,imageArchitecture"`
|
||||
|
||||
// List of types of compute suitable for image
|
||||
// Example: [ "KVM_X86" ]
|
||||
// Required: true
|
||||
Drivers []string `url:"drivers" json:"drivers" validate:"min=1,max=2,imageDrivers"`
|
||||
}
|
||||
|
||||
// Create creates image from a media identified by URL
|
||||
func (i Image) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(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
|
||||
}
|
||||
Reference in New Issue
Block a user