Exemplo n.º 1
0
func statusDaemon(ctx *cli.Context) {
	var (
		client *cnc.Client
		err    error
	)
	if host := ctx.GlobalString("host"); host == "" {
		client, err = cnc.NewDefaultClient()
	} else {
		client, err = cnc.NewClient(host, nil)
	}
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error while creating cilium-client: %s\n", err)
		os.Exit(1)
	}

	if sr, err := client.GlobalStatus(); err != nil {
		fmt.Fprintf(os.Stderr, "Status: ERROR - Unable to reach out daemon: %s\n", err)
		os.Exit(1)
	} else {
		w := tabwriter.NewWriter(os.Stdout, 2, 0, 3, ' ', 0)
		fmt.Fprintf(w, "KVStore:\t%s\n", sr.KVStore)
		fmt.Fprintf(w, "Docker:\t%s\n", sr.Docker)
		fmt.Fprintf(w, "Kubernetes:\t%s\n", sr.Kubernetes)
		fmt.Fprintf(w, "Cilium:\t%s\n", sr.Cilium)
		w.Flush()

		if sr.IPAMStatus != nil {
			fmt.Printf("V4 addresses reserved:\n")
			for _, ipv4 := range sr.IPAMStatus["4"] {
				fmt.Printf(" %s\n", ipv4)

			}
			fmt.Printf("V6 addresses reserved:\n")
			for _, ipv6 := range sr.IPAMStatus["6"] {
				fmt.Printf(" %s\n", ipv6)
			}
			w.Flush()
		}

		os.Exit(int(sr.Cilium.Code))
	}

}