示例#1
0
func getConfig(flagset *flag.FlagSet, file string) (*config.Config, error) {
	if _, err := os.Stat(file); err != nil {
		glog.Infof("Config file %s does not appear to exist - ignoring")
		file = ""
	}

	opts := globalconf.Options{
		EnvPrefix:  "FLEET_",
		ConfigFile: file,
	}
	gconf, err := globalconf.NewWithOptions(opts)
	if err != nil {
		return nil, err
	}

	gconf.ParseSet("", flagset)

	cfg := config.NewConfig()
	cfg.Verbosity = (*flagset.Lookup("verbosity")).Value.(flag.Getter).Get().(int)
	cfg.EtcdServers = (*flagset.Lookup("etcd_servers")).Value.(flag.Getter).Get().(stringSlice)
	cfg.BootId = (*flagset.Lookup("boot_id")).Value.(flag.Getter).Get().(string)
	cfg.PublicIP = (*flagset.Lookup("public_ip")).Value.(flag.Getter).Get().(string)
	cfg.RawMetadata = (*flagset.Lookup("metadata")).Value.(flag.Getter).Get().(string)
	cfg.UnitPrefix = (*flagset.Lookup("unit_prefix")).Value.(flag.Getter).Get().(string)
	cfg.AgentTTL = (*flagset.Lookup("agent_ttl")).Value.(flag.Getter).Get().(string)

	return cfg, nil
}
示例#2
0
文件: cmd.go 项目: nullstyle/fleet
func main() {
	app := cli.NewApp()
	app.Name = "fleetctl"
	app.Usage = "fleetctl is a command line driven interface to the cluster wide CoreOS init system."

	app.Flags = []cli.Flag{
		cli.StringFlag{"endpoint", "http://127.0.0.1:4001", "Fleet Engine API endpoint (etcd)"},
		cli.StringFlag{"tunnel", "", "Establish an SSH tunnel through the provided address for communication with fleet and etcd."},
		cli.BoolTFlag{"strict-host-key-checking", "Do strict check on known hosts for ssh connection. Defaults to 'true'."},
		cli.StringFlag{"known-hosts-file", ssh.DefaultKnownHostsFile, "Location for known_hosts file"},
	}

	app.Commands = []cli.Command{
		newListUnitsCommand(),
		newSubmitUnitCommand(),
		newDestroyUnitCommand(),
		newStartUnitCommand(),
		newStopUnitCommand(),
		newStatusUnitsCommand(),
		newCatUnitCommand(),
		newListMachinesCommand(),
		newJournalCommand(),
		newSSHCommand(),
		newVerifyUnitCommand(),
		newDebugInfoCommand(),
	}

	for _, f := range app.Flags {
		f.Apply(flagset)
	}

	flagset.Bool("version", false, "Print the version and exit")

	flagset.Parse(os.Args[1:])

	if (*flagset.Lookup("version")).Value.(flag.Getter).Get().(bool) {
		fmt.Println("fleetctl version", version.Version)
		os.Exit(0)
	}

	globalconf.Register("fleetctl", flagset)
	opts := globalconf.Options{EnvPrefix: "FLEETCTL_"}
	gconf, _ := globalconf.NewWithOptions(&opts)
	gconf.ParseSet("", flagset)

	registryCtl = NewRegistry(getRegistry())
	app.Run(os.Args)
}
示例#3
0
func getConfig(flagset *flag.FlagSet, userCfgFile string) (*config.Config, error) {
	opts := globalconf.Options{EnvPrefix: "FLEET_"}

	if userCfgFile != "" {
		// Fail hard if a user-provided config is not usable
		fi, err := os.Stat(userCfgFile)
		if err != nil {
			log.Fatalf("Unable to use config file %s: %v", userCfgFile, err)
		}
		if fi.IsDir() {
			log.Fatalf("Provided config %s is a directory, not a file", userCfgFile)
		}

		log.Infof("Using provided config file %s", userCfgFile)
		opts.Filename = userCfgFile

	} else if _, err := os.Stat(DefaultConfigFile); err == nil {
		log.Infof("Using default config file %s", DefaultConfigFile)
		opts.Filename = DefaultConfigFile
	} else {
		log.Infof("No provided or default config file found - proceeding without")
	}

	gconf, err := globalconf.NewWithOptions(&opts)
	if err != nil {
		return nil, err
	}

	gconf.ParseSet("", flagset)

	cfg := config.Config{
		Verbosity:          (*flagset.Lookup("verbosity")).Value.(flag.Getter).Get().(int),
		EtcdServers:        (*flagset.Lookup("etcd_servers")).Value.(flag.Getter).Get().(stringSlice),
		EtcdKeyPrefix:      (*flagset.Lookup("etcd_key_prefix")).Value.(flag.Getter).Get().(string),
		PublicIP:           (*flagset.Lookup("public_ip")).Value.(flag.Getter).Get().(string),
		RawMetadata:        (*flagset.Lookup("metadata")).Value.(flag.Getter).Get().(string),
		AgentTTL:           (*flagset.Lookup("agent_ttl")).Value.(flag.Getter).Get().(string),
		VerifyUnits:        (*flagset.Lookup("verify_units")).Value.(flag.Getter).Get().(bool),
		AuthorizedKeysFile: (*flagset.Lookup("authorized_keys_file")).Value.(flag.Getter).Get().(string),
	}

	config.UpdateLoggingFlagsFromConfig(flag.CommandLine, &cfg)

	return &cfg, nil
}
示例#4
0
func getConfig(flagset *flag.FlagSet, userCfgFile string) (*config.Config, error) {
	opts := globalconf.Options{EnvPrefix: "FLEET_"}

	if userCfgFile != "" {
		// Fail hard if a user-provided config is not usable
		if _, err := os.Stat(userCfgFile); err != nil {
			glog.Errorf("Unable to use config file %s: %v", userCfgFile, err)
			os.Exit(1)
		}

		glog.Infof("Using provided config file %s", userCfgFile)
		opts.Filename = userCfgFile

	} else if _, err := os.Stat(DefaultConfigFile); err == nil {
		glog.Infof("Using default config file %s", DefaultConfigFile)
		opts.Filename = DefaultConfigFile
	} else {
		glog.Infof("Continuing without config file")
	}

	gconf, err := globalconf.NewWithOptions(&opts)
	if err != nil {
		return nil, err
	}

	gconf.ParseSet("", flagset)

	cfg := config.Config{
		Verbosity:   (*flagset.Lookup("verbosity")).Value.(flag.Getter).Get().(int),
		EtcdServers: (*flagset.Lookup("etcd_servers")).Value.(flag.Getter).Get().(stringSlice),
		BootId:      (*flagset.Lookup("boot_id")).Value.(flag.Getter).Get().(string),
		PublicIP:    (*flagset.Lookup("public_ip")).Value.(flag.Getter).Get().(string),
		RawMetadata: (*flagset.Lookup("metadata")).Value.(flag.Getter).Get().(string),
		UnitPrefix:  (*flagset.Lookup("unit_prefix")).Value.(flag.Getter).Get().(string),
		AgentTTL:    (*flagset.Lookup("agent_ttl")).Value.(flag.Getter).Get().(string),
	}

	config.UpdateLoggingFlagsFromConfig(flag.CommandLine, &cfg)

	return &cfg, nil
}
示例#5
0
func main() {
	app := cli.NewApp()
	app.Version = version.Version
	app.Name = "fleetctl"
	app.Usage = "fleetctl is a command line driven interface to the cluster wide CoreOS init system."

	app.Flags = []cli.Flag{
		cli.StringFlag{"endpoint", "http://127.0.0.1:4001", "Fleet Engine API endpoint (etcd)"},
		cli.StringFlag{"tunnel", "", "Establish an SSH tunnel through the provided address for communication with fleet and etcd."},
	}

	app.Commands = []cli.Command{
		newListUnitsCommand(),
		newSubmitUnitCommand(),
		newDestroyUnitCommand(),
		newStartUnitCommand(),
		newStopUnitCommand(),
		newStatusUnitsCommand(),
		newCatUnitCommand(),
		newListMachinesCommand(),
		newJournalCommand(),
		newSSHCommand(),
	}

	//flagset := flag.NewFlagSet("fleetctl", flag.ExitOnError)
	for _, flag := range app.Flags {
		flag.Apply(flagset)
	}

	flagset.Parse(os.Args[1:])

	globalconf.Register("fleetctl", flagset)

	opts := globalconf.Options{
		EnvPrefix: "FLEETCTL_",
	}
	gconf, _ := globalconf.NewWithOptions(opts)
	gconf.ParseSet("", flagset)

	app.Run(os.Args)
}