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)) } }
func configDaemon(ctx *cli.Context) { var ( client *cnc.Client err error ) first := ctx.Args().First() if first == "list" { for k, s := range daemon.DaemonOptionLibrary { fmt.Printf("%-24s %s\n", k, s.Description) } return } 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) } res, err := client.Ping() if err != nil { fmt.Fprintf(os.Stderr, "Unable to reach daemon: %s\n", err) os.Exit(1) } if res == nil { fmt.Fprintf(os.Stderr, "Empty response from daemon\n") os.Exit(1) } opts := ctx.Args() if len(opts) == 0 { res.Opts.Dump() return } dOpts := make(option.OptionMap, len(opts)) for k := range opts { name, value, err := option.ParseOption(opts[k], &daemon.DaemonOptionLibrary) if err != nil { fmt.Printf("%s\n", err) os.Exit(1) } dOpts[name] = value err = client.Update(dOpts) if err != nil { fmt.Fprintf(os.Stderr, "Unable to update daemon: %s\n", err) os.Exit(1) } } }