Skip to content
Snippets Groups Projects
Commit 40fb6b1b authored by Malte Bauch's avatar Malte Bauch
Browse files

Merge branch '52-add-command-line-flags-to-gosdn-tview' into 'v.0.1.0-codename-threadbare'

Resolve "Add command-line flags to goSDN-tview"

See merge request cocsn/gosdn!70
parents 6cc58c2f 06fee9eb
No related branches found
No related tags found
3 merge requests!90Develop,!70Resolve "Add command-line flags to goSDN-tview",!53V.0.1.0 Codename Threadbare
Pipeline #53122 failed
......@@ -22,17 +22,16 @@ type command struct {
//CommandList contains the specific goSDN gRPC calls
var CommandList = []command{
{"hello", "test connection to goSDN controller", goSDNSayHello},
{"shutdown", "request goSDN controller to shutdown", goSDNShutdown},
{"hello", "test connection to controller", goSDNSayHello},
{"testdb", "test all database connections", goSDNTestDB},
{"tapigetedge", "get list of edges", TAPIGetEdge},
{"tapigetedgenode", "get list of edgenodes", TAPIGetEdgeNode},
{"tapigetlink", "get list of links", TAPIGetLink},
{"tapiGetDevices", "creates devices", TAPIGetEdge},
{"tapiGetInterfaces", "creates interfaces", TAPIGetEdgeNode},
{"tapiGetLinks", "creates links between devices", TAPIGetLink},
{"shutdown", "request controller to shutdown", goSDNShutdown},
}
//Connect creates a new connection to the gRPC server
func Connect() (*grpc.ClientConn, error) {
address := "141.100.70.170:55066"
func Connect(address string) (*grpc.ClientConn, error) {
return grpc.Dial(address, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second), grpc.WithBlock())
}
......@@ -51,7 +50,7 @@ func GoSDNLogStream(conn *grpc.ClientConn, clv *tview.TextView) error {
streamError = err
break
}
response := []byte(msg.Log + "\n")
response := []byte(msg.Log)
clv.Write(response)
}
}(stream)
......
package main
import (
"flag"
"strconv"
"strings"
"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
grpc "code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/grpc"
"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/views"
......@@ -8,7 +12,13 @@ import (
)
func main() {
conn, err := grpc.Connect()
addrIPv4 := flag.String("addr", "localhost", "IPv4 server adress to connect to")
port := flag.Int("port", 55055, "Port of gRPC")
flag.Parse()
addr := strings.Join([]string{*addrIPv4, strconv.Itoa(*port)}, ":")
conn, err := grpc.Connect(addr)
if err != nil {
log.Fatal(err)
}
......
......@@ -35,7 +35,7 @@ func (cv *CommandListView) GetContent() tview.Primitive {
func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView,
conn *grpc.ClientConn) {
//TODO: create own command in grpc -> commands
cv.commandsList.AddItem("AddPND", "closes the application", 'a', func() {
cv.commandsList.AddItem("addPND", "closes the application", 'a', func() {
rv.ChangeContentView("addPND")
app.SetFocus(rv.GetContent())
})
......@@ -50,7 +50,7 @@ func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView,
})
}
cv.commandsList.AddItem("Show Log", "shows the log of goSDN", 'l', func() {
cv.commandsList.AddItem("log", "shows the log of goSDN", 'l', func() {
rv.ChangeContentView("log")
})
......
......@@ -3,7 +3,7 @@ package views
import (
"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
"github.com/rivo/tview"
"time"
//"time"
)
//DatabaseStatusView is an application view to display the current status of
......@@ -24,8 +24,9 @@ func NewDatabaseStatusView(app *app.App) *DatabaseStatusView {
SetBorder(true).
SetTitle("Database")
// run the periodical refresh in a new go routine
go databaseTicker(dv)
//TODO: dummy text at the moment. database status check has to be initilized
//here
dv.databaseStatusView.SetText("[green]" + "connected")
return dv
}
......@@ -40,11 +41,3 @@ func (dv *DatabaseStatusView) SetContent(s string) {
dv.databaseStatusView.Clear()
dv.databaseStatusView.SetText(s)
}
func databaseTicker(dv *DatabaseStatusView) {
//TODO see gRPCStatusView!
ticker := time.NewTicker(5 * time.Second)
for t := range ticker.C {
dv.SetContent(t.String())
}
}
......@@ -49,13 +49,17 @@ func (sv *GRPCStatusView) SetContent(s string) {
}
func gRPCTicker(sv *GRPCStatusView, conn *grpc.ClientConn) {
sv.SetContent(checkStatus(conn))
//TODO: refactor -> get rid of hardcoded values
ticker := time.NewTicker(5 * time.Second)
for range ticker.C {
if str := conn.GetState().String(); str == "READY" || str == "IDLE" {
sv.SetContent("[green]" + "connected")
} else {
sv.SetContent("[red]" + "disconnected")
}
sv.SetContent(checkStatus(conn))
}
}
func checkStatus(conn *grpc.ClientConn) string {
if str := conn.GetState().String(); str == "READY" || str == "IDLE" {
return "[green]" + "connected"
}
return "[red]" + "disconnected"
}
......@@ -2,12 +2,12 @@ package views
import "github.com/rivo/tview"
var goSDNAscii = ` ____ ____ _ _ _ _ _ _ _ ____ _ _ _
__ _ ___/ ___|| _ \| \ | | | | | | ___ ___| |__ ___ ___| |__ _ _| | ___ | _ \ __ _ _ __ _ __ ___ ___| |_ __ _ __| | |_
/ _ |/ _ \___ \| | | | \| | _____ | |_| |/ _ \ / __| '_ \/ __|/ __| '_ \| | | | |/ _ \ | | | |/ _ | '__| '_ _ \/ __| __/ _ |/ _ | __|
| (_| | (_) |__) | |_| | |\ | |_____| | _ | (_) | (__| | | \__ \ (__| | | | |_| | | __/ | |_| | (_| | | | | | | | \__ \ || (_| | (_| | |_
\__ |\___/____/|____/|_| \_| |_| |_|\___/ \___|_| |_|___/\___|_| |_|\__,_|_|\___| |____/ \__,_|_| |_| |_| |_|___/\__\__,_|\__,_|\__|
|___/ `
var goSDNAscii = ` ____ ____ _ _ _ __ _ _ _
__ _ ___/ ___|| _ \| \ | | __| | __ _ / / __ ___| |_ | |__ __| | __ _
/ _ |/ _ \___ \| | | | \| | _____ / _ |/ _ | / / _ \ / _ \ __| _____ | _ \ / _ |/ _ |
| (_| | (_) |__) | |_| | |\ | |_____| | (_| | (_| |/ /| | | | __/ |_ |_____| | | | | | (_| | (_| |
\__, |\___/____/|____/|_| \_| \__,_|\__,_/_/ |_| |_|\___|\__| |_| |_|___\__,_|\__,_|
|___/ |_____| `
//HeaderView is an application view to display the header of the application
type HeaderView struct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment