Adding ability to print out responses as JSON.

This commit is contained in:
Renan DelValle 2018-11-09 15:58:26 -08:00
parent dcb27f64c2
commit bc28198c2d
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9
8 changed files with 210 additions and 130 deletions

View file

@ -2,10 +2,10 @@ package cmd
import (
"fmt"
"os"
"github.com/paypal/gorealis/gen-go/apache/aurora"
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
)
func init() {
@ -38,31 +38,46 @@ expects a space separated list of hosts to place into maintenance mode.`,
}
func drain(cmd *cobra.Command, args []string) {
fmt.Println("Setting hosts to DRAINING")
fmt.Println(args)
log.Infoln("Setting hosts to DRAINING")
log.Infoln(args)
_, result, err := client.DrainHosts(args...)
if err != nil {
fmt.Printf("error: %+v\n", err.Error())
os.Exit(1)
log.Fatalf("error: %+v\n", err)
}
log.Debugln(result)
// Monitor change to DRAINING and DRAINED mode
hostResult, err := monitor.HostMaintenance(
args,
[]aurora.MaintenanceMode{aurora.MaintenanceMode_DRAINED},
monitorInterval,
monitorTimeout)
transitioned := make([]string, 0,0)
if err != nil {
nonTransitioned := make([]string, 0,0)
for host, ok := range hostResult {
if !ok {
fmt.Printf("Host %s did not transtion into desired mode(s)\n", host)
if ok {
transitioned = append(transitioned, host)
} else {
nonTransitioned = append(nonTransitioned, host)
}
}
fmt.Printf("error: %+v\n", err.Error())
return
log.Printf("error: %+v\n", err)
if toJson {
fmt.Println(toJSON(nonTransitioned))
} else {
fmt.Println("Did not enter DRAINED status: ", nonTransitioned)
}
}
fmt.Println(result.String())
if toJson {
fmt.Println(toJSON(transitioned))
} else {
fmt.Println("Entered DRAINED status: ", transitioned)
}
}