|
|
@ -6,6 +6,8 @@ import ( |
|
|
|
"io" |
|
|
|
"io" |
|
|
|
"sort" |
|
|
|
"sort" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"git.jpi.io/amery/jpictl/pkg/rings" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Env is a shell environment factory for this cluster
|
|
|
|
// Env is a shell environment factory for this cluster
|
|
|
@ -35,8 +37,8 @@ func (m *Cluster) Env(export bool) (*Env, error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Zones returns the list of Zone IDs
|
|
|
|
// Zones returns the list of Zone IDs
|
|
|
|
func (m *Env) Zones() []int { |
|
|
|
func (m *Env) Zones() []rings.ZoneID { |
|
|
|
var zones []int |
|
|
|
var zones []rings.ZoneID |
|
|
|
|
|
|
|
|
|
|
|
m.ForEachZone(func(z *Zone) bool { |
|
|
|
m.ForEachZone(func(z *Zone) bool { |
|
|
|
zones = append(zones, z.ID) |
|
|
|
zones = append(zones, z.ID) |
|
|
@ -51,7 +53,7 @@ func (m *Env) Regions() []string { |
|
|
|
var regions []string |
|
|
|
var regions []string |
|
|
|
|
|
|
|
|
|
|
|
m.ForEachRegion(func(r *Region) bool { |
|
|
|
m.ForEachRegion(func(r *Region) bool { |
|
|
|
if r.Cluster != nil { |
|
|
|
if r.IsPrimary() { |
|
|
|
regions = append(regions, r.Name) |
|
|
|
regions = append(regions, r.Name) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -70,8 +72,8 @@ 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.writeEnvVar(&buf, genEnvStrings(m.Regions()), "REGIONS") |
|
|
|
m.writeEnvVarInts(&buf, m.Zones(), "ZONES") |
|
|
|
m.writeEnvVar(&buf, genEnvInts(m.Zones()), "ZONES") |
|
|
|
|
|
|
|
|
|
|
|
m.ForEachZone(func(z *Zone) bool { |
|
|
|
m.ForEachZone(func(z *Zone) bool { |
|
|
|
m.writeEnvZone(&buf, z) |
|
|
|
m.writeEnvZone(&buf, z) |
|
|
@ -92,7 +94,7 @@ func (m *Env) writeEnvZone(w io.Writer, z *Zone) { |
|
|
|
|
|
|
|
|
|
|
|
// ZONE{zoneID}_GW
|
|
|
|
// ZONE{zoneID}_GW
|
|
|
|
gateways, _ := z.GatewayIDs() |
|
|
|
gateways, _ := z.GatewayIDs() |
|
|
|
m.writeEnvVarInts(w, gateways, "ZONE%v_%s", zoneID, "GW") |
|
|
|
m.writeEnvVar(w, genEnvInts(gateways), "ZONE%v_%s", zoneID, "GW") |
|
|
|
|
|
|
|
|
|
|
|
// ZONE{zoneID}_REGION
|
|
|
|
// ZONE{zoneID}_REGION
|
|
|
|
m.writeEnvVar(w, genEnvZoneRegion(z), "ZONE%v_%s", zoneID, "REGION") |
|
|
|
m.writeEnvVar(w, genEnvZoneRegion(z), "ZONE%v_%s", zoneID, "REGION") |
|
|
@ -107,32 +109,6 @@ func (m *Env) writeEnvZone(w io.Writer, z *Zone) { |
|
|
|
m.writeEnvVar(w, genEnvZoneCephMonIDs(monitors), "MON%v_%s", zoneID, "ID") |
|
|
|
m.writeEnvVar(w, genEnvZoneCephMonIDs(monitors), "MON%v_%s", zoneID, "ID") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (m *Env) writeEnvVarInts(w io.Writer, value []int, name string, args ...any) { |
|
|
|
|
|
|
|
var buf bytes.Buffer |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range value { |
|
|
|
|
|
|
|
if buf.Len() > 0 { |
|
|
|
|
|
|
|
_, _ = fmt.Fprint(&buf, " ") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
_, _ = fmt.Fprintf(&buf, "%v", v) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m.writeEnvVar(w, buf.String(), name, args...) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (m *Env) writeEnvVarStrings(w io.Writer, value []string, name string, args ...any) { |
|
|
|
|
|
|
|
var buf bytes.Buffer |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range value { |
|
|
|
|
|
|
|
if buf.Len() > 0 { |
|
|
|
|
|
|
|
_, _ = fmt.Fprint(&buf, " ") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
_, _ = fmt.Fprintf(&buf, "%s", v) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m.writeEnvVar(w, buf.String(), name, args...) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (m *Env) writeEnvVar(w io.Writer, value string, name string, args ...any) { |
|
|
|
func (m *Env) writeEnvVar(w io.Writer, value string, name string, args ...any) { |
|
|
|
var prefix string |
|
|
|
var prefix string |
|
|
|
|
|
|
|
|
|
|
@ -155,6 +131,23 @@ func (m *Env) writeEnvVar(w io.Writer, value string, name string, args ...any) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func genEnvInts[T ~int | ~uint](values []T) string { |
|
|
|
|
|
|
|
var buf bytes.Buffer |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range values { |
|
|
|
|
|
|
|
if buf.Len() > 0 { |
|
|
|
|
|
|
|
_, _ = buf.WriteRune(' ') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
_, _ = buf.WriteString(fmt.Sprintf("%v", v)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return buf.String() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func genEnvStrings(values []string) string { |
|
|
|
|
|
|
|
return strings.Join(values, " ") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func genEnvZoneNodes(z *Zone) string { |
|
|
|
func genEnvZoneNodes(z *Zone) string { |
|
|
|
if n := z.Len(); n > 0 { |
|
|
|
if n := z.Len(); n > 0 { |
|
|
|
s := make([]string, 0, n) |
|
|
|
s := make([]string, 0, n) |
|
|
@ -164,24 +157,16 @@ func genEnvZoneNodes(z *Zone) string { |
|
|
|
return false |
|
|
|
return false |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return strings.Join(s, " ") |
|
|
|
return genEnvStrings(s) |
|
|
|
} |
|
|
|
} |
|
|
|
return "" |
|
|
|
return "" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func genEnvZoneRegion(z *Zone) string { |
|
|
|
func genEnvZoneRegion(z *Zone) string { |
|
|
|
var region string |
|
|
|
if z != nil && z.region != nil { |
|
|
|
|
|
|
|
return z.region.Name |
|
|
|
z.ForEachRegion(func(r *Region) bool { |
|
|
|
|
|
|
|
if r.Cluster != nil { |
|
|
|
|
|
|
|
region = r.Name |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return "" |
|
|
|
return false |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return region |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func genEnvZoneCephMonNames(m Machines) string { |
|
|
|
func genEnvZoneCephMonNames(m Machines) string { |
|
|
|