Skip to content

Commit

Permalink
Updated strategy of getting machinelist
Browse files Browse the repository at this point in the history
  • Loading branch information
hurngchunlee committed May 29, 2019
1 parent 8c9b978 commit 71de716
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CACERTDIR ?= "/etc/pki/tls/certs"

GOLDFLAGS = "-X github.com/Donders-Institute/hpc-utility/internal/cmd.defTorqueHelperCert=/etc/pki/tls/certs/star_dccn_nl.chained.crt \
-X github.com/Donders-Institute/hpc-utility/internal/cmd.defWebhookCert=/etc/pki/tls/certs/star_dccn_nl.chained.crt \
-X github.com/Donders-Institute/hpc-utility/internal/cmd.defMachineListFile=/opt/cluster/etc/machines.mentat \
-X github.com/Donders-Institute/hpc-utility/internal/cmd.defVersion=$(VERSION)"

all: build
Expand Down
47 changes: 39 additions & 8 deletions internal/cmd/cluster.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"bufio"
"bytes"
"fmt"
"io"
Expand Down Expand Up @@ -28,7 +29,9 @@ const (

// variable may be set at the build time to fix the default location for the TorqueHelper server certificate.
var defTorqueHelperCert string
var defMachineListFile string
var vncUser string
var vncMachineListFile string

func init() {

Expand All @@ -39,6 +42,7 @@ func init() {
clusterCmd.PersistentFlags().StringVarP(&TorqueHelperCert, "cert", "c", defTorqueHelperCert, "Torque helper service certificate")

nodeVncCmd.Flags().StringVarP(&vncUser, "user", "u", "", "username of the VNC owner")
nodeVncCmd.Flags().StringVarP(&vncMachineListFile, "machine-list", "l", defMachineListFile, "path to the machinelist file")

nodeCmd.AddCommand(nodeMeminfoCmd, nodeDiskinfoCmd, nodeVncCmd, nodeInfoCmd)
jobCmd.AddCommand(jobTraceCmd, jobMeminfoCmd)
Expand Down Expand Up @@ -335,14 +339,14 @@ var nodeInfoCmd = &cobra.Command{
}

var nodeVncCmd = &cobra.Command{
Use: "vnc {hostname}",
Use: "vnc [{host1} {host2} ...]",
Short: "Print list of VNC servers on the cluster or a specific node.",
Long: `Print list of VNC servers on the cluster or a specific node.
If the {hostname} is specified, only the VNCs on the node will be shown.
When the username is specified by the "-u" option, only the VNCs owned by the user will be shown.`,
Args: cobra.MaximumNArgs(1),
Args: cobra.ArbitraryArgs,
Run: func(cmd *cobra.Command, args []string) {

nodes := make(chan string, 4)
Expand Down Expand Up @@ -389,7 +393,9 @@ When the username is specified by the "-u" option, only the VNCs owned by the us

// filling access node hosts
go func() {
// sort nodes
var mlist []string

// 1. read machinelist from user provided hosts from commandline arguments
sort.Strings(args)
for _, n := range args {

Expand All @@ -398,19 +404,44 @@ When the username is specified by the "-u" option, only the VNCs owned by the us
}

log.Debugf("add node %s\n", n)
nodes <- n
mlist = append(mlist, n)
}
if len(args) == 0 {

// 2. read machinelist from the machinelist file
if len(mlist) == 0 {
// read nodes from user provided machinelist

if fml, err := os.Open(vncMachineListFile); err == nil {
defer fml.Close()
scanner := bufio.NewScanner(fml)
for scanner.Scan() {
mlist = append(mlist, scanner.Text())
}

if err := scanner.Err(); err != nil {
log.Warnln(err)
}
} else {
log.Warnln(err)
}
}

// 3. read machinelist from the Gangalia
if len(mlist) == 0 {
// TODO: append hostname of all of the access nodes.
accs, err := dg.GetAccessNodes()
// sort nodes
sort.Strings(accs)
if err != nil {
log.Errorln(err)
}
for _, n := range accs {
nodes <- n
}

mlist = append(mlist, accs...)
}

// fill mlist to node channel
for _, n := range mlist {
nodes <- n
}
close(nodes)
}()
Expand Down

0 comments on commit 71de716

Please sign in to comment.