v1.12.0
This commit is contained in:
@@ -2,6 +2,7 @@ package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -72,12 +73,6 @@ 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
|
||||
@@ -88,6 +83,11 @@ type CreateRequest struct {
|
||||
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)
|
||||
@@ -109,3 +109,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/create"
|
||||
|
||||
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