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