kea-manage/ipv4/reservation/reservation.go
Matthew Stobbs e68723738b added sample config
- simplified configuration file
- simplified to only use ipv4 and macaddresses for now
- added update query
- if insert fails with already exists error, try to update instead
2024-12-02 12:20:39 -07:00

46 lines
1.1 KiB
Go

package reservation
import (
"log/slog"
"git.staur.ca/stobbsm/kea-manage/lib/validators/ipv4"
"git.staur.ca/stobbsm/kea-manage/lib/validators/macaddr"
)
type ReservationV4 struct {
SubnetID int
Identifier string
Ipv4 string
Hostname string
typeName string
}
func ReserveV4MacAddr(identifier string, addr string, hostname string, subnet int) *ReservationV4 {
r := &ReservationV4{
SubnetID: subnet,
Identifier: identifier,
Ipv4: addr,
Hostname: hostname,
}
return r
}
// Validate implements the Validator interface. Returns true when valid, false when not.
// Will print message to the slog Error channel when an error is found to provide more information
// This does not validate against the database, just validates that the written configuration
// is correct
func (r *ReservationV4) Validate() bool {
if !ipv4.IsValid(r.Ipv4) {
slog.Error("validate", slog.Any("reservationV4.ipv4", r.Ipv4))
return false
}
if !macaddr.IsValid(r.Identifier) {
slog.Error("validate", slog.Any("reservationV4.identifier", r.Identifier))
return false
}
return true
}