package cluster import ( "net/netip" "strings" ) // revive:disable:line-length-limit // A Machine is a machine on a Zone type Machine struct { zone *Zone logger `json:"-" yaml:"-"` ID int Name string `json:"-" yaml:"-"` 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"` } // revive:enable:line-length-limit func (m *Machine) String() string { return m.Name } // FullName returns the Name of the machine including domain name func (m *Machine) FullName() string { var name []string for _, s := range []string{ m.Name, m.zone.zones.Name, m.zone.zones.Domain, } { if s != "" { name = append(name, s) } } return strings.Join(name, ".") } // IsGateway tells if the Machine is a ring0 gateway func (m *Machine) IsGateway() bool { _, ok := m.getRingInfo(0) return ok } // 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) } // Zone indicates the [Zone] this machine belongs to func (m *Machine) Zone() int { return m.zone.ID } func (m *Machine) getPeerByName(name string) (*Machine, bool) { return m.zone.zones.GetMachineByName(name) }