Skip to content

Commit

Permalink
Addedd additional output to stderr on runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
niasar committed Sep 11, 2019
1 parent a8a09b1 commit c12a887
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
"math"
"os"
"os/exec"
"strconv"
"strings"
)

func main() {
iface := flag.String("iface", "vmbr0", "network interface")
flag.Parse()
detectPveCluster()
_, _ = fmt.Fprintln(os.Stderr, "Gathering info about cluster nodes...")
list := getNodeNamelist()
ipAddr := getIPaddressess(list, *iface)
printResult(ipAddr, list)
Expand Down Expand Up @@ -49,6 +51,7 @@ func getIPaddressess(nodeList []string, iface string) map[string]string {
for i := range nodeList {
ifmap = make(map[string]string)
nodeName := nodeList[i]
_, _ = fmt.Fprintln(os.Stderr, strings.Join([]string{"[", strconv.Itoa(i + 1), "/", strconv.Itoa(len(nodeList)), "]"}, ""), "Gathering info about", nodeList[i], "\b...")
apiPath := strings.Join([]string{"/nodes/", nodeName, "/network"}, "")
jsonRaw, err := exec.Command("pvesh", "get", apiPath, "-output-format", "json").CombinedOutput() // Accessing proxmox API about interfaces on node
check(err)
Expand Down Expand Up @@ -76,6 +79,7 @@ func getIPaddressess(nodeList []string, iface string) map[string]string {
}

func printResult(ipMap map[string]string, nodeList []string) {
fmt.Fprintln(os.Stderr, "Printing result...")
var longest int
longest = 0
for i := range nodeList {
Expand All @@ -102,6 +106,7 @@ func printResult(ipMap map[string]string, nodeList []string) {
}
fmt.Println(strings.Join([]string{i, tabulator, ipAddr}, ""))
}
fmt.Fprintln(os.Stderr, "Done!")
}

func detectPveCluster() {
Expand Down

0 comments on commit c12a887

Please sign in to comment.