|
|
|
@ -1,8 +1,11 @@
|
|
|
|
|
package ceph |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"bytes" |
|
|
|
|
"fmt" |
|
|
|
|
"io" |
|
|
|
|
"net/netip" |
|
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
"github.com/gofrs/uuid/v5" |
|
|
|
|
|
|
|
|
@ -22,6 +25,32 @@ type GlobalConfig struct {
|
|
|
|
|
ClusterNetwork netip.Prefix `ini:"cluster_network"` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// WriteTo writes a Wireguard [Config] onto the provided [io.Writer]
|
|
|
|
|
func (cfg *Config) WriteTo(w io.Writer) (int64, error) { |
|
|
|
|
var buf bytes.Buffer |
|
|
|
|
|
|
|
|
|
writeGlobalToBuffer(&buf, &cfg.Global) |
|
|
|
|
return buf.WriteTo(w) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func writeGlobalToBuffer(w *bytes.Buffer, c *GlobalConfig) { |
|
|
|
|
_, _ = w.WriteString("[global]\n") |
|
|
|
|
_, _ = fmt.Fprintf(w, "%s = %s\n", "fsid", c.FSID.String()) |
|
|
|
|
_, _ = fmt.Fprintf(w, "%s = %s\n", "mon_initial_members", strings.Join(c.Monitors, ", ")) |
|
|
|
|
_, _ = fmt.Fprintf(w, "%s = %s\n", "mon_host", joinAddrs(c.MonitorsAddr, ", ")) |
|
|
|
|
_, _ = fmt.Fprintf(w, "%s = %s\n", "cluster_network", c.ClusterNetwork.String()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func joinAddrs(addrs []netip.Addr, sep string) string { |
|
|
|
|
s := make([]string, len(addrs)) |
|
|
|
|
|
|
|
|
|
for i, addr := range addrs { |
|
|
|
|
s[i] = addr.String() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return strings.Join(s, sep) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewConfigFromReader parses the ceph.conf file
|
|
|
|
|
func NewConfigFromReader(r io.Reader) (*Config, error) { |
|
|
|
|
doc, err := basic.Decode(r) |
|
|
|
|