cluster: introduce Machine.Inactive flag #38
+1
-1
@@ -52,7 +52,7 @@ func populateDNSManager(mgr *dns.Manager, m *cluster.Cluster) error {
|
|||||||
|
|
||||||
m.ForEachZone(func(z *cluster.Zone) bool {
|
m.ForEachZone(func(z *cluster.Zone) bool {
|
||||||
z.ForEachMachine(func(p *cluster.Machine) bool {
|
z.ForEachMachine(func(p *cluster.Machine) bool {
|
||||||
err = mgr.AddHost(ctx, z.Name, p.ID, true, p.PublicAddresses...)
|
err = mgr.AddHost(ctx, z.Name, p.ID, p.IsActive(), p.PublicAddresses...)
|
||||||
return err != nil
|
return err != nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type Machine struct {
|
|||||||
ID int
|
ID int
|
||||||
Name string `json:"-" yaml:"-"`
|
Name string `json:"-" yaml:"-"`
|
||||||
|
|
||||||
|
Inactive bool `json:"inactive,omitempty" yaml:"inactive,omitempty"`
|
||||||
|
|
|||||||
CephMonitor bool `json:"ceph_monitor,omitempty" yaml:"ceph_monitor,omitempty"`
|
CephMonitor bool `json:"ceph_monitor,omitempty" yaml:"ceph_monitor,omitempty"`
|
||||||
PublicAddresses []netip.Addr `json:"public,omitempty" yaml:"public,omitempty"`
|
PublicAddresses []netip.Addr `json:"public,omitempty" yaml:"public,omitempty"`
|
||||||
Rings []*RingInfo `json:"rings,omitempty" yaml:"rings,omitempty"`
|
Rings []*RingInfo `json:"rings,omitempty" yaml:"rings,omitempty"`
|
||||||
@@ -43,6 +44,11 @@ func (m *Machine) FullName() string {
|
|||||||
return strings.Join(name, ".")
|
return strings.Join(name, ".")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsActive indicates the machine is to be included in regions' DNS entries
|
||||||
|
func (m *Machine) IsActive() bool {
|
||||||
|
return !m.Inactive
|
||||||
|
}
|
||||||
|
|
||||||
|
amery marked this conversation as resolved
Outdated
karasz
commented
```go
func (m *Machine) IsActive() bool {
return m.Active
}
|
|||||||
// IsGateway tells if the Machine is a ring0 gateway
|
// IsGateway tells if the Machine is a ring0 gateway
|
||||||
func (m *Machine) IsGateway() bool {
|
func (m *Machine) IsGateway() bool {
|
||||||
_, ok := m.getRingInfo(0)
|
_, ok := m.getRingInfo(0)
|
||||||
|
|||||||
@@ -53,6 +53,14 @@ func (m *Machine) ReadFile(name string, args ...any) ([]byte, error) {
|
|||||||
return m.zone.zones.ReadFile(fullName)
|
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
|
// 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 {
|
func (m *Machine) WriteStringFile(value string, name string, args ...any) error {
|
||||||
fullName := m.getFilename(name, args...)
|
fullName := m.getFilename(name, args...)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package cluster
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -81,7 +82,30 @@ func (m *Machine) scan(_ *ScanOptions) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
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
|
||||||
|
karasz
commented
please see above s/Inactive/Active/ and switch logic. please see above s/Inactive/Active/ and switch logic.
|
|||||||
|
default:
|
||||||
|
m.Inactive = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// scanWrapUp is called once all machines have been scanned
|
// scanWrapUp is called once all machines have been scanned
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ func (r *Region) ForEachMachine(fn func(*Machine) bool) {
|
|||||||
var term bool
|
var term bool
|
||||||
|
|
||||||
z.ForEachMachine(func(p *Machine) bool {
|
z.ForEachMachine(func(p *Machine) bool {
|
||||||
term = fn(p)
|
if p.IsActive() {
|
||||||
|
amery marked this conversation as resolved
Outdated
karasz
commented
```go
if p.IsActive() {
...
```
|
|||||||
|
term = fn(p)
|
||||||
|
}
|
||||||
return term
|
return term
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user
Please name the field
ActiveActivebreaks zero-value rules, everything would become inactive by default