Browse Source

env: add REGIONS list to output

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/45/head
Alejandro Mery 9 months ago
parent
commit
7986e0fd3b
  1. 20
      pkg/cluster/env.go

20
pkg/cluster/env.go

@ -4,12 +4,14 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"sort"
"strings" "strings"
) )
// Env is a shell environment factory for this cluster // Env is a shell environment factory for this cluster
type Env struct { type Env struct {
ZoneIterator ZoneIterator
RegionIterator
cephFSID string cephFSID string
export bool export bool
@ -24,6 +26,7 @@ func (m *Cluster) Env(export bool) (*Env, error) {
env := &Env{ env := &Env{
ZoneIterator: m, ZoneIterator: m,
RegionIterator: m,
cephFSID: fsid.String(), cephFSID: fsid.String(),
export: export, export: export,
} }
@ -43,6 +46,22 @@ func (m *Env) Zones() []int {
return zones return zones
} }
// Regions returns the list of primary regions
func (m *Env) Regions() []string {
var regions []string
m.ForEachRegion(func(r *Region) bool {
if r.Cluster != nil {
regions = append(regions, r.Name)
}
return false
})
sort.Strings(regions)
return regions
}
// WriteTo generates environment variables for shell scripts // WriteTo generates environment variables for shell scripts
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
@ -51,6 +70,7 @@ func (m *Env) WriteTo(w io.Writer) (int64, error) {
m.writeEnvVar(&buf, m.cephFSID, "FSID") m.writeEnvVar(&buf, m.cephFSID, "FSID")
} }
m.writeEnvVarStrings(&buf, m.Regions(), "REGIONS")
m.writeEnvVarInts(&buf, m.Zones(), "ZONES") m.writeEnvVarInts(&buf, m.Zones(), "ZONES")
m.ForEachZone(func(z *Zone) bool { m.ForEachZone(func(z *Zone) bool {

Loading…
Cancel
Save