You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.5 KiB
75 lines
1.5 KiB
1 year ago
|
package cluster
|
||
1 year ago
|
|
||
|
import (
|
||
1 year ago
|
"net/netip"
|
||
1 year ago
|
"strings"
|
||
1 year ago
|
)
|
||
|
|
||
1 year ago
|
// revive:disable:line-length-limit
|
||
|
|
||
1 year ago
|
// A Machine is a machine on a Zone
|
||
|
type Machine struct {
|
||
1 year ago
|
zone *Zone
|
||
1 year ago
|
logger `json:"-" yaml:"-"`
|
||
1 year ago
|
|
||
1 year ago
|
ID int
|
||
|
Name string `json:"-" yaml:"-"`
|
||
1 year ago
|
|
||
1 year ago
|
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"`
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
// revive:enable:line-length-limit
|
||
|
|
||
1 year ago
|
func (m *Machine) String() string {
|
||
|
return m.Name
|
||
|
}
|
||
|
|
||
1 year ago
|
// FullName returns the Name of the machine including domain name
|
||
|
func (m *Machine) FullName() string {
|
||
|
if domain := m.zone.zones.domain; domain != "" {
|
||
|
var s = []string{
|
||
|
m.Name,
|
||
|
domain,
|
||
|
}
|
||
|
|
||
|
return strings.Join(s, ".")
|
||
|
}
|
||
|
|
||
|
return m.Name
|
||
|
}
|
||
1 year ago
|
|
||
1 year ago
|
// IsGateway tells if the Machine is a ring0 gateway
|
||
|
func (m *Machine) IsGateway() bool {
|
||
|
_, ok := m.getRingInfo(0)
|
||
|
return ok
|
||
|
}
|
||
|
|
||
1 year ago
|
// SetGateway enables/disables a Machine ring0 integration
|
||
|
func (m *Machine) SetGateway(enabled bool) error {
|
||
|
ri, found := m.getRingInfo(0)
|
||
|
switch {
|
||
|
case !found && !enabled:
|
||
|
return nil
|
||
|
case !found:
|
||
|
var err error
|
||
|
|
||
|
if ri, err = m.createRingInfo(0, false); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
|
||
|
ri.Enabled = enabled
|
||
|
return m.SyncWireguardConfig(0)
|
||
|
}
|
||
|
|
||
1 year ago
|
// Zone indicates the [Zone] this machine belongs to
|
||
|
func (m *Machine) Zone() int {
|
||
|
return m.zone.ID
|
||
|
}
|
||
|
|
||
1 year ago
|
func (m *Machine) getPeerByName(name string) (*Machine, bool) {
|
||
|
return m.zone.zones.GetMachineByName(name)
|
||
|
}
|