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

Cleaned-up vmedit code by avoiding serializing useless data

parent fd5fe28a
Branches
No related tags found
No related merge requests found
......@@ -99,7 +99,7 @@ func (cmd *Edit)Run(args []string) int {
}
func (cmd *Edit)parseArgs(args []string) (*params.VMEdit, []string, error) {
vmParams := &params.VMEdit {}
vmParams := &params.VMEdit { Cpus: 0, Ram: 0 }
var patterns []string
atLeastOneArg := false
......@@ -121,10 +121,9 @@ func (cmd *Edit)parseArgs(args []string) (*params.VMEdit, []string, error) {
s = getStringVal(arg, "cpus=")
if s != "" {
cpus, err := strconv.Atoi(s)
if err != nil {
return nil, nil, errors.New("Invalid number of CPU(s)")
if err != nil || cpus < 1 {
return nil, nil, errors.New("Error: invalid number of CPU(s)!")
}
vmParams.CpusUpdated = true
vmParams.Cpus = cpus
atLeastOneArg = true
continue
......@@ -132,10 +131,9 @@ func (cmd *Edit)parseArgs(args []string) (*params.VMEdit, []string, error) {
s = getStringVal(arg, "ram=")
if s != "" {
ram, err := strconv.Atoi(s)
if err != nil {
return nil, nil, errors.New("Invalid amount of RAM")
if err != nil || ram < 1 {
return nil, nil, errors.New("Error: invalid amount of RAM!")
}
vmParams.RamUpdated = true
vmParams.Ram = ram
atLeastOneArg = true
continue
......
......@@ -7,8 +7,8 @@ import (
const (
major = 1
minor = 8
bugfix = 10
minor = 9
bugfix = 0
)
type Version struct {
......
......@@ -26,8 +26,6 @@ type VMEdit struct {
Ram int `json:"ram" validate:"required,gte=256,lte=32768"`
Nic vm.NicType `json:"nic" validate:"required`
UsbDevs []string `json:"usbDevs" validate:"required`
CpusUpdated bool
RamUpdated bool
}
type VMAddAccess struct {
......
......@@ -6,8 +6,8 @@ import (
const (
major = 1
minor = 8
bugfix = 8
minor = 9
bugfix = 0
)
type Version struct {
......
......@@ -555,10 +555,10 @@ func (vms *VMs)EditVM(vmID uuid.UUID, p *params.VMEdit) error {
if p.Name != "" {
vm.v.Name = p.Name
}
if p.CpusUpdated {
if p.Cpus > 0 {
vm.v.Cpus = p.Cpus
}
if p.RamUpdated {
if p.Ram > 0 {
vm.v.Ram = p.Ram
}
if p.Nic != "" {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment