Esempio n. 1
1
func listPools(conn *rados.Conn, prefix string) {
	pools, err := conn.ListPools()
	if err != nil {
		fmt.Println("error when list pool", err)
		os.Exit(1)
	}
	fmt.Println(prefix, ":", pools)
}
Esempio n. 2
0
// connect builds up the ceph conn and default pool
func (d *cephRBDVolumeDriver) connect(pool string) error {
	log.Printf("INFO: connect() to Ceph via go-ceph, with pool: %s", pool)

	// create the go-ceph Client Connection
	var cephConn *rados.Conn
	var err error
	if d.cluster == "" {
		cephConn, err = rados.NewConnWithUser(d.user)
	} else {
		// FIXME: TODO: can't seem to use a cluster name -- get error -22 from noahdesu/go-ceph/rados:
		// panic: Unable to create ceph connection to cluster=ceph with user=admin: rados: ret=-22
		cephConn, err = rados.NewConnWithClusterAndUser(d.cluster, d.user)
	}
	if err != nil {
		log.Printf("ERROR: Unable to create ceph connection to cluster=%s with user=%s: %s", d.cluster, d.user, err)
		return err
	}

	// read ceph.conf and setup connection
	if d.config == "" {
		err = cephConn.ReadDefaultConfigFile()
	} else {
		err = cephConn.ReadConfigFile(d.config)
	}
	if err != nil {
		log.Printf("ERROR: Unable to read ceph config: %s", err)
		return err
	}

	err = cephConn.Connect()
	if err != nil {
		log.Printf("ERROR: Unable to connect to Ceph: %s", err)
		return err
	}

	// can now set conn in driver
	d.conn = cephConn

	// setup the requested pool context
	ioctx, err := d.goceph_openContext(pool)
	if err != nil {
		return err
	}
	d.ioctx = ioctx

	return nil
}
Esempio n. 3
0
// connect builds up the ceph conn and default pool
func (d *cephRBDVolumeDriver) connect() {
	log.Println("INFO: connecting to Ceph and default pool context")
	d.m.Lock()
	defer d.m.Unlock()

	// create reusable go-ceph Client Connection
	var cephConn *rados.Conn
	var err error
	if d.cluster == "" {
		cephConn, err = rados.NewConnWithUser(d.user)
	} else {
		// FIXME: TODO: can't seem to use a cluster name -- get error -22 from go-ceph/rados:
		// panic: Unable to create ceph connection to cluster=ceph with user=admin: rados: ret=-22
		cephConn, err = rados.NewConnWithClusterAndUser(d.cluster, d.user)
	}
	if err != nil {
		log.Panicf("ERROR: Unable to create ceph connection to cluster=%s with user=%s: %s", d.cluster, d.user, err)
	}

	// read ceph.conf and setup connection
	if d.config == "" {
		err = cephConn.ReadDefaultConfigFile()
	} else {
		err = cephConn.ReadConfigFile(d.config)
	}
	if err != nil {
		log.Panicf("ERROR: Unable to read ceph config: %s", err)
	}

	err = cephConn.Connect()
	if err != nil {
		log.Panicf("ERROR: Unable to connect to Ceph: %s", err)
	}

	// can now set conn in driver
	d.conn = cephConn

	// setup the default context (pool most likely to be used)
	defaultContext, err := d.openContext(d.defaultPool)
	if err != nil {
		log.Panicf("ERROR: Unable to connect to default Ceph Pool: %s", err)
	}
	d.defaultIoctx = defaultContext
}
Esempio n. 4
0
func (d *radosdesc) New() (factory.DrvInterface, error) {
	chunksize := uint64(defaultChunkSize)
	if setting.Chunksize != "" {
		if tmp, err := strconv.Atoi(setting.Chunksize); err != nil {
			return nil, fmt.Errorf("The chunksize parameter should be a number")
		} else {
			chunksize = uint64(tmp)
		}
	}

	var err error
	var conn *rados.Conn
	if setting.Username != "" {
		conn, err = rados.NewConnWithUser(setting.Username)
	} else {
		conn, err = rados.NewConn()
	}
	if err != nil {
		return nil, err
	}

	if err := conn.ReadDefaultConfigFile(); err != nil {
		return nil, err
	}

	if err := conn.Connect(); err != nil {
		return nil, err
	}

	ioctx, err := conn.OpenIOContext(setting.Poolname)
	if err != nil {
		return nil, err
	}

	return &radosdesc{
		Ioctx:     ioctx,
		Conn:      conn,
		Chunksize: chunksize,
	}, nil
}