env: add REGIONS list to output
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
+23
-3
@@ -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
|
||||||
@@ -23,9 +25,10 @@ func (m *Cluster) Env(export bool) (*Env, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
env := &Env{
|
env := &Env{
|
||||||
ZoneIterator: m,
|
ZoneIterator: m,
|
||||||
cephFSID: fsid.String(),
|
RegionIterator: m,
|
||||||
export: export,
|
cephFSID: fsid.String(),
|
||||||
|
export: export,
|
||||||
}
|
}
|
||||||
|
|
||||||
return env, nil
|
return env, nil
|
||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user