b49f5e61a2
Signed-off-by: Alejandro Mery <amery@jpi.io>
77 lines
1.3 KiB
Go
77 lines
1.3 KiB
Go
package ceph
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"net/netip"
|
|
|
|
"github.com/gofrs/uuid/v5"
|
|
|
|
"asciigoat.org/ini/basic"
|
|
)
|
|
|
|
// 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
|
|
}
|
|
|
|
// NewConfigFromReader parses the ceph.conf file
|
|
func NewConfigFromReader(r io.Reader) (*Config, error) {
|
|
doc, err := basic.Decode(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
cfg, err := newConfigFromDocument(doc)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|