state manager stub

master
Serge Bazanski 2018-10-06 17:54:25 +01:00
parent 69518ab6a2
commit a758ef510b
3 changed files with 36 additions and 4 deletions

View File

@ -12,8 +12,10 @@ import (
"github.com/golang/glog"
"github.com/golang/protobuf/proto"
"code.hackerspace.pl/q3k/topo/graph"
confpb "code.hackerspace.pl/q3k/topo/proto/config"
"code.hackerspace.pl/q3k/topo/graph"
"code.hackerspace.pl/q3k/topo/state"
)
var (
@ -57,9 +59,11 @@ func main() {
glog.Exitf("Initial netbox feed failed: %v", err)
}
stm := state.NewManager()
sconf := ServiceConfig{
DebugListen: flagDebugListen,
}
srv := NewService(gr, sconf)
srv := NewService(gr, stm, sconf)
srv.Run()
}

View File

@ -7,11 +7,13 @@ import (
"sort"
"strings"
"code.hackerspace.pl/q3k/topo/graph"
"github.com/gobuffalo/packr"
"github.com/golang/glog"
"github.com/q3k/statusz"
"vbom.ml/util/sortorder"
"code.hackerspace.pl/q3k/topo/graph"
"code.hackerspace.pl/q3k/topo/state"
)
type ServiceConfig struct {
@ -20,12 +22,14 @@ type ServiceConfig struct {
type Service struct {
gr *graph.Graph
stm *state.StateManager
config ServiceConfig
}
func NewService(gr *graph.Graph, c ServiceConfig) *Service {
func NewService(gr *graph.Graph, stm *state.StateManager, c ServiceConfig) *Service {
return &Service{
gr: gr,
stm: stm,
config: c,
}
}

24
state/state.go Normal file
View File

@ -0,0 +1,24 @@
package state
import (
pb "code.hackerspace.pl/q3k/topo/proto/control"
)
type SwitchportState struct {
Proto *pb.SwitchPort
}
type SwitchState struct {
Name string
Ports []*SwitchportState
}
type StateManager struct {
Switches map[string]*SwitchState
}
func NewManager() *StateManager {
return &StateManager{
Switches: make(map[string]*SwitchState),
}
}