|
|
@ -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 { |
|
|
|