Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-28 15:44:45 +01:00
parent 6f5ca3f235
commit b8aba9e05e
6 changed files with 121 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
// Package ceph deals with ceph config
package ceph
+70
View File
@@ -0,0 +1,70 @@
package ceph
import (
"bytes"
"io"
"net/netip"
"github.com/gofrs/uuid/v5"
"gopkg.in/gcfg.v1"
)
// Config represents a ceph.conf file
type Config struct {
Global GlobalConfig
}
// WriteTo writes a Wireguard [Config] onto the provided [io.Writer]
func (*Config) WriteTo(w io.Writer) (int64, error) {
var buf bytes.Buffer
return buf.WriteTo(w)
}
// GlobalConfig represents the [global] section of a ceph.conf file
type GlobalConfig struct {
FSID uuid.UUID
Monitors []string
MonitorsAddr []netip.Addr
}
type intermediateConfig struct {
Global intermediateGlobalConfig
}
func (p intermediateConfig) Export() (*Config, error) {
var out Config
var err error
// [global]
out.Global, err = p.Global.Export()
if err != nil {
return nil, err
}
return &out, nil
}
type intermediateGlobalConfig struct {
FSID uuid.UUID
MonInitialMembers string
MonHost string
ClusterNetwork string
}
func (intermediateGlobalConfig) Export() (GlobalConfig, error) {
var out GlobalConfig
var err error
return out, err
}
func NewConfigFromReader(r io.Reader) (*Config, error) {
var temp intermediateConfig
if err := gcfg.ReadInto(&temp, r); err != nil {
return nil, err
}
return temp.Export()
}