From 8ac41fb1452ee31496e5545cf3af3be085a25ac7 Mon Sep 17 00:00:00 2001 From: Florent Gluck <florent.gluck@hesge.ch> Date: Tue, 4 Oct 2022 16:14:24 +0200 Subject: [PATCH] Bumpped to version 1.0.1 Renamed some commands for better clarity: - useradd -> usercreate - vmstop -> vmkill - vmsetaccess -> vmaddaccess Fixed a bug in the validate script in case more than 1 VM is named Xubuntu --- README.md | 6 +++--- src/cmdUser/userAdd.go | 2 +- src/cmdVM/vmCreate.go | 2 +- src/cmdVM/vmDelAccess.go | 8 +------- src/cmdVM/vmEdit.go | 11 +++-------- src/cmdVM/vmListStop.go | 2 +- src/cmdVM/vmSetAccess.go | 10 ++-------- src/cmdVM/vmStop.go | 2 +- src/nexus-cli/nexus-cli.go | 8 ++++---- src/nexus-cli/validate | 33 ++++++++++++++++++--------------- src/nexush/nexush.go | 10 +++++----- src/version/version.go | 2 +- 12 files changed, 41 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 528019e..b6f1194 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ passwd Updates the current user's password. userlist Lists users (regex). Requires USER_LIST user capability. ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― -useradd Adds a user. +usercreate Creates a user. Requires USER_CREATE user capability. ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― userdel Deletes one or more users. @@ -124,7 +124,7 @@ vmcred2pdf Creates a PDF with the credentials required to attach to run vmstart Starts one or more VMs (regex). Requires VM_START VM access capability or VM_START_ANY user capability. ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― -vmstop Stops by force one or more VMs (regex). +vmkill Kill one or more VMs (regex). Requires VM_STOP VM access capability or VM_STOP_ANY user capability. ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― vmshutdown Gracefully shutdowns one or more VMs (regex). @@ -142,7 +142,7 @@ vmedit Edits one or more VMs' properties: name, cpus, ram or nic (r vmdel Deletes one or more VMs (regex). Requires VM_DESTROY VM access capability or VM_DESTROY_ANY user capability. ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― -vmsetaccess Sets a user's VM access in one or more VMs (regex). +vmaddaccess Adds a user's VM access in one or more VMs (regex). Requires VM_SET_ACCESS user capability and VM_SET_ACCESS VM access capability. ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― vmdelaccess Removes a user's VM access in one or more VMs (regex). diff --git a/src/cmdUser/userAdd.go b/src/cmdUser/userAdd.go index 5ee73b6..65812e5 100644 --- a/src/cmdUser/userAdd.go +++ b/src/cmdUser/userAdd.go @@ -15,7 +15,7 @@ func (cmd *Add)GetName() string { func (cmd *Add)GetDesc() []string { return []string{ - "Adds a user.", + "Creates a user.", "Requires USER_CREATE user capability."} } diff --git a/src/cmdVM/vmCreate.go b/src/cmdVM/vmCreate.go index a436799..88b3698 100644 --- a/src/cmdVM/vmCreate.go +++ b/src/cmdVM/vmCreate.go @@ -34,7 +34,7 @@ func (cmd *Create)PrintUsage() { 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". +nic Network interface, either "none" (no network) or "user" (network access). 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, the VM name is postfixed with [n], diff --git a/src/cmdVM/vmDelAccess.go b/src/cmdVM/vmDelAccess.go index 067ffda..2deadd6 100644 --- a/src/cmdVM/vmDelAccess.go +++ b/src/cmdVM/vmDelAccess.go @@ -28,13 +28,7 @@ func (cmd *DelAccess)PrintUsage() { u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――") u.PrintlnErr("USAGE: "+cmd.GetName()+" [ID ...] [regex ...] email") u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――") - const usage string = `Only VMs matching the specified IDs or regexes will have their VM access removed. -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 -"bla" -> matches any VMs containing "bla" in their name` - u.PrintlnErr(usage) + printRegexUsageDetails() } func (cmd *DelAccess)Run(args []string) int { diff --git a/src/cmdVM/vmEdit.go b/src/cmdVM/vmEdit.go index f50f289..c9f2e63 100644 --- a/src/cmdVM/vmEdit.go +++ b/src/cmdVM/vmEdit.go @@ -36,16 +36,11 @@ func (cmd *Edit)PrintUsage() { u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――") u.PrintlnErr("USAGE: "+cmd.GetName()+" [ID ...] [regex ...] [name=\"new name\"] [cpus=n] [ram=n] [nic=none/user]") u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――") - const usage string = `Only VMs matching the specified IDs or regexes will be edited. -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 -"bla" -> matches any VMs containing "bla" in their name -VM parameters that can be edited are the following: + printRegexUsageDetails() + const usage string = `VM parameters that can be edited: cpus must be between 1 and 16 ram must be between 512 and 32768 -nic must be either "none" or "user` +nic must be either "none" (no network) or "user (network access)` u.PrintlnErr(usage) } diff --git a/src/cmdVM/vmListStop.go b/src/cmdVM/vmListStop.go index 7dd9e11..453cc2b 100644 --- a/src/cmdVM/vmListStop.go +++ b/src/cmdVM/vmListStop.go @@ -10,7 +10,7 @@ func (cmd *ListStop)GetName() string { func (cmd *ListStop)GetDesc() []string { return []string{ - "Lists VMs that can be stopped or shutdown (regex).", + "Lists VMs that can be killed or shutdown (regex).", "Requires VM_STOP VM access capability or VM_STOP_ANY user capability."} } diff --git a/src/cmdVM/vmSetAccess.go b/src/cmdVM/vmSetAccess.go index 75a746b..3784939 100644 --- a/src/cmdVM/vmSetAccess.go +++ b/src/cmdVM/vmSetAccess.go @@ -17,7 +17,7 @@ func (cmd *SetAccess)GetName() string { func (cmd *SetAccess)GetDesc() []string { return []string{ - "Sets a user's VM access in one or more VMs (regex).", + "Adds a user's VM access in one or more VMs (regex).", "Requires VM_SET_ACCESS user capability and VM_SET_ACCESS VM access capability."} } @@ -28,13 +28,7 @@ func (cmd *SetAccess)PrintUsage() { u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――") u.PrintlnErr("USAGE: "+cmd.GetName()+" [ID ...] [regex ...] email [capability ...]") u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――") - const usage string = `Only VMs matching the specified IDs or regexes will have their VM access set. -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 -"bla" -> matches any VMs containing "bla" in their name` - u.PrintlnErr(usage) + printRegexUsageDetails() } func (cmd *SetAccess)Run(args []string) int { diff --git a/src/cmdVM/vmStop.go b/src/cmdVM/vmStop.go index 8e91ab4..c2ce958 100644 --- a/src/cmdVM/vmStop.go +++ b/src/cmdVM/vmStop.go @@ -15,7 +15,7 @@ func (cmd *Stop)GetName() string { func (cmd *Stop)GetDesc() []string { return []string{ - "Stops by force one or more VMs (regex).", + "Kill one or more VMs (regex).", "Requires VM_STOP VM access capability or VM_STOP_ANY user capability."} } diff --git a/src/nexus-cli/nexus-cli.go b/src/nexus-cli/nexus-cli.go index 2401103..03de5a0 100644 --- a/src/nexus-cli/nexus-cli.go +++ b/src/nexus-cli/nexus-cli.go @@ -26,7 +26,7 @@ var cmdList = []cmd.Command { &cmdUser.Whoami{"whoami"}, &cmdUser.UpdatePwd{"passwd"}, &cmdUser.List{"userlist"}, - &cmdUser.Add{"useradd"}, + &cmdUser.Add{"usercreate"}, &cmdUser.Del{"userdel"}, &cmdUser.SetCaps{"usersetcaps"}, @@ -42,13 +42,13 @@ var cmdList = []cmd.Command { &cmdVM.Cred2pdf{"vmcred2pdf"}, &cmdVM.Start{"vmstart"}, - &cmdVM.Stop{"vmstop"}, + &cmdVM.Stop{"vmkill"}, &cmdVM.Shutdown{"vmshutdown"}, &cmdVM.Attach{"vmattach"}, &cmdVM.Create{"vmcreate"}, &cmdVM.Edit{"vmedit"}, &cmdVM.Del{"vmdel"}, - &cmdVM.SetAccess{"vmsetaccess"}, + &cmdVM.SetAccess{"vmaddaccess"}, &cmdVM.DelAccess{"vmdelaccess"}, &cmdVM.ExportDir{"vmexportdir"}, &cmdVM.ImportDir{"vmimportdir"}, @@ -61,7 +61,7 @@ var cmdList = []cmd.Command { func main() { var appname = path.Base(os.Args[0]) - u.Println(appname+" version "+version.Get().String()) + u.PrintlnErr(appname+" version "+version.Get().String()) if err := exec.CheckRemoteViewer(); err != nil { u.PrintlnErr(err.Error()) diff --git a/src/nexus-cli/validate b/src/nexus-cli/validate index 0e98d3e..0c19ec8 100755 --- a/src/nexus-cli/validate +++ b/src/nexus-cli/validate @@ -16,7 +16,7 @@ del_gen_files () { cleanup () { echo "" echo "Cleaning up..." - $nexus_cli vmstop "$full_name" + $nexus_cli vmkill "$full_name" sleep 3 $nexus_cli vmdel "$partial_name" $nexus_cli tpldel "$partial_name" @@ -54,61 +54,64 @@ pwd=$2 echo "Log in..." export NEXUS_TOKEN=`$nexus_cli login $email $pwd` -checkVar $NEXUS_TOKEN "login" +if [ -z "$NEXUS_TOKEN" ]; then + echo "[FATAL] login failed." + exit 1 +fi OK -echo "Listing templates..." -baseTemplateID=`$nexus_cli tpllist . | grep "Xubuntu 22.04" | awk -F"|" '{print $2}'` +echo "List templates..." +baseTemplateID=`$nexus_cli tpllist . | grep "Xubuntu 22.04" | awk -F"|" '{print $2}'|head -n1` checkVar $baseTemplateID "tpllist" OK -echo "Creating base VM..." +echo "Create base VM..." vmID=`$nexus_cli vmcreate "$partial_name" 2 3000 user $baseTemplateID | awk -F"|" '{print $2}'` checkVar $vmID "vmcreate base VM" OK -echo "Importing files into VM..." +echo "Import files into VM..." $nexus_cli vmimportdir "$partial_name" validation_data/exam /home check "vmimportdir" OK -echo "Creating template from VM (can take a few minutes)..." +echo "Create template from VM (can take a few minutes)..." templateID=`$nexus_cli tplcreate $vmID "$partial_name" private | grep \"id\" | awk -F'"' '{print $4}'` checkVar $templateID "tplcreate" OK -echo "Creating students VMs..." +echo "Create students VMs..." $nexus_cli vmcreate "$full_name" 1 2000 none $templateID validation_data/students.csv check "vmcreate VMs" OK -echo "Starting students VMs..." +echo "Start students VMs..." $nexus_cli vmstart "$full_name" check "vmstart VMs" OK -echo "Generating credentials pdf..." +echo "Generate credentials pdf..." $nexus_cli vmcred2pdf "$full_name" $creds_file check "vmcred2pdf" OK -echo "Exporting files from VMs..." +echo "Export files from VMs..." $nexus_cli vmexportdir "$full_name" /home check "vmexportdir" OK -echo "Stopping students VMs..." -$nexus_cli vmstop "$full_name" +echo "Kill students VMs..." +$nexus_cli vmkill "$full_name" sleep 3 check "vmstop VMs" OK -echo "Deleting students VMs..." +echo "Delete students VMs..." $nexus_cli vmdel "$partial_name" check "vmdel VMs" OK -echo "Deleting template..." +echo "Delete template..." $nexus_cli tpldel "$partial_name" check "tpldel" OK diff --git a/src/nexush/nexush.go b/src/nexush/nexush.go index 9d8f153..1f202bb 100644 --- a/src/nexush/nexush.go +++ b/src/nexush/nexush.go @@ -33,7 +33,7 @@ var cmdList = []cmd.Command { &cmdUser.Whoami{"whoami"}, &cmdUser.UpdatePwd{"passwd"}, &cmdUser.List{"userlist"}, - &cmdUser.Add{"useradd"}, + &cmdUser.Add{"usercreate"}, &cmdUser.Del{"userdel"}, &cmdUser.SetCaps{"usersetcaps"}, @@ -49,13 +49,13 @@ var cmdList = []cmd.Command { &cmdVM.Cred2pdf{"vmcred2pdf"}, &cmdVM.Start{"vmstart"}, - &cmdVM.Stop{"vmstop"}, + &cmdVM.Stop{"vmkill"}, &cmdVM.Shutdown{"vmshutdown"}, &cmdVM.Attach{"vmattach"}, &cmdVM.Create{"vmcreate"}, &cmdVM.Edit{"vmedit"}, &cmdVM.Del{"vmdel"}, - &cmdVM.SetAccess{"vmsetaccess"}, + &cmdVM.SetAccess{"vmaddaccess"}, &cmdVM.DelAccess{"vmdelaccess"}, &cmdVM.ExportDir{"vmexportdir"}, &cmdVM.ImportDir{"vmimportdir"}, @@ -68,7 +68,7 @@ var cmdList = []cmd.Command { func main() { var appname = path.Base(os.Args[0]) - u.Println(appname+" version "+version.Get().String()) + u.PrintlnErr(appname+" version "+version.Get().String()) if err := exec.CheckRemoteViewer(); err != nil { u.PrintlnErr(err.Error()) @@ -126,7 +126,7 @@ func main() { // Logins and obtains a JWT token. token, err := cmdLogin.GetToken(email, pwd) - u.Println("") + u.PrintlnErr("") if err != nil { u.PrintlnErr("Error: "+err.Error()) os.Exit(1) diff --git a/src/version/version.go b/src/version/version.go index 924b749..6054296 100644 --- a/src/version/version.go +++ b/src/version/version.go @@ -8,7 +8,7 @@ import ( const ( major = 1 minor = 0 - bugfix = 0 + bugfix = 1 ) type Version struct { -- GitLab