forked from phc/cluster-dashboard
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
2 years ago
|
package executor
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"fmt"
|
||
|
"os/exec"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
type HostRunner struct{}
|
||
|
|
||
|
func (HostRunner) SlurmQueue() ([]string, error) {
|
||
|
panic("todo")
|
||
|
}
|
||
|
|
||
|
func (HostRunner) SlurmJobs() ([]string, error) {
|
||
|
panic("todo")
|
||
|
}
|
||
|
|
||
|
func (HostRunner) NodeUptime(hostname string) (string, error) {
|
||
|
panic("todo")
|
||
|
}
|
||
|
|
||
|
func (HostRunner) Temperature(hostname string) (string, error) {
|
||
|
panic("todo")
|
||
|
}
|
||
|
|
||
|
func (HostRunner) MemoryUsage(hostname string) (string, error) {
|
||
|
panic("todo")
|
||
|
}
|
||
|
|
||
|
func (HostRunner) StorageUsage(hostname string) (string, error) {
|
||
|
panic("todo")
|
||
|
}
|
||
|
|
||
|
func (HostRunner) NetworkUpload(hostname string) (string, error) {
|
||
|
panic("todo")
|
||
|
}
|
||
|
|
||
|
func (HostRunner) NetworkDownload(hostname string) (string, error) {
|
||
|
panic("todo")
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// Internals
|
||
|
//
|
||
|
|
||
|
// run a shell command and returns its output as string
|
||
|
func run(command string) (string, error) {
|
||
|
buf := &bytes.Buffer{}
|
||
|
|
||
|
// ctx := context.Background()
|
||
|
// ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
|
||
|
// defer cancel()
|
||
|
// cmd := exec.CommandContext(ctx, "sh", "-c", command)
|
||
|
|
||
|
cmd := exec.Command("sh", "-c", command)
|
||
|
cmd.Stdout = buf
|
||
|
|
||
|
// BUG: Al momento se questo comando ci mette troppo tutto si blocca, quindi sarebbe meglio
|
||
|
// usare un context per dare un timeout al comando
|
||
|
if err := cmd.Run(); err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
return buf.String(), nil
|
||
|
}
|
||
|
|
||
|
// run a shell command on a given remote via ssh and returns its output as string, does a bit of escaping
|
||
|
func runOnRemote(destination, command string) (string, error) {
|
||
|
return run(fmt.Sprintf(`ssh %s '%s'`, destination, strings.ReplaceAll(command, `'`, `\'`)))
|
||
|
}
|