mirror of
https://github.com/ceph/go-ceph
synced 2024-12-27 16:52:06 +00:00
cephfs admin: add support for running MON commands
Some of the queries we need to make are not mgr commands but (still?) mon commands. Extend the interface and helper funcs to support issuing mon commands. Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
736858ca7d
commit
3afac0b0b8
@ -14,6 +14,7 @@ import (
|
||||
// allow the cephfs administrative functions to interact with the Ceph cluster.
|
||||
type RadosCommander interface {
|
||||
MgrCommand(buf [][]byte) ([]byte, string, error)
|
||||
MonCommand(buf []byte) ([]byte, string, error)
|
||||
}
|
||||
|
||||
// FSAdmin is used to administrate CephFS within a ceph cluster.
|
||||
@ -76,6 +77,25 @@ func (fsa *FSAdmin) marshalMgrCommand(v interface{}) ([]byte, string, error) {
|
||||
return fsa.rawMgrCommand(b)
|
||||
}
|
||||
|
||||
// rawMonCommand takes a byte buffer and sends it to the MON as a command.
|
||||
// The buffer is expected to contain preformatted JSON.
|
||||
func (fsa *FSAdmin) rawMonCommand(buf []byte) ([]byte, string, error) {
|
||||
if err := fsa.validate(); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
return fsa.conn.MonCommand(buf)
|
||||
}
|
||||
|
||||
// marshalMonCommand takes an generic interface{} value, converts it to JSON and
|
||||
// sends the json to the MGR as a command.
|
||||
func (fsa *FSAdmin) marshalMonCommand(v interface{}) ([]byte, string, error) {
|
||||
b, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
return fsa.rawMonCommand(b)
|
||||
}
|
||||
|
||||
type listNamedResult struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ func tracer(c RadosCommander) RadosCommander {
|
||||
}
|
||||
|
||||
func (t *tracingCommander) MgrCommand(buf [][]byte) ([]byte, string, error) {
|
||||
fmt.Println("(MGR Command)")
|
||||
for i := range buf {
|
||||
fmt.Println("IN:", string(buf[i]))
|
||||
}
|
||||
@ -56,6 +57,20 @@ func (t *tracingCommander) MgrCommand(buf [][]byte) ([]byte, string, error) {
|
||||
return r, s, err
|
||||
}
|
||||
|
||||
func (t *tracingCommander) MonCommand(buf []byte) ([]byte, string, error) {
|
||||
fmt.Println("(MON Command)")
|
||||
fmt.Println("IN:", string(buf))
|
||||
r, s, err := t.conn.MonCommand(buf)
|
||||
fmt.Println("OUT(result):", string(r))
|
||||
if s != "" {
|
||||
fmt.Println("OUT(status):", s)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println("OUT(error):", err.Error())
|
||||
}
|
||||
return r, s, err
|
||||
}
|
||||
|
||||
func getFSAdmin(t *testing.T) *FSAdmin {
|
||||
if cachedFSAdmin != nil {
|
||||
return cachedFSAdmin
|
||||
|
Loading…
Reference in New Issue
Block a user