Files
my-rook-config/pkg/castled/mon.go
T

87 lines
2.2 KiB
Go

package castled
import (
"encoding/json"
"fmt"
"path"
"path/filepath"
"github.com/quantum/castle/pkg/cephd"
)
const (
PrivateIPv4Value = "privateIPv4"
monitorKeyringTemplate = `
[mon.]
key = %s
caps mon = "allow *"
[client.admin]
key = %s
auid = 0
caps mds = "allow"
caps mon = "allow *"
caps osd = "allow *"
`
)
// get the key value store path for a given monitor's endpoint
func getMonitorEndpointKey(name string) string {
return fmt.Sprintf(path.Join(cephKey, "mons/%s/endpoint"), name)
}
// get the path of a given monitor's run dir
func getMonRunDirPath(monName string) string {
return fmt.Sprintf("/tmp/%s", monName)
}
// get the path of a given monitor's config file
func getMonConfFilePath(monName string) string {
return filepath.Join(getMonRunDirPath(monName), "config")
}
// get the path of a given monitor's keyring
func getMonKeyringPath(monName string) string {
return filepath.Join(getMonRunDirPath(monName), "keyring")
}
// get the path of a given monitor's data dir
func getMonDataDirPath(monName string) string {
return filepath.Join(getMonRunDirPath(monName), fmt.Sprintf("mon.%s", monName))
}
// represents the response from a mon_status mon_command (subset of all available fields, only
// marshal ones we care about)
type MonStatusResponse struct {
Quorum []int `json:"quorum"`
MonMap struct {
Mons []MonMapEntry `json:"mons"`
} `json:"monmap"`
}
// represents an entry in the monitor map
type MonMapEntry struct {
Name string `json:"name"`
Rank int `json:"rank"`
Address string `json:"addr"`
}
// calls mon_status mon_command
func getMonStatus(adminConn *cephd.Conn) (MonStatusResponse, error) {
monCommand := "mon_status"
command, err := json.Marshal(map[string]string{"prefix": monCommand, "format": "json"})
if err != nil {
return MonStatusResponse{}, fmt.Errorf("command %s marshall failed: %+v", monCommand, err)
}
buf, _, err := adminConn.MonCommand(command)
if err != nil {
return MonStatusResponse{}, fmt.Errorf("mon_command failed: %+v", err)
}
var resp MonStatusResponse
err = json.Unmarshal(buf, &resp)
if err != nil {
return MonStatusResponse{}, fmt.Errorf("unmarshall failed: %+v. raw buffer response: %s", err, string(buf[:]))
}
return resp, nil
}