Browse Source

Merge pull request 'ceph: generate fsid if needed, and export FSID on env' (#10)

Reviewed-on: #10
pull/12/head
Alejandro Mery 1 year ago
parent
commit
e03e5e0d05
  1. 1
      .vscode/settings.json
  2. 6
      cmd/jpictl/env.go
  3. 8
      pkg/zones/ceph.go
  4. 20
      pkg/zones/env.go

1
.vscode/settings.json vendored

@ -2,6 +2,7 @@
"cSpell.words": [ "cSpell.words": [
"ceph", "ceph",
"darvaza", "darvaza",
"gofrs",
"jpictl", "jpictl",
"zerolog" "zerolog"
] ]

6
cmd/jpictl/env.go

@ -16,7 +16,11 @@ var envCmd = &cobra.Command{
return err 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 return err
}, },
} }

8
pkg/zones/ceph.go

@ -14,8 +14,12 @@ import (
// GetCephFSID returns our Ceph's FSID // GetCephFSID returns our Ceph's FSID
func (m *Zones) GetCephFSID() (uuid.UUID, error) { func (m *Zones) GetCephFSID() (uuid.UUID, error) {
if core.IsZero(m.CephFSID) { if core.IsZero(m.CephFSID) {
// TODO: generate one // generate one
return uuid.Nil, nil v, err := uuid.NewV4()
if err != nil {
return uuid.Nil, err
}
m.CephFSID = v
} }
return m.CephFSID, nil return m.CephFSID, nil
} }

20
pkg/zones/env.go

@ -11,15 +11,24 @@ import (
type Env struct { type Env struct {
ZoneIterator ZoneIterator
export bool cephFSID string
export bool
} }
// Env returns a shell environment factory // Env returns a shell environment factory
func (m *Zones) Env(export bool) *Env { func (m *Zones) Env(export bool) (*Env, error) {
return &Env{ fsid, err := m.GetCephFSID()
if err != nil {
return nil, err
}
env := &Env{
ZoneIterator: m, ZoneIterator: m,
cephFSID: fsid.String(),
export: export, export: export,
} }
return env, nil
} }
// Zones returns the list of Zone IDs // 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) { func (m *Env) WriteTo(w io.Writer) (int64, error) {
var buf bytes.Buffer var buf bytes.Buffer
if m.cephFSID != "" {
m.writeEnvVar(&buf, m.cephFSID, "FSID")
}
m.writeEnvVarInts(&buf, m.Zones(), "ZONES") m.writeEnvVarInts(&buf, m.Zones(), "ZONES")
m.ForEachZone(func(z *Zone) bool { m.ForEachZone(func(z *Zone) bool {
m.writeEnvZone(&buf, z) m.writeEnvZone(&buf, z)
return false return false

Loading…
Cancel
Save