Ejemplo n.º 1
0
// SetConfigOption sets the value of the configuration option identified by
// the given name.
func (c *Conn) SetConfigOption(option, value string) error {
	c_opt, c_val := C.CString(option), C.CString(value)
	defer C.free(unsafe.Pointer(c_opt))
	defer C.free(unsafe.Pointer(c_val))
	ret := C.rados_conf_set(c.cluster, c_opt, c_val)
	if ret < 0 {
		return RadosError(int(ret))
	} else {
		return nil
	}
}
Ejemplo n.º 2
0
func (r *Rados) ClusterSetConfig(option, value string) error {
	coption := C.CString(option)
	cvalue := C.CString(value)
	defer func() {
		C.free(unsafe.Pointer(coption))
		C.free(unsafe.Pointer(cvalue))
	}()
	cerr := C.rados_conf_set(*r.cluster, coption, cvalue)
	if cerr < 0 {
		return errors.New("set config failed")
	}

	return nil
}
Ejemplo n.º 3
0
func (conn *Connection) configure() error {

	// use default configuration
	if conn.ConfigFile == "" && !conn.ParseArgs && conn.ConfigEnv == "" && len(conn.ConfigMap) == 0 {
		ret := C.rados_conf_read_file(conn.cluster.handle, nil)
		if err := toRadosError(ret); err != nil {
			err.Message = "Unable to load default configuration."
			return err
		}
		return nil
	}

	// use config file if specified
	if conn.ConfigFile != "" {
		config := C.CString(conn.ConfigFile)
		defer freeString(config)
		ret := C.rados_conf_read_file(conn.cluster.handle, config)
		if err := toRadosError(ret); err != nil {
			err.Message = "Unable to load configuration file. Make sure it exists and is accessible."
			return err
		}
	}

	// use config env if specified
	if conn.ConfigEnv != "" {
		env := C.CString(conn.ConfigEnv)
		defer freeString(env)
		ret := C.rados_conf_parse_env(conn.cluster.handle, env)
		if err := toRadosError(ret); err != nil {
			err.Message = "Unable to load configuration from env."
			return err
		}
	}

	// use config from args
	if conn.ParseArgs {
		argc := C.int(len(os.Args))
		argv := make([]*C.char, argc)
		for i, arg := range os.Args {
			argv[i] = C.CString(arg)
			defer freeString(argv[i+1])
		}
		ret := C.rados_conf_parse_argv(conn.cluster.handle, argc, &argv[0])
		if err := toRadosError(ret); err != nil {
			err.Message = "Unable to load configuration from args."
			return err
		}
	}

	if conn.ConfigMap != nil || len(conn.ConfigMap) > 0 {
		for k, v := range conn.ConfigMap {
			key := C.CString(k)
			val := C.CString(v)
			defer freeString(key)
			defer freeString(val)
			ret := C.rados_conf_set(conn.cluster.handle, key, val)
			if err := toRadosError(ret); err != nil {
				err.Message = fmt.Sprintf("Unable to load config %s=%s", key, val)
				return err
			}
		}
	}

	return nil
}