Exemple #1
0
// initDefaultLibStorageServices initializes the config object with a default
// libStorage service if one is not present.
//
// TODO Move this into libStorage in libStorage 0.1.2
func initDefaultLibStorageServices(
	ctx apitypes.Context, config gofig.Config) error {

	if config.IsSet(apitypes.ConfigServices) {
		ctx.Debug(
			"libStorage auto service mode disabled; services defined")
		return nil
	}

	serviceName := config.GetString(apitypes.ConfigService)
	if serviceName == "" {
		ctx.Debug(
			"libStorage auto service mode disabled; service name empty")
		return nil
	}

	ctx.WithField("driver", serviceName).Info(
		"libStorage auto service mode enabled")

	buf := &bytes.Buffer{}
	fmt.Fprintf(buf, defaultServiceConfigFormat, serviceName)

	if err := config.ReadConfig(buf); err != nil {
		return err
	}

	return nil
}
// BackCompat ensures keys can be used from old configurations.
func BackCompat(config gofig.Config) {
	ec2Checks := [][]string{
		{ConfigEBSAccessKey, ConfigEC2AccessKey},
		{ConfigEBSSecretKey, ConfigEC2SecretKey},
		{ConfigEBSRegion, ConfigEC2Region},
		{ConfigEBSEndpoint, ConfigEC2Endpoint},
		{ConfigEBSMaxRetries, ConfigEC2MaxRetries},
		{ConfigEBSTag, ConfigEC2Tag},
		{ConfigEBSRexrayTag, ConfigEC2RexrayTag},
		{ConfigEBSKmsKeyID, ConfigEC2KmsKeyID},
	}
	for _, check := range ec2Checks {
		if !config.IsSet(check[0]) && config.IsSet(check[1]) {
			log.Debug(config.Get(check[1]))
			config.Set(check[0], config.Get(check[1]))
		}
	}

	awsChecks := [][]string{
		{ConfigEBSAccessKey, ConfigAWSAccessKey},
		{ConfigEBSSecretKey, ConfigAWSSecretKey},
		{ConfigEBSRegion, ConfigAWSRegion},
		{ConfigEBSEndpoint, ConfigAWSEndpoint},
		{ConfigEBSMaxRetries, ConfigAWSMaxRetries},
		{ConfigEBSTag, ConfigAWSTag},
		{ConfigEBSRexrayTag, ConfigAWSRexrayTag},
		{ConfigEBSKmsKeyID, ConfigAWSKmsKeyID},
	}
	for _, check := range awsChecks {
		if !config.IsSet(check[0]) && config.IsSet(check[1]) {
			log.Debug(config.Get(check[1]))
			config.Set(check[0], config.Get(check[1]))
		}
	}
}
Exemple #3
0
func isSet(
	config gofig.Config,
	key string,
	roots ...string) bool {

	for _, r := range roots {
		rk := strings.Replace(key, "libstorage.", fmt.Sprintf("%s.", r), 1)
		if config.IsSet(rk) {
			return true
		}
	}

	if config.IsSet(key) {
		return true
	}

	return false
}
Exemple #4
0
// ActivateLibStorage activates libStorage and returns a possibly mutated
// context.
func ActivateLibStorage(
	ctx apitypes.Context,
	config gofig.Config) (apitypes.Context, gofig.Config, <-chan error, error) {

	config = config.Scope("rexray")

	// set the `libstorage.service` property to the value of
	// `rexray.storageDrivers` if the former is not defined and the
	// latter is
	if !config.IsSet(apitypes.ConfigService) &&
		config.IsSet("rexray.storageDrivers") {
		if sd := config.GetStringSlice("rexray.storageDrivers"); len(sd) > 0 {
			config.Set(apitypes.ConfigService, sd[0])
		} else if sd := config.GetString("rexray.storageDrivers"); sd != "" {
			config.Set(apitypes.ConfigService, sd)
		}
	}

	if !config.IsSet(apitypes.ConfigIgVolOpsMountPath) {
		config.Set(apitypes.ConfigIgVolOpsMountPath, LibFilePath("volumes"))
	}

	var (
		err  error
		errs <-chan error
	)

	ctx, config, errs, err = activateLibStorage(ctx, config)
	if err != nil {
		return ctx, config, errs, err
	}

	return ctx, config, errs, nil
}
// BackCompat ensures keys can be used from old configurations.
func BackCompat(config gofig.Config) {
	checks := [][]string{
		{ConfigIgVolOpsMountPreempt, ConfigOldIntegrationVolMountPreempt},
		{ConfigIgVolOpsCreateDisable, ConfigOldIntegrationVolCreateDisable},
		{ConfigIgVolOpsRemoveDisable, ConfigOldIntegrationVolRemoveDisable},
		{ConfigIgVolOpsUnmountIgnoreUsed, ConfigOldIntegrationVolUnmountIgnoreUsed},
		{ConfigIgVolOpsPathCacheEnabled, ConfigOldIntegrationVolPathCache},
		{ConfigIgVolOpsCreateDefaultFsType, ConfigOldDockerFsType},
		{ConfigIgVolOpsCreateDefaultType, ConfigOldDockerVolumeType},
		{ConfigIgVolOpsCreateDefaultIOPS, ConfigOldDockerIOPS},
		{ConfigIgVolOpsCreateDefaultSize, ConfigOldDockerSize},
		{ConfigIgVolOpsCreateDefaultAZ, ConfigOldDockerAvailabilityZone},
		{ConfigIgVolOpsMountPath, ConfigOldDockerMountDirPath},
		{ConfigIgVolOpsMountRootPath, ConfigOldDockerLinuxVolumeRootPath},
	}
	for _, check := range checks {
		if !config.IsSet(check[0]) && config.IsSet(check[1]) {
			log.Debug(config.Get(check[1]))
			config.Set(check[0], config.Get(check[1]))
		}
	}
}
Exemple #6
0
// New returns a new libStorage client.
func New(goCtx gocontext.Context, config gofig.Config) (types.Client, error) {

	if config == nil {
		var err error
		if config, err = apicnfg.NewConfig(); err != nil {
			return nil, err
		}
	}

	config = config.Scope(types.ConfigClient)
	types.BackCompat(config)

	var (
		c   *client
		err error
	)

	c = &client{ctx: context.New(goCtx), config: config}
	c.ctx = c.ctx.WithValue(context.ClientKey, c)

	logFields := log.Fields{}
	logConfig, err := utils.ParseLoggingConfig(
		config, logFields, "libstorage.client")
	if err != nil {
		return nil, err
	}

	// always update the server context's log level
	context.SetLogLevel(c.ctx, logConfig.Level)
	c.ctx.WithFields(logFields).Info("configured logging")

	if config.IsSet(types.ConfigService) {
		c.ctx = c.ctx.WithValue(
			context.ServiceKey, config.GetString(types.ConfigService))
	}

	storDriverName := config.GetString(types.ConfigStorageDriver)
	if storDriverName == "" {
		c.ctx.Warn("no storage driver found")
	} else {
		if c.sd, err = registry.NewStorageDriver(storDriverName); err != nil {
			return nil, err
		}
		if err = c.sd.Init(c.ctx, config); err != nil {
			return nil, err
		}
		if papi, ok := c.sd.(types.ProvidesAPIClient); ok {
			c.api = papi.API()
		}
		if pxli, pxliOk := c.sd.(types.ProvidesStorageExecutorCLI); pxliOk {
			c.xli = pxli.XCLI()
		}
		c.ctx.Info("storage driver initialized")
	}

	// if the API or XLI are nil, then the storage driver is not the libStorage
	// storage driver, and we should jump avoid any more initialization
	if c.api == nil || c.xli == nil {
		c.ctx.Info("created libStorage client")
		return c, nil
	}

	osDriverName := config.GetString(types.ConfigOSDriver)
	if osDriverName == "" {
		c.ctx.Warn("no os driver found")
	} else {
		if c.od, err = registry.NewOSDriver(osDriverName); err != nil {
			return nil, err
		}
		if err = c.od.Init(c.ctx, config); err != nil {
			return nil, err
		}
		c.ctx.Info("os driver initialized")
	}

	intDriverName := config.GetString(types.ConfigIntegrationDriver)
	if intDriverName == "" {
		c.ctx.Warn("no integration driver found")
	} else {
		if c.id, err = registry.NewIntegrationDriver(
			intDriverName); err != nil {
			return nil, err
		}
		if err := c.id.Init(c.ctx, config); err != nil {
			return nil, err
		}
		c.ctx.Info("integration driver initialized")
	}

	c.ctx.Info("created libStorage client")
	return c, nil
}