sdf
This commit is contained in:
parent
45d9a8ea83
commit
0309c74925
52
ceph/ceph.go
52
ceph/ceph.go
|
|
@ -1,29 +1,59 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/ceph/go-ceph/rados"
|
"github.com/ceph/go-ceph/rados"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getPoolSize(cephConn *cephConnection, params string) Poolinfo {
|
||||||
|
monRawAnswer := makeMonQuery(cephConn, map[string]string{"prefix": "osd pool get", "pool": params,
|
||||||
|
"format": "json", "var": "size"})
|
||||||
|
monAnswer := Poolinfo{}
|
||||||
|
if err := json.Unmarshal([]byte(monRawAnswer), &monAnswer); err != nil {
|
||||||
|
log.Fatalf("Can't parse monitor answer. Error: %v", err)
|
||||||
|
}
|
||||||
|
return monAnswer
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func makeMonQuery(cephConn *cephConnection, query map[string]string) []byte {
|
||||||
|
monJson, err := json.Marshal(query)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Can't marshal json mon query. Error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
monRawAnswer, _, err := cephConn.conn.MonCommand(monJson)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed exec monCommand. Error: %v", err)
|
||||||
|
}
|
||||||
|
return monRawAnswer
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var connect cephConnection
|
||||||
|
var err error
|
||||||
|
|
||||||
fmt.Println("Creating connection object")
|
fmt.Println("Creating connection object")
|
||||||
conn,err := rados.NewConn()
|
connect.conn,err = rados.NewConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Cannot create Connection object\n")
|
log.Fatal("Cannot create Connection object\n")
|
||||||
}
|
}
|
||||||
conn.ReadConfigFile("/etc/ceph/ceph.conf")
|
connect.conn.ReadConfigFile("/etc/ceph/ceph.conf")
|
||||||
conn.Connect()
|
connect.conn.Connect()
|
||||||
defer conn.Shutdown()
|
defer connect.conn.Shutdown()
|
||||||
|
|
||||||
poolnames,err := conn.ListPools()
|
// poolnames,err := connect.conn.ListPools()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
log.Fatal("Cannot list pools")
|
// log.Fatal("Cannot list pools")
|
||||||
}
|
// }
|
||||||
|
|
||||||
for i,j := range poolnames {
|
// for i,j := range poolnames {
|
||||||
fmt.Printf("%d %s\n",i,j)
|
// fmt.Printf("%d %s\n",i,j)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,23 @@
|
||||||
// package main
|
package main
|
||||||
|
|
||||||
|
import "github.com/ceph/go-ceph/rados"
|
||||||
|
|
||||||
|
|
||||||
|
type cephConnection struct {
|
||||||
|
conn *rados.Conn
|
||||||
|
}
|
||||||
|
|
||||||
|
type Poolinfo struct {
|
||||||
|
Pool string `json:"pool,omitempty"`
|
||||||
|
PoolId uint64 `json:"pool_id,omitempty"`
|
||||||
|
Size uint64 `json:"size,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Device struct {
|
||||||
|
Class string `json:"class"`
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Info OsdMetadata
|
||||||
|
}
|
||||||
|
|
||||||
// const config = "/etc/ceph/ceph.conf"
|
|
||||||
|
|
||||||
// type params struct {
|
|
||||||
// cluster string
|
|
||||||
// user string
|
|
||||||
// config string
|
|
||||||
// }
|
|
||||||
|
|
|
||||||
3
headFirst/json/go.mod
Normal file
3
headFirst/json/go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
module main
|
||||||
|
|
||||||
|
go 1.24.6
|
||||||
25
headFirst/json/main.go
Normal file
25
headFirst/json/main.go
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
func main() {
|
||||||
|
input := `{
|
||||||
|
"name": "John Doe",
|
||||||
|
"age": 15,
|
||||||
|
"hobbies": ["climbing", "cycling", "running"]
|
||||||
|
}`
|
||||||
|
|
||||||
|
var target map[string]any
|
||||||
|
|
||||||
|
err := json.Unmarshal([]byte(input), &target)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Unable to marshal JSON due to %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range target {
|
||||||
|
fmt.Printf("k: %s, v: %v\n", k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user