Compare commits

..

10 Commits

Author SHA1 Message Date
amery 6a6cdfcfe8 Merge branch 'pr-amery-region-sort' into next-amery 2023-10-30 00:03:47 +00:00
amery 8866650a47 Merge branch 'pr-amery-files' into next-amery
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-10-29 23:32:50 +00:00
amery b1544c251c Merge branch 'pr-amery-dns-write' into next-amery 2023-10-29 02:32:50 +00:00
amery 7ea3906d63 Merge branch 'pr-amery-wireguard-ini' into next-amery 2023-10-29 01:13:19 +00:00
amery 6e0bf95fdf Merge branch 'pr-amery-wg-auto-init' into next-amery 2023-10-29 01:13:13 +00:00
amery 472b014a74 Merge branch 'pr-amery-jpictl-flags' into next-amery 2023-10-29 01:13:07 +00:00
amery 30b15da87d Merge branch 'pr-amery-mkdirall' into next-amery 2023-10-29 01:13:00 +00:00
amery da38250465 jpictl: create machine directories on jpictl write
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-10-29 01:12:21 +00:00
amery bdf0192ac5 cluster: add MkdirAll() support
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-10-29 01:12:21 +00:00
amery 194f03c86a cluster: refactor Machine.ReadFile() and Machine.OpenFile()
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-10-29 01:12:21 +00:00
6 changed files with 12 additions and 52 deletions
+1 -1
View File
@@ -52,7 +52,7 @@ func populateDNSManager(mgr *dns.Manager, m *cluster.Cluster) error {
m.ForEachZone(func(z *cluster.Zone) bool {
z.ForEachMachine(func(p *cluster.Machine) bool {
err = mgr.AddHost(ctx, z.Name, p.ID, p.Active(), p.PublicAddresses...)
err = mgr.AddHost(ctx, z.Name, p.ID, true, p.PublicAddresses...)
return err != nil
})
+9 -9
View File
@@ -67,6 +67,15 @@ func (m *Cluster) ReadFile(name string, args ...any) ([]byte, error) {
return fs.ReadFile(m.dir, name)
}
// MkdirAll creates directories relative to the cluster's config directory
func (m *Cluster) MkdirAll(name string, args ...any) error {
if len(args) > 0 {
name = fmt.Sprintf(name, args...)
}
return fs.MkdirAll(m.dir, name, 0755)
}
// ReadLines reads a file from the cluster's config directory,
// split by lines, trimmed, and accepting `#` to comment lines out.
func (m *Cluster) ReadLines(name string, args ...any) ([]string, error) {
@@ -104,12 +113,3 @@ func (m *Cluster) WriteStringFile(value string, name string, args ...any) error
_, err = buf.WriteTo(f)
return err
}
// MkdirAll creates directories relative to the cluster's config directory
func (m *Cluster) MkdirAll(name string, args ...any) error {
if len(args) > 0 {
name = fmt.Sprintf(name, args...)
}
return fs.MkdirAll(m.dir, name, 0755)
}
-6
View File
@@ -15,7 +15,6 @@ type Machine struct {
ID int
Name string `json:"-" yaml:"-"`
Inactive bool `json:"inactive,omitempty" yaml:"inactive,omitempty"`
CephMonitor bool `json:"ceph_monitor,omitempty" yaml:"ceph_monitor,omitempty"`
PublicAddresses []netip.Addr `json:"public,omitempty" yaml:"public,omitempty"`
Rings []*RingInfo `json:"rings,omitempty" yaml:"rings,omitempty"`
@@ -44,11 +43,6 @@ func (m *Machine) FullName() string {
return strings.Join(name, ".")
}
// Active indicates the machine is to be included in regions' DNS entries
func (m *Machine) Active() bool {
return !m.Inactive
}
// IsGateway tells if the Machine is a ring0 gateway
func (m *Machine) IsGateway() bool {
_, ok := m.getRingInfo(0)
-8
View File
@@ -53,14 +53,6 @@ func (m *Machine) ReadFile(name string, args ...any) ([]byte, error) {
return m.zone.zones.ReadFile(fullName)
}
// ReadLines reads a file from the machine's config directory,
// split by lines, trimmed, and accepting `#` to comment lines out.
func (m *Machine) ReadLines(name string, args ...any) ([]string, error) {
fullName := m.getFilename(name, args...)
return m.zone.zones.ReadLines(fullName)
}
// WriteStringFile writes the given content to a file on the machine's config directory
func (m *Machine) WriteStringFile(value string, name string, args ...any) error {
fullName := m.getFilename(name, args...)
+1 -25
View File
@@ -3,7 +3,6 @@ package cluster
import (
"context"
"net/netip"
"os"
"strconv"
"strings"
"time"
@@ -82,30 +81,7 @@ func (m *Machine) scan(_ *ScanOptions) error {
}
}
return m.loadInactive()
}
func (m *Machine) loadInactive() error {
data, err := m.ReadLines("region")
switch {
case os.IsNotExist(err):
// no file
return nil
case err != nil:
// read error
return err
default:
// look for "none"
for _, r := range data {
switch r {
case "none":
m.Inactive = true
default:
m.Inactive = false
}
}
return nil
}
return nil
}
// scanWrapUp is called once all machines have been scanned
+1 -3
View File
@@ -32,9 +32,7 @@ func (r *Region) ForEachMachine(fn func(*Machine) bool) {
var term bool
z.ForEachMachine(func(p *Machine) bool {
if p.Active() {
term = fn(p)
}
term = fn(p)
return term
})