You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
decort-golang-sdk/pkg/cloudbroker/kvmppc/create.go

136 lines
3.0 KiB

package kvmppc
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for create KVM PowerPC VM
type CreateRequest struct {
// ID of the resource group, which will own this VM
// Required: true
RGID uint64 `url:"rgId"`
// Name of this VM.
// Must be unique among all VMs (including those in DELETED state) in target resource group
// Required: true
Name string `url:"name"`
// Number CPUs to allocate to this VM
// Required: true
CPU uint64 `url:"cpu"`
// Volume of RAM in MB to allocate to this VM
// Required: true
RAM uint64 `url:"ram"`
// ID of the OS image to base this VM on;
// Could be boot disk image or CD-ROM image
// Required: true
ImageID uint64 `url:"imageId"`
// Size of the boot disk in GB
// Required: false
BootDisk uint64 `url:"bootDisk,omitempty"`
// ID of SEP to create boot disk on.
// Uses images SEP ID if not set
// Required: false
SEPID uint64 `url:"sepId,omitempty"`
// Pool to use if SEP ID is set, can be also empty if needed to be chosen by system
// Required: false
Pool string `url:"pool,omitempty"`
// Network type
// Should be one of:
// - VINS
// - EXTNET
// - NONE
// Required: false
NetType string `url:"netType,omitempty"`
// Network ID for connect to,
// for EXTNET - external network ID,
// for VINS - VINS ID,
// when network type is not "NONE"
// Required: false
NetID uint64 `url:"netId,omitempty"`
// IP address to assign to this VM when connecting to the specified network
// Required: false
IPAddr string `url:"ipAddr,omitempty"`
// Input data for cloud-init facility
// Required: false
Userdata string `url:"userdata,omitempty"`
// Text description of this VM
// Required: false
Description string `url:"desc,omitempty"`
// Start VM upon success
// Required: false
Start bool `url:"start,omitempty"`
// Stack ID
// Required: false
StackID uint64 `url:"stackId,omitempty"`
// System name
// Required: false
IS string `url:"IS,omitempty"`
// Compute purpose
// Required: false
IPAType string `url:"ipaType,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (krq CreateRequest) validate() error {
if krq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if krq.Name == "" {
return errors.New("validation-error: field Name must be set")
}
if krq.CPU == 0 {
return errors.New("validation-error: field CPU must be set")
}
if krq.RAM == 0 {
return errors.New("validation-error: field RAM must be set")
}
if krq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
return nil
}
// Create creates KVM PowerPC VM based on specified OS image
func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := req.validate()
if err != nil {
return 0, err
}
url := "/cloudbroker/kvmppc/create"
res, err := k.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
}