summaryrefslogtreecommitdiff
path: root/src/rhctl/switch_control.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-04-03 00:29:47 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-04-03 00:29:47 (GMT)
commit3d8206bf7883b56f5adb4252c7d0c9190d541874 (patch)
tree10fed6b82e56107bf98e42bce190fe6226f60128 /src/rhctl/switch_control.go
parent783cf8a2b983186b371cec346ad9151eebcc5ed1 (diff)
shallow implementation of server command
Diffstat (limited to 'src/rhctl/switch_control.go')
-rw-r--r--src/rhctl/switch_control.go21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go
index a73d465..463c97e 100644
--- a/src/rhctl/switch_control.go
+++ b/src/rhctl/switch_control.go
@@ -96,9 +96,14 @@ func (ctrl *SwitchControl) handleCommand(cmd *Command) {
case CmdState:
cmd.Response <- ctrl.state
case CmdServer:
+ if len(cmd.Args) == 0 {
+ cmd.Response <- fmt.Errorf("no server specified")
+ return
+ }
+ cmd.Response <- ctrl.reconcile(cmd.Args[0])
case CmdSwitch:
if len(cmd.Args) == 0 {
- rhl.Printf("SwitchCTRL: ignoring empty raw switch command")
+ cmd.Response <- fmt.Errorf("no command specified")
return
}
c, err := NewSwitchCommandFromStrings(cmd.Args[0], cmd.Args[1:]...)
@@ -118,15 +123,17 @@ func handleServer(in <-chan ServerState, out chan<- ServerState) {
}
}
-func (ctrl *SwitchControl) reconcile() {
- rhdl.Printf("SwitchCTRL: reconciling state...")
+func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) {
+ rhdl.Printf("SwitchCTRL: reconciling state... (requested server: '%s')", requestedServer)
// TODO: set mood dependent on overall-state
// TODO: send out commands to switch, server to get missing infos
- // TODO: change active server it fails
+ // TODO: change active server it fails or on request
+ // return true if requested server got selected
// TODO: change switch output mappings if servers change channels or fail
+ return
}
func (ctrl *SwitchControl) Run() {
@@ -137,7 +144,7 @@ func (ctrl *SwitchControl) Run() {
go handleServer(srv.StateChanges, serverStateChanges)
}
- ctrl.reconcile()
+ ctrl.reconcile("")
for {
select {
case update := <-ctrl.sw.Updates:
@@ -150,13 +157,13 @@ func (ctrl *SwitchControl) Run() {
rhdl.Printf("got switch state update: %+v", state)
ctrl.Updates.Pub(state, "switch:state")
ctrl.state.Switch = state
- ctrl.reconcile()
+ ctrl.reconcile("")
ctrl.Updates.Pub(ctrl.state, "state")
case state := <-serverStateChanges:
rhdl.Printf("got server state update: %+v", state)
ctrl.Updates.Pub(state, "server:state")
ctrl.state.Server[state.Name] = state
- ctrl.reconcile()
+ ctrl.reconcile("")
ctrl.Updates.Pub(ctrl.state, "state")
case cmd := <-ctrl.Commands:
ctrl.handleCommand(cmd)