Select Git revision
vmAttach.go
vmAttach.go 1.12 KiB
package cmdVM
import (
"sync"
"nexus-client/exec"
u "nexus-client/utils"
g "nexus-client/globals"
)
type Attach struct {
Name string
}
func (cmd *Attach)GetName() string {
return cmd.Name
}
func (cmd *Attach)GetDesc() []string {
return []string{
"Attaches to one or more VMs in order to use their desktop environment (regex).",
"Requires VM_LIST VM access capability or VM_LIST_ANY user capability."}
}
func (cmd *Attach)PrintUsage() {
printRegexUsage(cmd)
printRegexUsageDetails()
}
func (cmd *Attach)Run(args []string) int {
hostname := g.GetInstance().Hostname
cert := g.GetInstance().PubCert
argc := len(args)
if argc < 1 {
cmd.PrintUsage()
return 1
}
vms, err := getFilteredVMs("/vms/attach", args)
if err != nil {
u.PrintlnErr(err.Error())
return 1
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
return 1
}
// Use wait groups to wait until all viewers threads have completed.
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()
} (vm)
}
wg.Wait()
return 0
}