forked from hswaw/hscloud
Sergiusz Bazanski
2da126caff
Continued from https://gerrit.hackerspace.pl/c/hscloud/+/73 . Change-Id: Ie761c2af588e06739de94fa1eff4f715d1f9b145
73 lines
1.3 KiB
Go
73 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
mirko "code.hackerspace.pl/hscloud/go/mirko"
|
|
"code.hackerspace.pl/hscloud/go/statusz"
|
|
)
|
|
|
|
const statuszFragment = `
|
|
<style type="text/css">
|
|
.table td,th {
|
|
background-color: #eee;
|
|
padding: 0.2em 0.4em 0.2em 0.4em;
|
|
}
|
|
.table th {
|
|
background-color: #c0c0c0;
|
|
}
|
|
.table {
|
|
background-color: #fff;
|
|
border-spacing: 0.2em;
|
|
}
|
|
</style>
|
|
<div>
|
|
<b>Current leases:</b> {{ .Leases | len }}<br />
|
|
<table class="table">
|
|
<tr>
|
|
<th>IP Address</th>
|
|
<th>MAC Address</th>
|
|
<th>Start</th>
|
|
<th>End</th>
|
|
</tr>
|
|
{{range .Leases }}
|
|
<tr>
|
|
<td>{{ .IP }}</td>
|
|
<td>{{ .MAC }}</td>
|
|
<td>{{ .Start }}</td>
|
|
<td>{{ .End }}</td>
|
|
</tr>
|
|
{{end}}
|
|
</table>
|
|
</div>
|
|
`
|
|
|
|
type szLeases struct {
|
|
IP string
|
|
MAC string
|
|
Start string
|
|
End string
|
|
}
|
|
|
|
func (s *service) setupStatusz(m *mirko.Mirko) {
|
|
statusz.AddStatusPart("Leases", statuszFragment, func(ctx context.Context) interface{} {
|
|
c := make(chan []lease)
|
|
s.leaseC <- c
|
|
leases := <-c
|
|
|
|
ls := make([]szLeases, len(leases))
|
|
|
|
for i, l := range leases {
|
|
ls[i].IP = l.ip.String()
|
|
ls[i].MAC = l.hardware.String()
|
|
ls[i].Start = l.from.String()
|
|
ls[i].End = l.to.String()
|
|
}
|
|
|
|
return struct {
|
|
Leases []szLeases
|
|
}{
|
|
Leases: ls,
|
|
}
|
|
})
|
|
}
|