pkg/ceph: [WIP]

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-28 15:44:45 +01:00
parent d5d25f01b0
commit 01ce54b0d0
6 changed files with 122 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
// Package ceph deals with ceph config
package ceph
+71
View File
@@ -0,0 +1,71 @@
package ceph
import (
"bytes"
"io"
"net/netip"
"github.com/gofrs/uuid/v5"
"asciigoat.org/ini"
)
// 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 := ini.ReadInto(&temp, r); err != nil {
return nil, err
}
return temp.Export()
}