62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"log/slog"
|
||
|
"os"
|
||
|
|
||
|
"git.staur.ca/stobbsm/kea-manage/ipv4/reservation"
|
||
|
"github.com/jackc/pgx/v5"
|
||
|
)
|
||
|
|
||
|
// Manage kea dhcp host reservations in postgresql directly
|
||
|
// postgresql schema used from [https://gitlab.isc.org/isc-projects/kea/-/wikis/docs/editing-host-reservations]
|
||
|
|
||
|
// This will only work with hw-address identifiers. If I need support for more, I'll add it
|
||
|
|
||
|
func main() {
|
||
|
reslist := []*reservation.ReservationV4{
|
||
|
reservation.ReserveV4MacAddr(
|
||
|
"90:e2:ba:19:25:70",
|
||
|
"10.0.255.2",
|
||
|
"mars",
|
||
|
100,
|
||
|
),
|
||
|
reservation.ReserveV4MacAddr(
|
||
|
"90:e2:ba:19:25:70",
|
||
|
"10.1.255.2",
|
||
|
"mars",
|
||
|
101,
|
||
|
),
|
||
|
reservation.ReserveV4MacAddr(
|
||
|
"90:e2:ba:19:25:70",
|
||
|
"10.2.255.2",
|
||
|
"mars",
|
||
|
102,
|
||
|
),
|
||
|
reservation.ReserveV4MacAddr(
|
||
|
"90:e2:ba:19:25:70",
|
||
|
"10.3.255.2",
|
||
|
"mars",
|
||
|
103,
|
||
|
),
|
||
|
}
|
||
|
|
||
|
conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
|
||
|
if err != nil {
|
||
|
slog.Error(err.Error())
|
||
|
} else {
|
||
|
slog.Info("connected to database")
|
||
|
}
|
||
|
defer conn.Close(context.Background())
|
||
|
|
||
|
for _, v := range reslist {
|
||
|
v := v
|
||
|
if err = v.Insert(conn); err != nil {
|
||
|
slog.Error(err.Error())
|
||
|
continue
|
||
|
}
|
||
|
slog.Info("inserted reservation", *v)
|
||
|
}
|
||
|
}
|