// ParseDefaultConfigEnv configures the connection from the default Ceph // environment variable(s). func (c *Conn) ParseDefaultConfigEnv() error { ret := C.rados_conf_parse_env(c.cluster, nil) if ret == 0 { return nil } else { return RadosError(int(ret)) } }
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 }