Files
my-rook-config/pkg/cephclient/pool.go
T

58 lines
1.3 KiB
Go

package cephclient
import (
"encoding/json"
"fmt"
"log"
)
type CephStoragePool struct {
Number int `json:"poolnum"`
Name string `json:"poolname"`
}
func ListPools(conn Connection) ([]CephStoragePool, error) {
cmd := "osd lspools"
command, err := json.Marshal(map[string]interface{}{
"prefix": cmd,
"format": "json",
})
if err != nil {
return nil, fmt.Errorf("command %s marshall failed: %+v", cmd, err)
}
buf, _, err := conn.MonCommand(command)
if err != nil {
return nil, fmt.Errorf("mon_command %s failed: %+v", cmd, err)
}
var pools []CephStoragePool
err = json.Unmarshal(buf, &pools)
if err != nil {
return nil, fmt.Errorf("unmarhsall failed: %+v. raw buffer response: %s", err, string(buf[:]))
}
return pools, nil
}
func CreatePool(conn Connection, name string) (string, error) {
cmd := "osd pool create"
command, err := json.Marshal(map[string]interface{}{
"prefix": cmd,
"format": "json",
"pool": name,
})
if err != nil {
return "", fmt.Errorf("command %s marshall failed: %+v", cmd, err)
}
buf, info, err := conn.MonCommand(command)
if err != nil {
return "", fmt.Errorf("mon_command %s failed: %+v", cmd, err)
}
log.Printf("command %s succeeded, info: %s, buf: %s", cmd, info, string(buf[:]))
return info, nil
}