Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gitlab-review-float-env-dashboard
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ai3
tools
gitlab-review-float-env-dashboard
Commits
6d2b2375
Commit
6d2b2375
authored
3 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parents
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.go
+131
-0
131 additions, 0 deletions
main.go
with
131 additions
and
0 deletions
main.go
0 → 100644
+
131
−
0
View file @
6d2b2375
package
main
import
(
"bytes"
"compress/flate"
"encoding/base64"
"encoding/json"
"flag"
"html/template"
"io"
"log"
"net/http"
)
var
(
addr
=
flag
.
String
(
"addr"
,
":3499"
,
"address to listen on"
)
hostname
=
flag
.
String
(
"hostname"
,
"localhost"
,
"public hostname"
)
)
var
(
dashTplSrc
=
`<!doctype html>
<html lang="en">
<head>
<title>VMine test cluster</title>
<style type="text/css">
body { background: white; }
.name { font-size: 120%; }
.attrs { color: #666; font-size: 90%; }
.table { border: 0; width: 100%; }
</style>
</head>
<body>
<h1>VMine test cluster</h1>
<h4>Hosts</h4>
<table class="table">
<tbody>
{{$hostname := .Hostname}}
{{range $index, $host := .Inventory}}
<tr>
<td>
<b class="name">{{$host.Name}}</b> {{$host.IP}}<br>
<span class="attrs">
{{$host.CPU}} cores, {{$host.RAM}}M ram
</span>
</td>
<td>
<pre>ssh -i ~/.vagrant.d/insecure_private_key -J {{$hostname}} vagrant@{{$host.IP}}</pre>
</td>
</tr>
{{end}}
</tbody>
</table>
<h4>SOCKS proxy connection</h4>
<pre>ssh -n -L 9051:{{.SocksIP}}:9051 {{.Hostname}} &
export https_proxy=localhost:9051
</pre>
</body>
</html>`
dashTpl
=
template
.
Must
(
template
.
New
(
""
)
.
Parse
(
dashTplSrc
))
)
type
hostinfo
struct
{
Name
string
`json:"name"`
Image
string
`json:"image"`
CPU
float64
`json:"cpu"`
RAM
float64
`json:"ram"`
IP
string
`json:"ip"`
}
func
decompress
(
input
[]
byte
)
([]
byte
,
error
)
{
var
out
bytes
.
Buffer
r
:=
flate
.
NewReader
(
bytes
.
NewReader
(
input
))
defer
r
.
Close
()
_
,
err
:=
io
.
Copy
(
&
out
,
r
)
return
out
.
Bytes
(),
err
}
func
decodePayload
(
encoded
string
)
([]
*
hostinfo
,
error
)
{
compressed
,
err
:=
base64
.
URLEncoding
.
DecodeString
(
encoded
)
if
err
!=
nil
{
return
nil
,
err
}
decompressed
,
err
:=
decompress
(
compressed
)
if
err
!=
nil
{
return
nil
,
err
}
var
inventory
[]
*
hostinfo
err
=
json
.
Unmarshal
(
decompressed
,
&
inventory
)
return
inventory
,
err
}
func
handleRequest
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
inventory
,
err
:=
decodePayload
(
req
.
URL
.
Path
)
if
err
!=
nil
{
log
.
Printf
(
"error decoding payload: %s"
,
err
)
http
.
Error
(
w
,
"Bad Request"
,
http
.
StatusBadRequest
)
return
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/html; charset=utf-8"
)
w
.
Header
()
.
Set
(
"Cache-Control"
,
"no-store"
)
// nolint: errcheck
dashTpl
.
Execute
(
w
,
struct
{
Inventory
[]
*
hostinfo
SocksIP
string
Hostname
string
}{
Inventory
:
inventory
,
SocksIP
:
inventory
[
0
]
.
IP
,
Hostname
:
*
hostname
,
})
}
func
main
()
{
log
.
SetFlags
(
0
)
flag
.
Parse
()
http
.
Handle
(
"/dash/"
,
http
.
StripPrefix
(
"/dash/"
,
http
.
HandlerFunc
(
handleRequest
)))
log
.
Fatal
(
http
.
ListenAndServe
(
*
addr
,
nil
))
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment