env: export FSID

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-09-05 19:51:37 +00:00
parent 84d380ae73
commit c2a21707c9
2 changed files with 22 additions and 4 deletions
+5 -1
View File
@@ -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
},
}
+17 -3
View File
@@ -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