Exemple #1
0
func start(
	ctx apitypes.Context,
	config gofig.Config,
	host string,
	stop <-chan os.Signal) (<-chan error, error) {
	ctx, _, errs, err := util.ActivateLibStorage(ctx, config)
	if err != nil {
		ctx.WithError(err).Error(
			"error activing libStorage in server-only mode")
		return nil, err
	}
	return errs, nil
}
Exemple #2
0
// InitializeDefaultModules initializes the default modules.
func InitializeDefaultModules(
	ctx apitypes.Context,
	config gofig.Config) (<-chan error, error) {

	modTypesRwl.RLock()
	defer modTypesRwl.RUnlock()

	var (
		err  error
		mod  *Instance
		errs <-chan error
	)

	// enable path caching for the modules
	config.Set(apitypes.ConfigIgVolOpsPathCacheEnabled, true)

	ctx, config, errs, err = util.ActivateLibStorage(ctx, config)
	if err != nil {
		return nil, err
	}

	modConfigs, err := getConfiguredModules(ctx, config)
	if err != nil {
		return nil, err
	}

	ctx.WithField("len(modConfigs)", len(modConfigs)).Debug(
		"got configured modules")

	for _, mc := range modConfigs {

		ctx.WithField("name", mc.Name).Debug(
			"creating libStorage client for module instance")

		if mc.Client, err = util.NewClient(ctx, mc.Config); err != nil {
			panic(err)
		}

		if mod, err = InitializeModule(ctx, mc); err != nil {
			return nil, err
		}

		modInstances[mod.Name] = mod
	}

	return errs, nil
}
Exemple #3
0
func (c *CLI) preRun(cmd *cobra.Command, args []string) {

	if c.cfgFile != "" && gotil.FileExists(c.cfgFile) {
		util.ValidateConfig(c.cfgFile)
		if err := c.config.ReadConfigFile(c.cfgFile); err != nil {
			panic(err)
		}
		os.Setenv("REXRAY_CONFIG_FILE", c.cfgFile)
		cmd.Flags().Parse(os.Args[1:])
	}

	c.updateLogLevel()

	// disable path caching for the CLI
	c.config.Set(apitypes.ConfigIgVolOpsPathCacheEnabled, false)

	if v := c.rrHost(); v != "" {
		c.config.Set(apitypes.ConfigHost, v)
	}
	if v := c.rrService(); v != "" {
		c.config.Set(apitypes.ConfigService, v)
	}

	if isHelpFlag(cmd) {
		cmd.Help()
		panic(&helpFlagPanic{})
	}

	if permErr := c.checkCmdPermRequirements(cmd); permErr != nil {
		if term.IsTerminal() {
			printColorizedError(permErr)
		} else {
			printNonColorizedError(permErr)
		}

		fmt.Println()
		cmd.Help()
		panic(&printedErrorPanic{})
	}

	c.ctx.WithField("val", os.Args).Debug("os.args")

	if c.activateLibStorage {

		if c.runAsync {
			c.ctx = c.ctx.WithValue("async", true)
		}

		c.ctx.WithField("cmd", cmd.Name()).Debug("activating libStorage")

		var err error
		c.ctx, c.config, c.rsErrs, err = util.ActivateLibStorage(
			c.ctx, c.config)
		if err == nil {
			c.ctx.WithField("cmd", cmd.Name()).Debug(
				"creating libStorage client")
			c.r, err = util.NewClient(c.ctx, c.config)
		}

		if err != nil {
			if term.IsTerminal() {
				printColorizedError(err)
			} else {
				printNonColorizedError(err)
			}
			fmt.Println()
			cmd.Help()
			panic(&printedErrorPanic{})
		}
	}
}