v1.0.0
This commit is contained in:
@@ -7,26 +7,84 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for create KVM x86 VM
|
||||
type CreateRequest struct {
|
||||
RGID uint64 `url:"rgId"`
|
||||
Name string `url:"name"`
|
||||
CPU uint64 `url:"cpu"`
|
||||
RAM uint64 `url:"ram"`
|
||||
ImageID uint64 `url:"imageId"`
|
||||
BootDisk uint64 `url:"bootDisk,omitempty"`
|
||||
SepID uint64 `url:"sepId,omitempty"`
|
||||
Pool string `url:"pool,omitempty"`
|
||||
NetType string `url:"netType,omitempty"`
|
||||
NetID uint64 `url:"netId,omitempty"`
|
||||
IPAddr string `url:"ipAddr,omitempty"`
|
||||
Userdata string `url:"userdata,omitempty"`
|
||||
// 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 sepId 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 bool `url:"start,omitempty"`
|
||||
IS string `url:"IS,omitempty"`
|
||||
IPAType string `url:"ipaType,omitempty"`
|
||||
|
||||
// Start VM upon success
|
||||
// Required: false
|
||||
Start bool `url:"start,omitempty"`
|
||||
|
||||
// System name
|
||||
// Required: false
|
||||
IS string `url:"IS,omitempty"`
|
||||
|
||||
// Compute purpose
|
||||
// Required: false
|
||||
IPAType string `url:"ipaType,omitempty"`
|
||||
}
|
||||
|
||||
func (krq CreateRequest) Validate() error {
|
||||
func (krq CreateRequest) validate() error {
|
||||
if krq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -46,16 +104,15 @@ func (krq CreateRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create creates KVM x86 VM based on specified OS image
|
||||
func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/kvmx86/create"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/kvmx86/create"
|
||||
|
||||
url = prefix + url
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -65,6 +122,6 @@ func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result, nil
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,21 +7,63 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for create KVM x86 VM from scratch
|
||||
type CreateBlankRequest struct {
|
||||
RGID uint64 `url:"rgId"`
|
||||
Name string `url:"name"`
|
||||
CPU uint64 `url:"cpu"`
|
||||
RAM uint64 `url:"ram"`
|
||||
BootDisk uint64 `url:"bootDisk"`
|
||||
SepID uint64 `url:"sepId"`
|
||||
Pool string `url:"pool"`
|
||||
NetType string `url:"netType,omitempty"`
|
||||
NetID uint64 `url:"netId,omitempty"`
|
||||
IPAddr string `url:"ipAddr,omitempty"`
|
||||
// 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"`
|
||||
|
||||
// Size of the boot disk in GB
|
||||
// Required: true
|
||||
BootDisk uint64 `url:"bootDisk"`
|
||||
|
||||
// ID of SEP to create boot disk on.
|
||||
// Uses images SEP ID if not set
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sepId"`
|
||||
|
||||
// Pool to use if sepId is set, can be also empty if needed to be chosen by system
|
||||
// Required: true
|
||||
Pool string `url:"pool"`
|
||||
|
||||
// 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"`
|
||||
|
||||
// Text description of this VM
|
||||
// Required: false
|
||||
Description string `url:"desc,omitempty"`
|
||||
}
|
||||
|
||||
func (krq CreateBlankRequest) Validate() error {
|
||||
func (krq CreateBlankRequest) validate() error {
|
||||
if krq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -37,7 +79,7 @@ func (krq CreateBlankRequest) Validate() error {
|
||||
if krq.BootDisk == 0 {
|
||||
return errors.New("validation-error: field BootDisk can not be empty or equal to 0")
|
||||
}
|
||||
if krq.SepID == 0 {
|
||||
if krq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SepID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.Pool == "" {
|
||||
@@ -47,16 +89,15 @@ func (krq CreateBlankRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateBlank creates KVM x86 VM from scratch
|
||||
func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/kvmx86/createBlank"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/kvmx86/createBlank"
|
||||
|
||||
url = prefix + url
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -66,6 +107,6 @@ func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result, nil
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
// API to manage KVM x86 compute instances (x86 VMs)
|
||||
package kvmx86
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to KVMX86
|
||||
type KVMX86 struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for KVMX86 endpoints
|
||||
func New(client interfaces.Caller) *KVMX86 {
|
||||
return &KVMX86{
|
||||
client,
|
||||
|
||||
Reference in New Issue
Block a user