diff --git a/src/client_cli/cmdTemplate/helper.go b/src/client_cli/cmdTemplate/helper.go index 5628b814966d00e8d1f8b27991f30344a5200bf9..1995b224eefab28fe54a645c6cafe01f424a233b 100644 --- a/src/client_cli/cmdTemplate/helper.go +++ b/src/client_cli/cmdTemplate/helper.go @@ -32,14 +32,15 @@ func (tpl *Template)String() string { func printUsage(c cmd.Command) { u.PrintlnErr(c.GetDesc()) - u.PrintlnErr("Usage: ",c.GetName()," [ID] [regex]") - u.PrintlnErr("Only templates matching either the specified ID or regex will be listed.") - u.PrintlnErr("Any number of ID or regex can be specified.") - u.PrintlnErr("The regex matches the template's name only and is case-insensitive.") - u.PrintlnErr("Regex examples:") - u.PrintlnErr(" \"\" -> matches any name") - u.PrintlnErr(" \".\" -> matches any name") - u.PrintlnErr(" \"bla\" -> matches any name containing \"bla\"") + u.PrintlnErr("Usage: ",c.GetName()," [ID ...] [regex ...]") + const usage string = `Only templates matching the specified IDs or regexes will be listed. +Any number of IDs or regexes can be specified. +The regex only matches the templates's name and is case-insensitive. +Regex examples: + "" -> matches any templates + "." -> matches any templates + "bla" -> matches any templates containing "bla"` + u.PrintlnErr(usage) } // Call the given route and filter the results based on ID and regex. diff --git a/src/client_cli/cmdUser/helper.go b/src/client_cli/cmdUser/helper.go index ad853da5fd950fa70f5c19b2de64e38ff0b98958..ad36e0dd47fd629fc93375e4a043c38261f6b91f 100644 --- a/src/client_cli/cmdUser/helper.go +++ b/src/client_cli/cmdUser/helper.go @@ -34,14 +34,15 @@ func (user *User)String() string { func printUsage(c cmd.Command) { u.PrintlnErr(c.GetDesc()) - u.PrintlnErr("Usage: ",c.GetName()," [regex]") - u.PrintlnErr("Only users matching the specified regex will be listed.") - u.PrintlnErr("Any number of regex can be specified.") - u.PrintlnErr("The regex matches the user email, first name and last name and is case-insensitive.") - u.PrintlnErr("Regex examples:") - u.PrintlnErr(" \"\" -> matches any user") - u.PrintlnErr(" \".\" -> matches any user") - u.PrintlnErr(" \"bla\" -> matches any user containing \"bla\"") + u.PrintlnErr("Usage: ",c.GetName()," [regex ...]") + const usage string = `Only users matching the specified regexes will be listed. +Any number of regexes can be specified. +The regex matches the user email, first name and last name and is case-insensitive. +Regex examples: + "" -> matches any users + "." -> matches any users + "bla" -> matches any users containing "bla"` + u.PrintlnErr(usage) } // Call the given route and filter the results based on a regex. diff --git a/src/client_cli/cmdUser/userAdd.go b/src/client_cli/cmdUser/userAdd.go index e5dee74b6ded52f1b0452ceab761035d00e006e8..8be5e050046256df4f9d2649e3b17a750f0828fb 100644 --- a/src/client_cli/cmdUser/userAdd.go +++ b/src/client_cli/cmdUser/userAdd.go @@ -19,7 +19,7 @@ func (cmd *Add)GetDesc() string { func (cmd *Add)PrintUsage() { u.PrintlnErr(cmd.GetDesc()) - u.PrintlnErr("Usage: "+cmd.Name+" email firstname lastname password [capability1 capability2 ...]") + u.PrintlnErr("Usage: "+cmd.Name+" email firstname lastname password [capability ...]") } func (cmd *Add)Run(args []string) int { diff --git a/src/client_cli/cmdUser/userSetCaps.go b/src/client_cli/cmdUser/userSetCaps.go index 028cd6b8837dde235eca7e09d6b7a051c2f4896c..2d49448145875979b7b5bc1bc867492ba7bb0998 100644 --- a/src/client_cli/cmdUser/userSetCaps.go +++ b/src/client_cli/cmdUser/userSetCaps.go @@ -19,7 +19,7 @@ func (cmd *SetCaps)GetDesc() string { func (cmd *SetCaps)PrintUsage() { u.PrintlnErr(cmd.GetDesc()) - u.PrintlnErr("Usage: "+cmd.Name+" email [capability1 capability2 ...]") + u.PrintlnErr("Usage: "+cmd.Name+" email [capability ...]") } func (cmd *SetCaps)Run(args []string) int { diff --git a/src/client_cli/cmdVM/helper.go b/src/client_cli/cmdVM/helper.go index 9a97aac6ccfa4a12e9675e14d702567786d8b54f..06f6f06b92fd71a27133546244aa61503607b684 100644 --- a/src/client_cli/cmdVM/helper.go +++ b/src/client_cli/cmdVM/helper.go @@ -53,14 +53,15 @@ func (vm *VM)String() string { func printUsage(c cmd.Command) { u.PrintlnErr(c.GetDesc()) - u.PrintlnErr("Usage: ",c.GetName()," [ID] [regex]") - u.PrintlnErr("Only VMs matching either the specified ID or regex will be listed.") - u.PrintlnErr("Any number of ID or regex can be specified.") - u.PrintlnErr("The regex matches the VM's name only and is case-insensitive.") - u.PrintlnErr("Regex examples:") - u.PrintlnErr(" \"\" -> matches any name") - u.PrintlnErr(" \".\" -> matches any name") - u.PrintlnErr(" \"bla\" -> matches any name containing \"bla\"") + u.PrintlnErr("Usage: ",c.GetName()," [ID ...] [regex ...]") + const usage string = `Only VMs matching the specified IDs or regexes will be listed. +Any number of IDs or regexes can be specified. +The regex only matches the VM's name and is case-insensitive. +Regex examples: + "" -> matches any VMs + "." -> matches any VMs + "bla" -> matches any VMs containing "bla" in their name` + u.PrintlnErr(usage) } // Call the given route and filter the results based on ID and regex. diff --git a/src/client_cli/cmdVM/vmCreate.go b/src/client_cli/cmdVM/vmCreate.go index 688bc75517e2be5089cb7428b0994cfbdb4bcaff..851b698acae0e65920755b31922f095452d8d704 100644 --- a/src/client_cli/cmdVM/vmCreate.go +++ b/src/client_cli/cmdVM/vmCreate.go @@ -15,18 +15,21 @@ func (cmd *Create)GetName() string { } func (cmd *Create)GetDesc() string { - return "Create a VM" + return "Create one or more VMs" } func (cmd *Create)PrintUsage() { u.PrintlnErr(cmd.GetDesc()) - u.PrintlnErr("Usage: "+cmd.Name+" name cpus ram nic template") - u.PrintlnErr("name name of the VM") - u.PrintlnErr("cpus number of CPUs, between 1 and 16") - u.PrintlnErr("ram amount of RAM in MB, between 512 and 32768") - u.PrintlnErr("nic network interface, either \"none\" or \"user\"") - u.PrintlnErr("template ID of the template to VM will be based on") - + u.PrintlnErr("Usage: "+cmd.Name+" name cpus ram nic template [count]") + const usage string = `name name of the VM +cpus number of CPUs, between 1 and 16 +ram amount of RAM in MB, between 512 and 32768 +nic network interface, either "none" or "user" +template ID of the template to VM will be based on +count number of VMs to create (if not specified, one is created) + if specified and > 1, name is postfixed with [n] + where n ranges from 1..count` + u.PrintlnErr(usage) } func (cmd *Create)Run(args []string) int { @@ -34,24 +37,36 @@ func (cmd *Create)Run(args []string) int { host := g.GetInstance().Host argc := len(args) - if argc != 5 { + if argc < 5 || argc > 6 { cmd.PrintUsage() return 1 } + name := args[0] ncpus, err := strconv.Atoi(args[1]) if err != nil { u.PrintlnErr("Invalid number of CPU(s)") return 1 } - ram, err := strconv.Atoi(args[2]) if err != nil { u.PrintlnErr("Invalid amount of RAM") return 1 } - nic := args[3] + template := args[4] + count := 1 + if argc == 6 { + count, err = strconv.Atoi(args[5]) + if err != nil { + u.PrintlnErr("Invalid count") + return 1 + } + if count < 1 { + u.PrintlnErr("count must be > 0") + return 1 + } + } type VMArgs struct { Name string @@ -62,24 +77,37 @@ func (cmd *Create)Run(args []string) int { } vmArgs := &VMArgs { - Name: args[0], + Name: name, Cpus: ncpus, Ram: ram, - Nic: nic, - TemplateID: args[4], + Nic: nic, + TemplateID: template, } - resp, err := client.R().SetBody(vmArgs).Post(host+"/vms") - if err != nil { - u.PrintlnErr("Error: "+err.Error()) - return 1 + errors := false + + for i := 1; i <= count; i++ { + if count > 1 { + vmArgs.Name = name+" ["+strconv.Itoa(i)+"]" + } + + resp, err := client.R().SetBody(vmArgs).Post(host+"/vms") + if err != nil { + u.PrintlnErr("Failed creating VM \""+vmArgs.Name+"\": "+err.Error()) + errors = true + } else { + if resp.IsSuccess() { + u.Println("Successfully created VM \""+vmArgs.Name+"\"") + } else { + u.PrintlnErr("Failed creating VM \""+vmArgs.Name+"\": "+resp.Status()+": "+resp.String()) + errors = true + } + } } - if resp.IsSuccess() { - u.Println(resp) - return 0 - } else { - u.PrintlnErr("Error: "+resp.Status()+": "+resp.String()) + if errors { return 1 + } else { + return 0 } } diff --git a/src/client_cli/cmdVM/vmSetAccess.go b/src/client_cli/cmdVM/vmSetAccess.go index 54162460a292b594acd62f6402cfe95bd7ff9781..f0e675a50dbafbe060ee88e3b0a913ac88feb822 100644 --- a/src/client_cli/cmdVM/vmSetAccess.go +++ b/src/client_cli/cmdVM/vmSetAccess.go @@ -19,7 +19,7 @@ func (cmd *SetAccess)GetDesc() string { func (cmd *SetAccess)PrintUsage() { u.PrintlnErr(cmd.GetDesc()) - u.PrintlnErr("Usage: "+cmd.Name+" vmID email [capability1 capability2 ...]") + u.PrintlnErr("Usage: "+cmd.Name+" vmID email [capability ...]") } func (cmd *SetAccess)Run(args []string) int {