Include zone records in status

This commit is contained in:
Adam Harrison committed 2015-03-17 15:02:09 +00:00
1 parent 50f6402774
commit 6f57774d15
3 files changed
+16

No files matched your search

+1
View File
@@ -24,6 +24,7 @@ func ListenHttp(version string, domain string, db Zone, port int) {
router.Methods("GET").Path("/status").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, fmt.Sprintln("weave DNS", version))
io.WriteString(w, fmt.Sprintln("Serving domain", domain))
io.WriteString(w, db.Status())
})
router.Methods("PUT").Path("/name/{identifier:.+}/{ip:.+}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+14
View File
@@ -5,6 +5,8 @@ import (
. "github.com/zettio/weave/common"
"net"
"sync"
"bytes"
"fmt"
)
const (
@@ -20,6 +22,7 @@ type Lookup interface {
}
type Zone interface {
Status() string
AddRecord(ident string, name string, ip net.IP) error
DeleteRecord(ident string, ip net.IP) error
DeleteRecordsFor(ident string) error
@@ -61,6 +64,17 @@ func (zone *ZoneDb) indexOf(match func(Record) bool) int {
return -1
}
func (zone *ZoneDb) Status() string {
zone.mx.RLock()
defer zone.mx.RUnlock()
var buf bytes.Buffer
buf.WriteString("Records:\n")
for _, r := range zone.recs {
buf.WriteString(fmt.Sprintf("%s %s %v\n", r.Ident, r.IP, r.Name))
}
return buf.String()
}
func (zone *ZoneDb) LookupName(name string) (net.IP, error) {
zone.mx.RLock()
defer zone.mx.RUnlock()
+1
View File
@@ -556,6 +556,7 @@ case "$COMMAND" in
;;
status)
http_call $CONTAINER_NAME $HTTP_PORT GET /status
echo
http_call $DNS_CONTAINER_NAME $DNS_HTTP_PORT GET /status
;;
ps)