예제 #1
0
파일: conn.go 프로젝트: Xmagicer/origin
// ParseCmdLineArgs configures the connection from command line arguments.
func (c *Conn) ParseCmdLineArgs(args []string) error {
	// add an empty element 0 -- Ceph treats the array as the actual contents
	// of argv and skips the first element (the executable name)
	argc := C.int(len(args) + 1)
	argv := make([]*C.char, argc)

	// make the first element a string just in case it is ever examined
	argv[0] = C.CString("placeholder")
	defer C.free(unsafe.Pointer(argv[0]))

	for i, arg := range args {
		argv[i+1] = C.CString(arg)
		defer C.free(unsafe.Pointer(argv[i+1]))
	}

	ret := C.rados_conf_parse_argv(c.cluster, argc, &argv[0])
	if ret < 0 {
		return RadosError(int(ret))
	} else {
		return nil
	}
}
예제 #2
0
파일: grados.go 프로젝트: objStorage/grados
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
}