forked from xcat2/goconserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add break sequence framework to support sysrq
Support at most 9 break sequences which can be invoked with 'Ctrl + e + c + l + [1-9]'. By default all of the break sequence is '~B'. This patch includes the following: 1. Design prefix tree framework to help register and search the sequence keys. 2. Support define break sequences in server.conf 3. Add sequence handler at both server and client side 4. Add rest api and console command to list the break sequences. Ctrl + e + c + l + ? TODO: Manage the sequence keys definition via rest api and store them in etcd.
- Loading branch information
Showing
12 changed files
with
594 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"encoding/json" | ||
"github.com/gorilla/mux" | ||
"github.com/xcat2/goconserver/console" | ||
) | ||
|
||
type EscapeApi struct { | ||
routes Routes | ||
} | ||
|
||
func NewEscapeApi(router *mux.Router) *CommandApi { | ||
api := CommandApi{} | ||
routes := Routes{ | ||
Route{"Command", "GET", "/breaksequence", api.listSequence}, | ||
} | ||
api.routes = routes | ||
for _, route := range routes { | ||
router. | ||
Methods(route.Method). | ||
Path(route.Pattern). | ||
Name(route.Name). | ||
Handler(route.HandlerFunc) | ||
} | ||
return &api | ||
} | ||
|
||
func (api *CommandApi) listSequence(w http.ResponseWriter, req *http.Request) { | ||
plog.Debug(fmt.Sprintf("Receive %s request %s from %s.", req.Method, req.URL.Path, req.RemoteAddr)) | ||
var resp []byte | ||
var err error | ||
w.Header().Set("Content-Type", "application/json; charset=UTF-8") | ||
w.WriteHeader(http.StatusOK) | ||
serverEscape := console.GetServerEscape() | ||
if serverEscape == nil { | ||
plog.HandleHttp(w, req, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
seqs := serverEscape.GetSequences() | ||
if resp, err = json.Marshal(seqs); err != nil { | ||
plog.HandleHttp(w, req, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
fmt.Fprintf(w, "%s\n", resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.