Skip to content
Snippets Groups Projects
Commit f9ed9ec5 authored by Florent Gluck's avatar Florent Gluck
Browse files

- minimum RAM amount for vmcreate and vmedit is now 256MB (instead of 512 previously)

- fixed a bug in parameters validation in vmedit
- bumped client version to 1.8.5
- bumped server version to 1.8.4
parent 2dec4a79
Branches
No related tags found
No related merge requests found
...@@ -32,7 +32,7 @@ func (cmd *Create)PrintUsage() { ...@@ -32,7 +32,7 @@ func (cmd *Create)PrintUsage() {
u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――") u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
const usage string = `name Name of the VM to create. const usage string = `name Name of the VM to create.
cpus Number of CPUs, between 1 and 16. cpus Number of CPUs, between 1 and 16.
ram Amount of RAM in MB, between 512 and 32768. ram Amount of RAM in MB, between 256 and 32768.
nic Network interface, either "none" (no network) or "user" (network access). nic Network interface, either "none" (no network) or "user" (network access).
usb List of USB devices exposed in the VM; either "none" or a list of comma separated usb List of USB devices exposed in the VM; either "none" or a list of comma separated
vendorID:productID (4-digit hex number), each specifying a USB device; example vendorID:productID (4-digit hex number), each specifying a USB device; example
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"strings" "strings"
"errors" "errors"
"nexus-common/vm" "nexus-common/vm"
"nexus-common/params"
u "nexus-client/utils" u "nexus-client/utils"
g "nexus-client/globals" g "nexus-client/globals"
) )
...@@ -13,14 +14,6 @@ type Edit struct { ...@@ -13,14 +14,6 @@ type Edit struct {
Name string Name string
} }
type vmEditParameters struct {
Name string
Cpus int
Ram int
Nic vm.NicType
UsbDevs []string
}
func (cmd *Edit)GetName() string { func (cmd *Edit)GetName() string {
return cmd.Name return cmd.Name
} }
...@@ -41,7 +34,7 @@ func (cmd *Edit)PrintUsage() { ...@@ -41,7 +34,7 @@ func (cmd *Edit)PrintUsage() {
const usage string = `Parameters that can be changed (at least one must be specified): const usage string = `Parameters that can be changed (at least one must be specified):
name Name of the VM. name Name of the VM.
cpus Number of CPUs, between 1 and 16. cpus Number of CPUs, between 1 and 16.
ram Amount of RAM in MB, between 512 and 32768. ram Amount of RAM in MB, between 256 and 32768.
nic Network interface, either "none" (no network) or "user" (network access). nic Network interface, either "none" (no network) or "user" (network access).
usb List of USB devices exposed in the VM; either "none" or a list of comma separated usb List of USB devices exposed in the VM; either "none" or a list of comma separated
vendorID:productID (4-digit hex number), each specifying a USB device; example vendorID:productID (4-digit hex number), each specifying a USB device; example
...@@ -105,8 +98,8 @@ func (cmd *Edit)Run(args []string) int { ...@@ -105,8 +98,8 @@ func (cmd *Edit)Run(args []string) int {
return statusCode return statusCode
} }
func (cmd *Edit)parseArgs(args []string) (*vmEditParameters, []string, error) { func (cmd *Edit)parseArgs(args []string) (*params.VMEdit, []string, error) {
vmParams := &vmEditParameters {} vmParams := &params.VMEdit {}
var patterns []string var patterns []string
atLeastOneArg := false atLeastOneArg := false
...@@ -131,6 +124,7 @@ func (cmd *Edit)parseArgs(args []string) (*vmEditParameters, []string, error) { ...@@ -131,6 +124,7 @@ func (cmd *Edit)parseArgs(args []string) (*vmEditParameters, []string, error) {
if err != nil { if err != nil {
return nil, nil, errors.New("Invalid number of CPU(s)") return nil, nil, errors.New("Invalid number of CPU(s)")
} }
vmParams.CpusUpdated = true
vmParams.Cpus = cpus vmParams.Cpus = cpus
atLeastOneArg = true atLeastOneArg = true
continue continue
...@@ -141,6 +135,7 @@ func (cmd *Edit)parseArgs(args []string) (*vmEditParameters, []string, error) { ...@@ -141,6 +135,7 @@ func (cmd *Edit)parseArgs(args []string) (*vmEditParameters, []string, error) {
if err != nil { if err != nil {
return nil, nil, errors.New("Invalid amount of RAM") return nil, nil, errors.New("Invalid amount of RAM")
} }
vmParams.RamUpdated = true
vmParams.Ram = ram vmParams.Ram = ram
atLeastOneArg = true atLeastOneArg = true
continue continue
......
package cmdVM package cmdVM
import ( import (
"nexus-common/params"
u "nexus-client/utils" u "nexus-client/utils"
g "nexus-client/globals" g "nexus-client/globals"
) )
...@@ -9,10 +10,6 @@ type ExportDir struct { ...@@ -9,10 +10,6 @@ type ExportDir struct {
Name string Name string
} }
type vmExportDirParams struct {
Dir string
}
func (cmd *ExportDir)GetName() string { func (cmd *ExportDir)GetName() string {
return cmd.Name return cmd.Name
} }
...@@ -60,7 +57,7 @@ func (cmd *ExportDir)Run(args []string) int { ...@@ -60,7 +57,7 @@ func (cmd *ExportDir)Run(args []string) int {
return 1 return 1
} }
params := &vmExportDirParams { Dir: dir } params := &params.VMExportDir { Dir: dir }
statusCode := 0 statusCode := 0
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
const ( const (
major = 1 major = 1
minor = 8 minor = 8
bugfix = 4 bugfix = 5
) )
type Version struct { type Version struct {
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
type VMCreate struct { type VMCreate struct {
Name string `json:"name" validate:"required,min=4,max=256"` Name string `json:"name" validate:"required,min=4,max=256"`
Cpus int `json:"cpus" validate:"required,gte=1,lte=16"` Cpus int `json:"cpus" validate:"required,gte=1,lte=16"`
Ram int `json:"ram" validate:"required,gte=512,lte=32768"` Ram int `json:"ram" validate:"required,gte=256,lte=32768"`
Nic vm.NicType `json:"nic" validate:"required` Nic vm.NicType `json:"nic" validate:"required`
UsbDevs []string `json:"usbDevs" validate:"required` UsbDevs []string `json:"usbDevs" validate:"required`
TemplateID uuid.UUID `json:"templateID" validate:"required"` TemplateID uuid.UUID `json:"templateID" validate:"required"`
...@@ -23,9 +23,11 @@ type VMStartWithCreds struct { ...@@ -23,9 +23,11 @@ type VMStartWithCreds struct {
type VMEdit struct { type VMEdit struct {
Name string `json:"name" validate:"required,min=4,max=256"` Name string `json:"name" validate:"required,min=4,max=256"`
Cpus int `json:"cpus" validate:"required,gte=1,lte=16"` Cpus int `json:"cpus" validate:"required,gte=1,lte=16"`
Ram int `json:"ram" validate:"required,gte=512,lte=32768"` Ram int `json:"ram" validate:"required,gte=256,lte=32768"`
Nic vm.NicType `json:"nic" validate:"required` Nic vm.NicType `json:"nic" validate:"required`
UsbDevs []string `json:"usbDevs" validate:"required` UsbDevs []string `json:"usbDevs" validate:"required`
CpusUpdated bool
RamUpdated bool
} }
type VMAddAccess struct { type VMAddAccess struct {
......
...@@ -13,7 +13,7 @@ type ( ...@@ -13,7 +13,7 @@ type (
Owner string `json:"owner" validate:"required,email"` Owner string `json:"owner" validate:"required,email"`
Name string `json:"name" validate:"required,min=2,max=256"` Name string `json:"name" validate:"required,min=2,max=256"`
Cpus int `json:"cpus" validate:"required,gte=1,lte=16"` Cpus int `json:"cpus" validate:"required,gte=1,lte=16"`
Ram int `json:"ram" validate:"required,gte=512,lte=32768"` // in MB Ram int `json:"ram" validate:"required,gte=256,lte=32768"` // in MB
Nic NicType `json:"nic" validate:"required"` Nic NicType `json:"nic" validate:"required"`
UsbDevs []string `json:"usbDevs" validate:"required"` UsbDevs []string `json:"usbDevs" validate:"required"`
TemplateID uuid.UUID `json:"templateID" validate:"required"` TemplateID uuid.UUID `json:"templateID" validate:"required"`
...@@ -26,7 +26,7 @@ type ( ...@@ -26,7 +26,7 @@ type (
Owner string `json:"owner" validate:"required,email"` Owner string `json:"owner" validate:"required,email"`
Name string `json:"name" validate:"required,min=2,max=256"` Name string `json:"name" validate:"required,min=2,max=256"`
Cpus int `json:"cpus" validate:"required,gte=1,lte=16"` Cpus int `json:"cpus" validate:"required,gte=1,lte=16"`
Ram int `json:"ram" validate:"required,gte=512,lte=32768"` // in MB Ram int `json:"ram" validate:"required,gte=256,lte=32768"` // in MB
Nic NicType `json:"nic" validate:"required"` Nic NicType `json:"nic" validate:"required"`
UsbDevs []string `json:"usbDevs" validate:"required"` UsbDevs []string `json:"usbDevs" validate:"required"`
TemplateID uuid.UUID `json:"templateID" validate:"required"` TemplateID uuid.UUID `json:"templateID" validate:"required"`
......
...@@ -316,7 +316,7 @@ func (r *RouterVMs)EditVM(c echo.Context) error { ...@@ -316,7 +316,7 @@ func (r *RouterVMs)EditVM(c echo.Context) error {
if err := decodeJson(c, &p); err != nil { if err := decodeJson(c, &p); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error()) return echo.NewHTTPError(http.StatusBadRequest, err.Error())
} }
if err := r.vms.EditVM(vm.GetID(), p.Name, p.Cpus, p.Ram, p.Nic, p.UsbDevs); err != nil { if err := r.vms.EditVM(vm.GetID(), p); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error()) return echo.NewHTTPError(http.StatusBadRequest, err.Error())
} }
return c.JSONPretty(http.StatusOK, vm.SerializeToNetwork(), " ") return c.JSONPretty(http.StatusOK, vm.SerializeToNetwork(), " ")
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
const ( const (
major = 1 major = 1
minor = 8 minor = 8
bugfix = 3 bugfix = 4
) )
type Version struct { type Version struct {
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"path/filepath" "path/filepath"
"nexus-common/vm" "nexus-common/vm"
"nexus-common/caps" "nexus-common/caps"
"nexus-common/params"
"nexus-server/exec" "nexus-server/exec"
"nexus-server/paths" "nexus-server/paths"
"nexus-server/utils" "nexus-server/utils"
...@@ -360,7 +361,7 @@ func (vms *VMs)IsTemplateUsed(templateID string) bool { ...@@ -360,7 +361,7 @@ func (vms *VMs)IsTemplateUsed(templateID string) bool {
} }
// Edit a VM' specs: name, cpus, ram, nic // Edit a VM' specs: name, cpus, ram, nic
func (vms *VMs)EditVM(vmID uuid.UUID, name string, cpus, ram int, nic vm.NicType, usbDevs []string) error { func (vms *VMs)EditVM(vmID uuid.UUID, p *params.VMEdit) error {
vms.rwlock.Lock() vms.rwlock.Lock()
defer vms.rwlock.Unlock() defer vms.rwlock.Unlock()
...@@ -377,23 +378,27 @@ func (vms *VMs)EditVM(vmID uuid.UUID, name string, cpus, ram int, nic vm.NicType ...@@ -377,23 +378,27 @@ func (vms *VMs)EditVM(vmID uuid.UUID, name string, cpus, ram int, nic vm.NicType
} }
// Only updates fields that have changed. // Only updates fields that have changed.
if name != "" { prevVal := vm.v // Saves previous params values.
vm.v.Name = name
if p.Name != "" {
vm.v.Name = p.Name
} }
if cpus > 0 { if p.CpusUpdated {
vm.v.Cpus = cpus vm.v.Cpus = p.Cpus
} }
if ram > 0 { if p.RamUpdated {
vm.v.Ram = ram vm.v.Ram = p.Ram
} }
if nic != "" { if p.Nic != "" {
vm.v.Nic = nic vm.v.Nic = p.Nic
} }
if usbDevs != nil { if p.UsbDevs != nil {
vm.v.UsbDevs = usbDevs vm.v.UsbDevs = p.UsbDevs
} }
if err = vm.validate(); err != nil { if err = vm.validate(); err != nil {
// Restores previous values.
vm.v = prevVal
return err return err
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment