64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/ceph/go-ceph/rados"
|
|
"github.com/ceph/go-ceph/rbd"
|
|
)
|
|
|
|
func PoolFactory(cephConn CephConnection, poolName string) (Pool, error) {
|
|
var rbdlist []iRBD = []iRBD{}
|
|
|
|
ioctx, err := cephConn.conn.OpenIOContext(poolName)
|
|
if err != nil {
|
|
return Pool{}, fmt.Errorf("Couldn't set context for pool %s %w", poolName, err)
|
|
}
|
|
|
|
defer ioctx.Destroy()
|
|
|
|
imageList, err := rbd.GetImageNames(ioctx)
|
|
if err != nil {
|
|
return Pool{}, fmt.Errorf("Couldn't get list of rbds %w", err)
|
|
}
|
|
for _, rbdname := range imageList {
|
|
stat, err := RBDFacroty(ioctx, rbdname)
|
|
if err != nil {
|
|
logger.Errorf("Coundn't get stat from disk %s %w", rbdname, err)
|
|
panic(err)
|
|
}
|
|
rbdlist = append(rbdlist, stat)
|
|
}
|
|
return Pool{
|
|
Name: poolName,
|
|
hasRBD: len(imageList) != 0,
|
|
RBDlist: rbdlist,
|
|
}, nil
|
|
}
|
|
|
|
func RBDFacroty(ioctx *rados.IOContext, rbdname string) (RBD, error) {
|
|
defer func() {
|
|
if v := recover(); v != nil {
|
|
fmt.Println("Shit happened")
|
|
}
|
|
}()
|
|
|
|
image := rbd.GetImage(ioctx,rbdname)
|
|
err := image.Open()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
defer image.Close()
|
|
|
|
|
|
info,err := image.Stat()
|
|
if err != nil {
|
|
return RBD{},fmt.Errorf("Couldn't get stats for image %s %w",rbdname,err)
|
|
}
|
|
|
|
return RBD{
|
|
Name: rbdname,
|
|
ImageInfo: *info,
|
|
},nil
|
|
}
|