v12.0.0
This commit is contained in:
@@ -2,15 +2,16 @@ package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v11/internal/validators"
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
|
||||
)
|
||||
|
||||
// CreateRequest struct to create image
|
||||
type CreateRequest struct {
|
||||
// Name of the rescue disk
|
||||
// Name of the image
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
@@ -33,6 +34,10 @@ type CreateRequest struct {
|
||||
// Required: true
|
||||
ImageType string `url:"imagetype" json:"imagetype" validate:"required,imageType"`
|
||||
|
||||
// ID of the chosen storage policy
|
||||
// Required: true
|
||||
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||
|
||||
// Select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming
|
||||
// Should be:
|
||||
// - eth
|
||||
@@ -72,22 +77,16 @@ type CreateRequest struct {
|
||||
// Required: false
|
||||
PoolName string `url:"poolName,omitempty" json:"poolName,omitempty"`
|
||||
|
||||
// Binary architecture of this image
|
||||
// Should be one of:
|
||||
// - X86_64
|
||||
// Required: false
|
||||
Architecture string `url:"architecture,omitempty" json:"architecture,omitempty"`
|
||||
|
||||
// List of types of compute suitable for image
|
||||
// Example: [ "KVM_X86" ]
|
||||
// Required: required
|
||||
Drivers []string `url:"drivers" json:"drivers" validate:"min=1,max=2,imageDrivers"`
|
||||
|
||||
// Bootable image or not
|
||||
// Required: false
|
||||
Bootable bool `url:"bootable,omitempty" json:"bootable,omitempty"`
|
||||
}
|
||||
|
||||
type asyncWrapperCreateRequest struct {
|
||||
CreateRequest
|
||||
AsyncMode bool `url:"asyncMode"`
|
||||
}
|
||||
|
||||
// CreateImage creates image from a media identified by URL
|
||||
func (i Image) CreateImage(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
@@ -97,7 +96,9 @@ func (i Image) CreateImage(ctx context.Context, req CreateRequest) (uint64, erro
|
||||
|
||||
url := "/cloudbroker/image/createImage"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
syncReq := asyncWrapperCreateRequest{CreateRequest: req, AsyncMode: false}
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, syncReq)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -109,3 +110,29 @@ func (i Image) CreateImage(ctx context.Context, req CreateRequest) (uint64, erro
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// AsyncCreate creates image from a media identified by URL in async mode
|
||||
func (i Image) AsyncCreateImage(ctx context.Context, req CreateRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/createImage"
|
||||
|
||||
asyncReq := asyncWrapperCreateRequest{CreateRequest: req, AsyncMode: true}
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, asyncReq)
|
||||
if err != nil {
|
||||
return " ", err
|
||||
}
|
||||
|
||||
var taskID string
|
||||
|
||||
err = json.Unmarshal(res, &taskID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return taskID, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user