state manager stub

This commit is contained in:
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/glog"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"code.hackerspace.pl/q3k/topo/graph"
confpb "code.hackerspace.pl/q3k/topo/proto/config" confpb "code.hackerspace.pl/q3k/topo/proto/config"
"code.hackerspace.pl/q3k/topo/graph"
"code.hackerspace.pl/q3k/topo/state"
) )
var ( var (
@ -57,9 +59,11 @@ func main() {
glog.Exitf("Initial netbox feed failed: %v", err) glog.Exitf("Initial netbox feed failed: %v", err)
} }
stm := state.NewManager()
sconf := ServiceConfig{ sconf := ServiceConfig{
DebugListen: flagDebugListen, DebugListen: flagDebugListen,
} }
srv := NewService(gr, sconf) srv := NewService(gr, stm, sconf)
srv.Run() srv.Run()
} }

View file

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