Example #1
0
func configEndpoint(ctx *cli.Context) {
	if ctx.Args().First() == "list" {
		listEndpointOptions()
		return
	}
	epID, err := getValidEPID(ctx.Args().First())
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", err)
		return
	}

	ep, err := client.EndpointGet(epID)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error while getting endpoint %d from daemon: %s\n", epID, err)
		os.Exit(1)
	}

	if ep == nil {
		fmt.Printf("Endpoint %d not found\n", epID)
		os.Exit(1)
	}

	opts := ctx.Args().Tail()
	if len(opts) == 0 {
		ep.Opts.Dump()
		return
	}

	epOpts := make(option.OptionMap, len(opts))

	for k := range opts {
		name, value, err := option.ParseOption(opts[k], &endpoint.EndpointOptionLibrary)
		if err != nil {
			fmt.Printf("%s\n", err)
			os.Exit(1)
		}

		epOpts[name] = value
	}

	err = client.EndpointUpdate(ep.ID, epOpts)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to update endpoint %d: %s\n", ep.ID, err)
		os.Exit(1)
	}
}
Example #2
0
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)
		}
	}
}