Example #1
0
func newWithConfig(configPath string) (types.Client, error) {
	config := gofig.New()
	if err := config.ReadConfigFile(configPath); err != nil {
		return nil, err
	}
	return client.New(nil, config)
}
Example #2
0
// NewWithConfigReader creates a new REX-Ray instance and configures it with a
// custom configuration stream.
func NewWithConfigReader(in io.Reader) (*core.RexRay, error) {
	c := gofig.New()
	if err := c.ReadConfig(in); err != nil {
		return nil, err
	}
	return core.New(c), nil
}
Example #3
0
func getTestConfig(
	t *testing.T,
	clientType types.ClientType,
	configBuf []byte,
	debug bool) gofig.Config {

	config := gofigCore.New()

	if debug {
		log.SetLevel(log.DebugLevel)
		err := config.ReadConfig(bytes.NewReader(debugConfig))
		if err != nil {
			t.Fatal(err)
		}
	}

	clientTypeConfig := []byte(fmt.Sprintf(clientTypeConfigFormat, clientType))
	if err := config.ReadConfig(bytes.NewReader(clientTypeConfig)); err != nil {
		t.Fatal(err)
	}

	if err := config.ReadConfig(bytes.NewReader(profilesConfig)); err != nil {
		t.Fatal(err)
	}

	if configBuf != nil {
		if err := config.ReadConfig(bytes.NewReader(configBuf)); err != nil {
			t.Fatal(err)
		}
	}

	return config
}
Example #4
0
// NewWithConfigFile creates a new REX-Ray instance and configures it with a
// custom configuration file.
func NewWithConfigFile(path string) (*core.RexRay, error) {
	c := gofig.New()
	if err := c.ReadConfigFile(path); err != nil {
		return nil, err
	}
	return core.New(c), nil
}
Example #5
0
func getRexRayNoDrivers() (*core.RexRay, error) {
	c := gofig.New()
	c.Set("rexray.osDrivers", []string{""})
	c.Set("rexray.volumeDrivers", []string{""})
	c.Set("rexray.storageDrivers", []string{""})
	r := core.New(c)
	r.InitDrivers()
	return r, nil
}
Example #6
0
func TestNewNoVolumeDrivers(t *testing.T) {
	c := gofig.New()
	c.Set("rexray.osDrivers", []string{mock.MockOSDriverName})
	c.Set("rexray.volumeDrivers", []string{})
	c.Set("rexray.storageDrivers", []string{mock.MockStorDriverName})
	r := core.New(c)
	if err := r.InitDrivers(); err != errors.ErrNoVolumeDrivers {
		t.Fatal(err)
	}
}
Example #7
0
func getRexRay() (*core.RexRay, error) {
	c := gofig.New()
	c.Set("rexray.osDrivers", []string{mock.MockOSDriverName})
	c.Set("rexray.volumeDrivers", []string{mock.MockVolDriverName})
	c.Set("rexray.storageDrivers", []string{mock.MockStorDriverName})
	r := core.New(c)

	if err := r.InitDrivers(); err != nil {
		return nil, err
	}

	return r, nil
}
Example #8
0
func init() {
	//tcpAddr := fmt.Sprintf("tcp://:%d", ModPort)

	_, fsPath, parseAddrErr := gotil.ParseAddress(modAddress)
	if parseAddrErr != nil {
		panic(parseAddrErr)
	}

	fsPathDir := filepath.Dir(fsPath)
	os.MkdirAll(fsPathDir, 0755)

	mc := &module.Config{
		Address: modAddress,
		Config:  gofig.New(),
	}

	module.RegisterModule(modName, true, newModule, []*module.Config{mc})
}
Example #9
0
// New creates a new REX-Ray instance and configures it with the
// provided configuration instance.
func New(conf gofig.Config) *RexRay {

	if conf == nil {
		conf = gofig.New()
	}

	r := &RexRay{
		Config:  conf,
		drivers: map[string]Driver{},
	}

	for name, ctor := range driverCtors {
		r.drivers[name] = ctor()
		log.WithField("driverName", name).Debug("constructed driver")
	}

	return r
}
Example #10
0
// InitializeDefaultModules initializes the default modules.
func InitializeDefaultModules() error {
	modTypesRwl.RLock()
	defer modTypesRwl.RUnlock()

	c := gofig.New()
	modConfigs, err := getConfiguredModules(c)
	if err != nil {
		return err
	}

	for _, mc := range modConfigs {
		mod, err := InitializeModule(mc)
		if err != nil {
			return err
		}
		func() {
			modInstancesRwl.Lock()
			defer modInstancesRwl.Unlock()
			modInstances[mod.Name] = mod
		}()
	}

	return nil
}
Example #11
0
// Run the server.
func Run() {
	server.CloseOnAbort()

	flag.Usage = printUsage
	flag.Parse()

	if flagVersion != nil && *flagVersion {
		_, _, thisExeAbsPath := gotil.GetThisPathParts()
		fmt.Fprintf(os.Stdout, "Binary: %s\n", thisExeAbsPath)
		fmt.Fprint(os.Stdout, api.Version.String())
		os.Exit(0)
	}

	if flagEnv != nil && *flagEnv {
		for _, v := range os.Environ() {
			fmt.Fprintf(os.Stdout, "%s\n", v)
		}
		os.Exit(0)
	}

	// if a config is specified then do not care about any other options
	if flagConfig != nil && gotil.FileExists(*flagConfig) {

		config = gofigCore.New()

		if err := config.ReadConfigFile(*flagConfig); err != nil {
			fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
			os.Exit(1)
		}

		if flagPrintConfig != nil && *flagPrintConfig {
			jstr, err := config.ToJSON()
			if err != nil {
				fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
				os.Exit(1)
			}
			fmt.Fprintln(os.Stdout, jstr)
			os.Exit(0)
		}

		s, errs, err := server.Serve(nil, config)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
			os.Exit(1)
		}

		err = <-errs
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
			os.Exit(1)
		}

		s.Close()
		os.Exit(0)
	}

	cfg, err := apiconfig.NewConfig()
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
		os.Exit(1)
	}

	config = cfg
	for _, fs := range config.FlagSets() {
		flag.CommandLine.AddFlagSet(fs)
	}

	if flagHelp != nil && *flagHelp {
		flag.Usage()
	}

	if len(flag.Args()) == 0 {
		flag.Usage()
	}

	if flagHost != nil {
		os.Setenv("LIBSTORAGE_HOST", *flagHost)
	}

	if flagLogLvl != nil {
		os.Setenv("LIBSTORAGE_LOGGING_LEVEL", *flagLogLvl)
	}

	if lvl, err := log.ParseLevel(
		config.GetString(apitypes.ConfigLogLevel)); err == nil {
		log.SetLevel(lvl)
	}

	if flagPrintConfig != nil && *flagPrintConfig {
		jstr, err := config.ToJSON()
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
			os.Exit(1)
		}
		fmt.Fprintln(os.Stdout, jstr)
		os.Exit(0)
	}

	buf := &bytes.Buffer{}
	fmt.Fprintf(buf, "libstorage:\n  server:\n    services:\n")
	for _, ds := range flag.Args() {
		dsp := strings.Split(ds, ":")
		dn := dsp[0]
		sn := dsp[0]
		if len(dsp) > 1 {
			sn = dsp[1]
		}
		fmt.Fprintf(buf, "      %s:\n        driver: %s\n", sn, dn)
	}
	if err := config.ReadConfig(buf); err != nil {
		fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
		os.Exit(1)
	}

	server.CloseOnAbort()

	_, errs, err := server.Serve(nil, config)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
		os.Exit(1)
	}

	<-errs
}
Example #12
0
// New creates a new REX-Ray instance and configures using the standard
// configuration workflow: environment variables followed by global and user
// configuration files.
func New() (*core.RexRay, error) {
	return core.New(gofig.New()), nil
}