Files
jpictl/pkg/zones/machine.go
T
amery 6a2cbdffd0 WIP
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-25 16:04:01 +00:00

63 lines
1.1 KiB
Go

package zones
import (
"net/netip"
"strings"
)
// A Machine is a machine on a Zone
type Machine struct {
zone *Zone
ID int
Name string `toml:"name"`
PublicAddresses []netip.Addr `toml:"public,omitempty"`
Rings []*RingInfo `toml:"rings,omitempty"`
}
func (m *Machine) String() string {
return m.Name
}
// 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
}
// 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.syncRingConfig(0)
}
func (m *Machine) getPeerByName(name string) (*Machine, bool) {
return m.zone.zones.GetMachineByName(name)
}