|
|
|
@ -4,12 +4,14 @@ import (
|
|
|
|
|
"bytes" |
|
|
|
|
"fmt" |
|
|
|
|
"io" |
|
|
|
|
"sort" |
|
|
|
|
"strings" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// Env is a shell environment factory for this cluster
|
|
|
|
|
type Env struct { |
|
|
|
|
ZoneIterator |
|
|
|
|
RegionIterator |
|
|
|
|
|
|
|
|
|
cephFSID string |
|
|
|
|
export bool |
|
|
|
@ -23,9 +25,10 @@ func (m *Cluster) Env(export bool) (*Env, error) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
env := &Env{ |
|
|
|
|
ZoneIterator: m, |
|
|
|
|
cephFSID: fsid.String(), |
|
|
|
|
export: export, |
|
|
|
|
ZoneIterator: m, |
|
|
|
|
RegionIterator: m, |
|
|
|
|
cephFSID: fsid.String(), |
|
|
|
|
export: export, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return env, nil |
|
|
|
@ -43,6 +46,22 @@ func (m *Env) Zones() []int {
|
|
|
|
|
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
|
|
|
|
|
func (m *Env) WriteTo(w io.Writer) (int64, error) { |
|
|
|
|
var buf bytes.Buffer |
|
|
|
@ -51,6 +70,7 @@ func (m *Env) WriteTo(w io.Writer) (int64, error) {
|
|
|
|
|
m.writeEnvVar(&buf, m.cephFSID, "FSID") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m.writeEnvVarStrings(&buf, m.Regions(), "REGIONS") |
|
|
|
|
m.writeEnvVarInts(&buf, m.Zones(), "ZONES") |
|
|
|
|
|
|
|
|
|
m.ForEachZone(func(z *Zone) bool { |
|
|
|
|