diff --git a/README.md b/README.md index 896e3b01a65d908b7cb2c431bb42e34c2a1e2853..a02e440e9d8cab6f2fe4c8ae2b001d96062b32af 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,8 @@ The table below lists all potential capabilities associated to a user: | VM_DESTROY_ANY | Can destoy **ANY** VM | | VM_EDIT_ANY | Can edit **ANY** VM | | VM_START_ANY | Can start **ANY** VM | -| VM_STOP_ANY | Can stop **ANY** VM | +| VM_STOP_ANY | Can kill/shutdown **ANY** VM | +| VM_REBOOT_ANY | Can Reboot **ANY** VM | | VM_LIST_ANY | Can list **ANY** VM | | VM_READFS_ANY | Can export files from **ANY** VM | | VM_WRITEFS_ANY | Can import files into **ANY** VM | @@ -72,7 +73,8 @@ These capabilities are called "VM access capabilities": | VM_DESTROY | User can destroy the VM | | VM_EDIT | User can edit the VM | | VM_START | User can start the VM | -| VM_STOP | User can stop/shutdown the VM | +| VM_STOP | User can kill/shutdown the VM | +| VM_REBOOT | User can reboot the VM | | VM_LIST | User can list or attach to the VM | | VM_READFS | User can export files from the VM | | VM_WRITEFS | User can import files into the VM | @@ -115,7 +117,7 @@ userdel Deletes one or more users. usersetcaps Sets a user's capabilities. Requires USER_SET_CAPS user capability. ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― -vmlist Lists VMs that can be listed. +vmlist Lists VMs. Requires VM_LIST VM access capability or VM_LIST_ANY user capability. ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― vmcred2pdf Creates a PDF with the credentials required to attach to running VMs. @@ -130,6 +132,9 @@ vmkill Kills one or more VMs. vmshutdown Gracefully shutdowns one or more VMs. Requires VM_STOP VM access capability or VM_STOP_ANY user capability. ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― +vmreboot Gracefully reboots one or more VMs. + Requires VM_REBOOT VM access capability or VM_REBOOT_ANY user capability. +――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― vmattach Attaches to one or more VMs in order to use their desktop environment. Requires VM_LIST VM access capability or VM_LIST_ANY user capability. ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― @@ -244,11 +249,6 @@ List listable VMs matching the "ubuntu" pattern and also the VM with ID `6713ce2 vmlist ubuntu 6713ce26-941e-4d95-8e92-6b71d44bf75a ``` -List all VMs that can be started: -``` -vmliststart . -``` - Start VM `6713ce26-941e-4d95-8e92-6b71d44bf75a`: ``` vmstart 6713ce26-941e-4d95-8e92-6b71d44bf75a @@ -259,21 +259,11 @@ Start VMs matching the "exam ISC_433 PCO" pattern: vmstart "exam ISC_433 PCO" ``` -List all VMs that can be attached to: -``` -vmlistattach . -``` - Attach to VM `6713ce26-941e-4d95-8e92-6b71d44bf75a` and all VMs matching the pattern "zorglub": ``` vmattach 6713ce26-941e-4d95-8e92-6b71d44bf75a zorglub ``` -List all VMs that can be shutdowned or stopped: -``` -vmliststop . -``` - Shutdown VMs matching the "exam ISC_433 PCO" pattern (for this to work, `qemu-guest-agent` must be running in the VM's guest OS!): ``` vmshutdown "exam ISC_433 PCO" @@ -302,11 +292,6 @@ ISC_433 Exam [2] ISC_433 Exam [50] ``` -List all VMs that can be edited: -``` -vmlistedit . -``` - Edit VM `6713ce26-941e-4d95-8e92-6b71d44bf75a` by changing its name to "Tagada VM", changing it to 1 CPU and no network interface (`none`): ``` vmedit 6713ce26-941e-4d95-8e92-6b71d44bf75a name="Tagada VM" cpus=1 nic=none @@ -317,11 +302,6 @@ Edit VMs matching the "PCO lab2" pattern by changing their CPU to 1 core and a n vmedit "PCO lab2" cpus=1 nic=user ``` -List all VMs that can be deleted: -``` -vmlistdel . -``` - Delete VM `6713ce26-941e-4d95-8e92-6b71d44bf75a`: ``` vmdel 6713ce26-941e-4d95-8e92-6b71d44bf75a @@ -332,11 +312,6 @@ Delete VMs matching the "exam ISC_433 PCO" pattern: vmdel "exam ISC_433 PCO" ``` -List all VMs that can have their access edited: -``` -vmlisteditaccess . -``` - Set the VM access for VM `89649fe3-4940-4b77-929e-50903789cd87` with: `VM_LIST` and `VM_DESTROY` for user `student@nexus.org`: ``` vmsetaccess 89649fe3-4940-4b77-929e-50903789cd87 student@nexus.org VM_LIST VM_DESTROY @@ -364,7 +339,7 @@ vmcred2pdf "exam prog sys" output.pdf Extract and download the `/home` directory of all VMs matching "exam prog sys" (each directory is saved in a `.tar` archive named after the VM's ID): ``` -vmlistexportdir "exam prog sys" /home +vmexportdir "exam prog sys" /home ``` List all available templates: diff --git a/src/cmdVM/vmAttach.go b/src/cmdVM/vmAttach.go index 614bd3f170d11b7ddc1f6b1e0ed02b20d1d4c81e..56d135891ed31a8fb3168376ea583da9ac479463 100644 --- a/src/cmdVM/vmAttach.go +++ b/src/cmdVM/vmAttach.go @@ -1,7 +1,7 @@ package cmdVM import ( - "sync" + // "sync" "nexus-client/exec" u "nexus-client/utils" g "nexus-client/globals" @@ -48,17 +48,17 @@ func (cmd *Attach)Run(args []string) int { } // Use wait groups to wait until all viewers threads have completed. - var wg sync.WaitGroup - wg.Add(len(vms)) + // var wg sync.WaitGroup + // wg.Add(len(vms)) for _, vm := range(vms) { go func(vm VM) { exec.RunRemoteViewer(hostname, cert, vm.Name, vm.Run.Port, vm.Run.Pwd, false) - wg.Done() + // wg.Done() } (vm) } - wg.Wait() + // wg.Wait() return 0 } diff --git a/src/cmdVM/vmList.go b/src/cmdVM/vmList.go index be745195adbcdcd0bda1f8e6466ce5f5ccada8b0..b710688a964c740d195382f72392bebbf4e5e60a 100644 --- a/src/cmdVM/vmList.go +++ b/src/cmdVM/vmList.go @@ -14,7 +14,7 @@ func (cmd *List)GetName() string { func (cmd *List)GetDesc() []string { return []string{ - "Lists VMs that can be listed.", + "Lists VMs.", "Requires VM_LIST VM access capability or VM_LIST_ANY user capability."} } diff --git a/src/cmdVM/vmReboot.go b/src/cmdVM/vmReboot.go new file mode 100644 index 0000000000000000000000000000000000000000..ccba0a8c3389d95339cc1ed22b57894d8b06fc54 --- /dev/null +++ b/src/cmdVM/vmReboot.go @@ -0,0 +1,68 @@ +package cmdVM + +import ( + u "nexus-client/utils" + g "nexus-client/globals" +) + +type Reboot struct { + Name string +} + +func (cmd *Reboot)GetName() string { + return cmd.Name +} + +func (cmd *Reboot)GetDesc() []string { + return []string{ + "Gracefully reboots one or more VMs.", + "Requires VM_REBOOT VM access capability or VM_REBOOT_ANY user capability."} +} + +func (cmd *Reboot)PrintUsage() { + printRegexUsage(cmd) + printRegexUsageDetails() +} + +func (cmd *Reboot)Run(args []string) int { + client := g.GetInstance().Client + host := g.GetInstance().Host + + argc := len(args) + if argc < 1 { + cmd.PrintUsage() + return 1 + } + + vms, err := getFilteredVMs("/vms/reboot", args) + if err != nil { + u.PrintlnErr(err.Error()) + return 1 + } + + if len(vms) == 0 { + u.PrintlnErr("No match.") + return 1 + } + + statusCode := 0 + + for _, vm := range(vms) { + uuid := vm.ID.String() + resp, err := client.R().Put(host+"/vms/"+uuid+"/reboot") + if err != nil { + u.PrintlnErr("Reboot failed for VM \""+vm.Name+"\": "+err.Error()) + statusCode = 1 + } else { + if resp.IsSuccess() { + u.Println("Sent reboot message to VM \""+vm.Name+"\"") + } else { + u.PrintlnErr("Reboot failed for VM \""+vm.Name+"\": "+resp.Status()+": "+resp.String()) + statusCode = 1 + } + } + + } + + return statusCode +} diff --git a/src/nexus-cli/nexus-cli.go b/src/nexus-cli/nexus-cli.go index 1d692d4f2ba33640e7781b2712dd6579b4fb1466..72bedc374f8dcf4a3b651b8a9c45e33994b052a7 100644 --- a/src/nexus-cli/nexus-cli.go +++ b/src/nexus-cli/nexus-cli.go @@ -35,6 +35,7 @@ var cmdList = []cmd.Command { &cmdVM.Start{"vmstart"}, &cmdVM.Stop{"vmkill"}, &cmdVM.Shutdown{"vmshutdown"}, + &cmdVM.Reboot{"vmreboot"}, &cmdVM.Attach{"vmattach"}, &cmdVM.Create{"vmcreate"}, &cmdVM.Edit{"vmedit"}, diff --git a/src/nexush/nexush.go b/src/nexush/nexush.go index 295964445b147b337733b655643123731e0ab0d5..a052644aa34c881eab8e850c9f9adec13558e4ff 100644 --- a/src/nexush/nexush.go +++ b/src/nexush/nexush.go @@ -43,6 +43,7 @@ var cmdList = []cmd.Command { &cmdVM.Start{"vmstart"}, &cmdVM.Stop{"vmkill"}, &cmdVM.Shutdown{"vmshutdown"}, + &cmdVM.Reboot{"vmreboot"}, &cmdVM.Attach{"vmattach"}, &cmdVM.Create{"vmcreate"}, &cmdVM.Edit{"vmedit"}, diff --git a/src/version/version.go b/src/version/version.go index 641fb435471504d4d47792f8c2cd04da214b25a0..979b9bc821e356eec1e4566a67168a1d2d0f0b5c 100644 --- a/src/version/version.go +++ b/src/version/version.go @@ -7,8 +7,8 @@ import ( const ( major = 1 - minor = 0 - bugfix = 4 + minor = 1 + bugfix = 0 ) type Version struct {