From 7035facf7bac894415237334d5cda38c7b5a00ac Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Mon, 4 Sep 2023 19:45:04 +0000 Subject: [PATCH] ceph: zones.Zones.WriteCephConfig() and ceph.Config.WriteTo() [WIP] Signed-off-by: Alejandro Mery --- pkg/ceph/config.go | 8 ++++++++ pkg/zones/ceph.go | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkg/ceph/config.go b/pkg/ceph/config.go index 9a96ae1..7cf73e8 100644 --- a/pkg/ceph/config.go +++ b/pkg/ceph/config.go @@ -1,6 +1,7 @@ package ceph import ( + "bytes" "io" "net/netip" @@ -14,6 +15,13 @@ type Config struct { Global GlobalConfig `ini:"global"` } +// 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 `ini:"fsid"` diff --git a/pkg/zones/ceph.go b/pkg/zones/ceph.go index cfd3b0f..8a2a655 100644 --- a/pkg/zones/ceph.go +++ b/pkg/zones/ceph.go @@ -18,6 +18,18 @@ func (m *Zones) GetCephConfig() (*ceph.Config, error) { return ceph.NewConfigFromReader(r) } +// WriteCephConfig writes the ceph.conf file +func (m *Zones) WriteCephConfig(cfg *ceph.Config) error { + f, err := m.CreateTruncFile("ceph.conf") + if err != nil { + return err + } + defer f.Close() + + _, err = cfg.WriteTo(f) + return err +} + // GetCephMonitors returns the set of Ceph monitors on // the zone func (z *Zone) GetCephMonitors() Machines {