fea: state for bgp neighbor.
Some checks failed
Coverage CI / build (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
Ubuntu CI / build (push) Has been cancelled

This commit is contained in:
Daniel Ding
2025-09-04 16:39:49 +08:00
parent 101e1e37a3
commit db26f4881f
4 changed files with 93 additions and 29 deletions

View File

@@ -2,6 +2,7 @@ package cswitch
import (
"os/exec"
"strings"
"text/template"
"github.com/luscis/openlan/pkg/api"
@@ -11,7 +12,7 @@ import (
)
const (
BgpBin = "/var/openlan/script/frr-reload"
BgpBin = "/var/openlan/script/frr-client"
BgpEtc = "/etc/frr/frr.conf"
)
@@ -108,7 +109,7 @@ func (w *BgpWorker) save() {
func (w *BgpWorker) reload() {
w.save()
cmd := exec.Command(BgpBin)
cmd := exec.Command(BgpBin, "--reload")
if err := cmd.Run(); err != nil {
w.out.Warn("BgpWorker.reload: %s", err)
return
@@ -142,6 +143,19 @@ func (w *BgpWorker) Get() *schema.Bgp {
LocalAs: w.spec.LocalAs,
RouterId: w.spec.RouterId,
}
show := map[string]struct {
State string `json:"state"`
}{}
out, err := exec.Command(BgpBin, "--show-neighbors").CombinedOutput()
if err == nil {
if err := libol.Unmarshal(&show, out); err != nil {
w.out.Warn("BgpWorker.Get.Status: %s", err)
}
} else {
w.out.Warn("BgpWorker.Get.Status: %s", err)
}
for _, nei := range w.spec.Neighbors {
obj := schema.BgpNeighbor{
Address: nei.Address,
@@ -150,6 +164,9 @@ func (w *BgpWorker) Get() *schema.Bgp {
Receives: nei.Receives,
Advertis: nei.Advertis,
}
if state, ok := show[nei.Address]; ok {
obj.State = strings.ToLower(state.State)
}
data.Neighbors = append(data.Neighbors, obj)
}
return data