forked from hswaw/hscloud
better graphviz
parent
c7be4a115b
commit
de869df9ac
26
service.go
26
service.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"code.hackerspace.pl/q3k/topo/graph"
|
"code.hackerspace.pl/q3k/topo/graph"
|
||||||
"github.com/gobuffalo/packr"
|
"github.com/gobuffalo/packr"
|
||||||
|
@ -61,32 +62,31 @@ func (s *Service) Run() {
|
||||||
|
|
||||||
http.HandleFunc("/debug/graphviz", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/debug/graphviz", func(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintf(w, "graph G {\n")
|
fmt.Fprintf(w, "graph G {\n")
|
||||||
|
fmt.Fprintf(w, " rankdir = LR\n")
|
||||||
for _, machine := range s.gr.Machines {
|
for _, machine := range s.gr.Machines {
|
||||||
fmt.Fprintf(w, " subgraph cluster%s {\n", machine.Name)
|
portNames := []string{}
|
||||||
fmt.Fprintf(w, " label = %s\n", machine.Name)
|
|
||||||
for _, port := range machine.Ports {
|
for _, port := range machine.Ports {
|
||||||
a := machine.Name + "|" + port.Name
|
name := fmt.Sprintf("<%s> %s", port.Name, port.Name)
|
||||||
fmt.Fprintf(w, " %q [label = %q]\n", a, port.Name)
|
portNames = append(portNames, name)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, " }\n")
|
ports := strings.Join(portNames, "|")
|
||||||
|
fmt.Fprintf(w, " %s [shape=record label=\"{ %s | { %s }}\"]\n", machine.Name, machine.Name, ports)
|
||||||
}
|
}
|
||||||
for _, sw := range s.gr.Switches {
|
for _, sw := range s.gr.Switches {
|
||||||
fmt.Fprintf(w, " subgraph cluster%s {\n", sw.Name)
|
portNames := []string{}
|
||||||
fmt.Fprintf(w, " label = %s\n", sw.Name)
|
|
||||||
for _, port := range sw.Ports {
|
for _, port := range sw.Ports {
|
||||||
a := sw.Name + "|" + port.Name
|
name := fmt.Sprintf("<%s> %s", port.Name, port.Name)
|
||||||
fmt.Fprintf(w, " %q [label = %q]\n", a, port.Name)
|
portNames = append(portNames, name)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, " }\n")
|
ports := strings.Join(portNames, "|")
|
||||||
|
fmt.Fprintf(w, " %s [shape=record label=\"{{ %s } | %s}\"]\n", sw.Name, ports, sw.Name)
|
||||||
}
|
}
|
||||||
for _, machine := range s.gr.Machines {
|
for _, machine := range s.gr.Machines {
|
||||||
for _, port := range machine.Ports {
|
for _, port := range machine.Ports {
|
||||||
if port.OtherEnd == nil {
|
if port.OtherEnd == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
a := machine.Name + "|" + port.Name
|
fmt.Fprintf(w, " %s:%q -- %s:%q\n", machine.Name, port.Name, port.OtherEnd.Switch.Name, port.OtherEnd.Name)
|
||||||
b := port.OtherEnd.Switch.Name + "|" + port.OtherEnd.Name
|
|
||||||
fmt.Fprintf(w, " %q -- %q\n", a, b)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, "}\n")
|
fmt.Fprintf(w, "}\n")
|
||||||
|
|
Loading…
Reference in New Issue