From 3911a51ccfa5fa48c2819034e8f80724a7a4c2d8 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Tue, 5 Sep 2023 19:43:27 +0000 Subject: [PATCH 1/3] vscode: add gofrs to the dictionary as we use "github.com/gofrs/uuid/v5" Signed-off-by: Alejandro Mery --- .vscode/settings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7411ff7..2f6ce64 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,7 @@ "cSpell.words": [ "ceph", "darvaza", + "gofrs", "jpictl", "zerolog" ] From c291b218a4c76a1cd907f2db506bbfe5191b588f Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Tue, 5 Sep 2023 19:44:09 +0000 Subject: [PATCH 2/3] zones: improve GetCephFSID() to generate a new UUID if none was found Signed-off-by: Alejandro Mery --- pkg/zones/ceph.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/zones/ceph.go b/pkg/zones/ceph.go index 7b828e3..676339b 100644 --- a/pkg/zones/ceph.go +++ b/pkg/zones/ceph.go @@ -14,8 +14,12 @@ import ( // 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 + // generate one + v, err := uuid.NewV4() + if err != nil { + return uuid.Nil, err + } + m.CephFSID = v } return m.CephFSID, nil } From a655603343a205ee40a08f347adf02c1219cf98d Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Tue, 5 Sep 2023 19:51:37 +0000 Subject: [PATCH 3/3] env: export FSID Signed-off-by: Alejandro Mery --- cmd/jpictl/env.go | 6 +++++- pkg/zones/env.go | 20 +++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cmd/jpictl/env.go b/cmd/jpictl/env.go index a968725..4b21773 100644 --- a/cmd/jpictl/env.go +++ b/cmd/jpictl/env.go @@ -16,7 +16,11 @@ var envCmd = &cobra.Command{ return err } - _, err = m.Env(*envExport).WriteTo(os.Stdout) + env, err := m.Env(*envExport) + if err != nil { + return err + } + _, err = env.WriteTo(os.Stdout) return err }, } diff --git a/pkg/zones/env.go b/pkg/zones/env.go index 36649f7..8780da9 100644 --- a/pkg/zones/env.go +++ b/pkg/zones/env.go @@ -11,15 +11,24 @@ import ( type Env struct { ZoneIterator - export bool + cephFSID string + export bool } // Env returns a shell environment factory -func (m *Zones) Env(export bool) *Env { - return &Env{ +func (m *Zones) Env(export bool) (*Env, error) { + fsid, err := m.GetCephFSID() + if err != nil { + return nil, err + } + + env := &Env{ ZoneIterator: m, + cephFSID: fsid.String(), export: export, } + + return env, nil } // Zones returns the list of Zone IDs @@ -38,7 +47,12 @@ func (m *Env) Zones() []int { func (m *Env) WriteTo(w io.Writer) (int64, error) { var buf bytes.Buffer + if m.cephFSID != "" { + m.writeEnvVar(&buf, m.cephFSID, "FSID") + } + m.writeEnvVarInts(&buf, m.Zones(), "ZONES") + m.ForEachZone(func(z *Zone) bool { m.writeEnvZone(&buf, z) return false