From 0fb8c1d44b8b8322280b4a2e08c32e1fb4874033 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Tue, 5 Sep 2023 12:04:22 +0000 Subject: [PATCH] zones: introduce Zones.CephFSID and Zones.GetCephFSID() the accessor doesn't generate one if needed yet Signed-off-by: Alejandro Mery --- go.mod | 1 + go.sum | 2 ++ pkg/zones/ceph.go | 15 +++++++++++++++ pkg/zones/zones.go | 7 +++++++ 4 files changed, 25 insertions(+) create mode 100644 pkg/zones/ceph.go diff --git a/go.mod b/go.mod index 898b328..6e9c068 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( darvaza.org/sidecar v0.0.2 darvaza.org/slog v0.5.3 github.com/burntSushi/toml v0.3.1 + github.com/gofrs/uuid/v5 v5.0.0 github.com/hack-pad/hackpadfs v0.2.1 github.com/mgechev/revive v1.3.3 github.com/spf13/cobra v1.7.0 diff --git a/go.sum b/go.sum index d04ecf7..8d58d18 100644 --- a/go.sum +++ b/go.sum @@ -26,6 +26,8 @@ github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBD github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gofrs/uuid/v5 v5.0.0 h1:p544++a97kEL+svbcFbCQVM9KFu0Yo25UoISXGNNH9M= +github.com/gofrs/uuid/v5 v5.0.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8= github.com/hack-pad/hackpadfs v0.2.1 h1:FelFhIhv26gyjujoA/yeFO+6YGlqzmc9la/6iKMIxMw= github.com/hack-pad/hackpadfs v0.2.1/go.mod h1:khQBuCEwGXWakkmq8ZiFUvUZz84ZkJ2KNwKvChs4OrU= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= diff --git a/pkg/zones/ceph.go b/pkg/zones/ceph.go new file mode 100644 index 0000000..94ef7d9 --- /dev/null +++ b/pkg/zones/ceph.go @@ -0,0 +1,15 @@ +package zones + +import ( + "darvaza.org/core" + "github.com/gofrs/uuid/v5" +) + +// GetCephFSID returns our Ceph's FSID +func (m *Zones) GetCephFSID() (uuid.UUID, error) { + if core.IsZero(m.CephFSID) { + // TODO: generate one + return uuid.Nil, nil + } + return m.CephFSID, nil +} diff --git a/pkg/zones/zones.go b/pkg/zones/zones.go index f25f264..fad4c30 100644 --- a/pkg/zones/zones.go +++ b/pkg/zones/zones.go @@ -6,6 +6,7 @@ import ( "sort" "darvaza.org/resolver" + "github.com/gofrs/uuid/v5" ) var ( @@ -135,15 +136,21 @@ func (z *Zone) GatewayIDs() ([]int, int) { return out, len(out) } +// revive:disable:line-length-limit + // Zones represents all zones in a cluster type Zones struct { dir fs.FS resolver resolver.Resolver domain string + CephFSID uuid.UUID `toml:"ceph_fsid,omitempty" json:"ceph_fsid,omitempty" yaml:"ceph_fsid,omitempty"` + Zones []*Zone `toml:"zones"` } +// revive:enable:line-length-limit + // ForEachMachine calls a function for each Machine in the cluster // until instructed to terminate the loop func (m *Zones) ForEachMachine(fn func(*Machine) bool) {