-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Web console for humans * Formatting * Update chart.yaml * Fix templates in dockerfile * Rename 'info' to 'annotations' * placements: Rename Date CreationTimestamp and use time.Time * Don't break the API, deprecate instead * Update swagger version
- Loading branch information
Showing
13 changed files
with
229 additions
and
8 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package console | ||
|
||
import ( | ||
"encoding/json" | ||
"html/template" | ||
"github.com/julienschmidt/httprouter" | ||
"github.com/redhat-gpe/agnostics/internal/config" | ||
"github.com/redhat-gpe/agnostics/internal/api/v1" | ||
"github.com/redhat-gpe/agnostics/internal/log" | ||
"github.com/redhat-gpe/agnostics/internal/placement" | ||
"io" | ||
"path/filepath" | ||
"net/http" | ||
) | ||
|
||
func marshal(data interface{}) string { | ||
json, err := json.MarshalIndent(data, "", " ") | ||
if err != nil { | ||
log.Err.Fatal(err) | ||
} | ||
return string(json) | ||
} | ||
|
||
func countPlacements(name string) string{ | ||
reply, err := placement.GetCountPlacementsByCloud(name) | ||
if err != nil { | ||
return "ERROR" | ||
} | ||
return reply | ||
} | ||
|
||
func getDashboard(w http.ResponseWriter, req *http.Request, params httprouter.Params) { | ||
w.Header().Set("Content-Type", "text/html") | ||
placements, err := placement.GetAll(100) | ||
if err != nil{ | ||
w.WriteHeader(http.StatusInternalServerError) | ||
io.WriteString(w, "ERROR") | ||
log.Err.Println(err) | ||
return | ||
} | ||
|
||
var fm = template.FuncMap{ | ||
"marshal": marshal, | ||
"countPlacements": countPlacements, | ||
} | ||
|
||
clouds := config.GetClouds() | ||
|
||
type HomeData struct { | ||
Clouds map[string]v1.Cloud | ||
Placements []v1.Placement | ||
} | ||
|
||
t := template.Must( | ||
template.New("layout.tmpl").Funcs(fm).ParseGlob( | ||
filepath.Join(templateDir,"/*.tmpl"))) | ||
|
||
t.ExecuteTemplate(w, "layout.tmpl", HomeData { | ||
clouds, | ||
placements, | ||
}) | ||
} | ||
|
||
var templateDir string | ||
|
||
// Serve function is | ||
func Serve(t string) { | ||
templateDir = t | ||
router := httprouter.New() | ||
|
||
// Protected | ||
router.GET("/", getDashboard) | ||
|
||
log.Out.Println("Console listen on port :8081") | ||
log.Err.Fatal(http.ListenAndServe(":8081", router)) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<div class="pure-u-1 pure-u-md-1-2"> | ||
<h1>Clouds</h1> | ||
|
||
<table class="pure-table pure-table-horizontal"> | ||
<tr> | ||
<td>Name</td> | ||
<td>Placements</td> | ||
<td>Labels</td> | ||
<td>Enabled</td> | ||
<td>Taints</td> | ||
</tr> | ||
|
||
{{ range . }} | ||
<tr> | ||
<td><b>{{ .Name }}</b></td> | ||
<td>{{ countPlacements .Name }}</td> | ||
<td> | ||
<ul> | ||
{{ range $key, $val := .Labels }} | ||
<li><code>{{ $key }}: {{ $val }}</code></li> | ||
{{end}} | ||
</ul> | ||
</td> | ||
<td> | ||
{{ if eq .Enabled true }} | ||
<span style="font-weight: bold; color: green">true</span> | ||
{{ else }} | ||
<span style="font-weight: bold; color: red">false</span> | ||
{{ end }} | ||
</td> | ||
<td><pre>{{ marshal .Taints }}</pre></td> | ||
</tr> | ||
{{ end }} | ||
</table> | ||
</div> |
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,28 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Dashboard</title> | ||
<link rel="stylesheet" href="https://unpkg.com/purecss@2.0.3/build/pure-min.css" integrity="sha384-cg6SkqEOCV1NbJoCu11+bm0NvBRc8IYLRGXkmNrqUBfTjmMYwNKPWBTIKyw9mHNJ" crossorigin="anonymous"> | ||
<link rel="stylesheet" href="https://unpkg.com/purecss@2.0.3/build/base-min.css"> | ||
<link rel="stylesheet" href="https://unpkg.com/purecss@2.0.3/build/grids-min.css"> | ||
<link rel="stylesheet" href="https://unpkg.com/purecss@2.0.3/build/grids-responsive-min.css"> | ||
|
||
|
||
<style> | ||
.pure-g > div { | ||
box-sizing: border-box; | ||
padding-left: 1em; | ||
} | ||
|
||
tr:nth-child(even) { | ||
background-color: #eeeeee; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="pure-g"> | ||
{{ template "clouds.tmpl" .Clouds }} | ||
{{ template "placements.tmpl" .Placements }} | ||
</div> | ||
</body> | ||
</html> |
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,33 @@ | ||
<div class="pure-u-1 pure-u-md-1-2"> | ||
<h1>Placements</h1> | ||
|
||
<p>Total: {{ countPlacements "all" }} placements</p> | ||
<table class="pure-table pure-table-horizontal" style="font-size: 80%"> | ||
<caption>First 100 placements</caption> | ||
<tr> | ||
<td>Creation Timestamp</td> | ||
<td>UUID</td> | ||
<td>Annotations</td> | ||
<td>Cloud Name</td> | ||
</tr> | ||
|
||
{{ range . }} | ||
<tr> | ||
<td>{{ .CreationTimestamp }}</td> | ||
<td> | ||
<span style="font-size: 80%"> | ||
<code>{{ .UUID }}</code> | ||
</span> | ||
</td> | ||
<td> | ||
<ul> | ||
{{ range $key, $val := .Annotations }} | ||
<li><code>{{ $key }}: {{ $val }}</code></li> | ||
{{ end }} | ||
</ul> | ||
</td> | ||
<td>{{ .Cloud.Name }}</td> | ||
</tr> | ||
{{ end }} | ||
</table> | ||
</div> |