parent
54eda59c6e
commit
bd62967a53
20
argv.go
20
argv.go
|
@ -12,9 +12,7 @@ import (
|
|||
var argv args
|
||||
|
||||
type args struct {
|
||||
ListRepos bool `arg:"--list-repos" help:"list all repositories"`
|
||||
Port int `arg:"--port" default:"2520" help:"port to run on"`
|
||||
Start string `arg:"--start" help:"start a droplet"`
|
||||
}
|
||||
|
||||
func (args) Version() string {
|
||||
|
@ -24,3 +22,21 @@ func (args) Version() string {
|
|||
func init() {
|
||||
arg.MustParse(&argv)
|
||||
}
|
||||
|
||||
func (a args) Description() string {
|
||||
return `
|
||||
this daemon talks to virtigo talks to libvirt and/or qemu
|
||||
|
||||
This sends data back to virtigo. It helps read out the libvirtxml
|
||||
and convert it to protobuf.
|
||||
The name is odd, it's virtigo-D not virti-god.
|
||||
|
||||
You can query the status directly:
|
||||
|
||||
# the list of running vms:
|
||||
curl --silent http://localhost:2520/vms
|
||||
|
||||
# information about vm foo.bar.com:
|
||||
curl --silent http://localhost:2520/dumpdroplet?foo.bar.com
|
||||
`
|
||||
}
|
||||
|
|
109
http.go
109
http.go
|
@ -22,12 +22,8 @@ func cleanURL(url string) string {
|
|||
}
|
||||
|
||||
func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var tmp string
|
||||
|
||||
log.Info("Got URL Path: ", r.URL.Path)
|
||||
log.Info("Got URL Query:", r.URL.Query().Get("start"))
|
||||
|
||||
tmp = cleanURL(r.URL.Path)
|
||||
route := cleanURL(r.URL.Path)
|
||||
|
||||
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
|
||||
if err != nil {
|
||||
|
@ -36,33 +32,59 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
log.Info("Got URL msg:", string(msg))
|
||||
log.Info("Got URL jcarr2 tmp:", tmp)
|
||||
if tmp == "/" {
|
||||
if route == "/" {
|
||||
fmt.Fprintln(w, "OK")
|
||||
return
|
||||
}
|
||||
|
||||
// curl http://localhost:2520/dumpdomain?domain=foo.bar.com
|
||||
if route == "/dumpdomain" {
|
||||
domname := r.URL.Query().Get("domain")
|
||||
fmt.Fprint(w, "import domain:", domname)
|
||||
|
||||
xmldoc, err := virshDumpXML(w, r, domname)
|
||||
|
||||
domcfg := &libvirtxml.Domain{}
|
||||
err = domcfg.Unmarshal(xmldoc)
|
||||
if err != nil {
|
||||
fmt.Fprintln(w, "domain.Unmarshal XML failed")
|
||||
fmt.Fprintln(w, "error =", err)
|
||||
return
|
||||
}
|
||||
d, _, err := virtigolib.ImportXML(domcfg)
|
||||
if err != nil {
|
||||
fmt.Fprintln(w, "ImportXML failed for", domname, err)
|
||||
return
|
||||
}
|
||||
fmt.Fprintln(w, "ImportXML worked for", domname)
|
||||
fmt.Fprintln(w, "should send the protobuf to virtigo here", domname)
|
||||
d.Current.FullXml = xmldoc
|
||||
d.DumpDroplet(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
if route == "/vms" {
|
||||
s := pollHypervisor(me.hv)
|
||||
fmt.Fprint(w, s)
|
||||
return
|
||||
}
|
||||
|
||||
// exit the virtigo daemon & have systemd restart it
|
||||
// this can happen & when it does, access to
|
||||
// to libvirtd will hang (aka: virsh list will hang)
|
||||
// One way to trigger this is to not properly close
|
||||
// domain sockets opened from go-qemu/hypervisor
|
||||
// it's a good idea in any case so leave it here
|
||||
if tmp == "/kill" {
|
||||
if route == "/kill" {
|
||||
log.Warn("KILLED")
|
||||
fmt.Fprintln(w, "KILLED")
|
||||
os.Exit(-1)
|
||||
return
|
||||
}
|
||||
|
||||
if tmp == "/vms" {
|
||||
s := pollHypervisor(me.hv)
|
||||
fmt.Fprint(w, s)
|
||||
return
|
||||
}
|
||||
|
||||
if tmp == "/import" {
|
||||
domname := r.URL.Query().Get("import")
|
||||
// curl http://localhost:2520/import?domain=foo.bar.com
|
||||
if route == "/import" {
|
||||
domname := r.URL.Query().Get("domain")
|
||||
fmt.Fprint(w, "import domain:", domname)
|
||||
|
||||
xmldoc, err := virshDumpXML(w, r, domname)
|
||||
|
@ -87,39 +109,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
/*
|
||||
if tmp == "/cluster" {
|
||||
log.Info("/cluster jcarr actually doing START")
|
||||
fmt.Fprintln(w, "/cluster jcarr actually doing START")
|
||||
c := pb.InitCluster()
|
||||
|
||||
fmt.Fprintln(w, "cluster len(msg) =", len(msg))
|
||||
err = c.UnmarshalJSON(msg)
|
||||
if err != nil {
|
||||
fmt.Fprintln(w, "cluster dirs failed")
|
||||
fmt.Fprintln(w, "error =", err)
|
||||
}
|
||||
for _, dir := range c.Dirs {
|
||||
var found bool = false
|
||||
for _, d := range me.dirs {
|
||||
if d == dir {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if found {
|
||||
log.Info("dir already here", dir)
|
||||
fmt.Fprintln(w, "dir already here", dir)
|
||||
} else {
|
||||
log.Info("append new dir", dir)
|
||||
fmt.Fprintln(w, "append new dir", dir)
|
||||
me.dirs = append(me.dirs, dir)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
if tmp == "/start" {
|
||||
if route == "/start" {
|
||||
log.Info("/start jcarr actually doing START", me.Hostname)
|
||||
fmt.Fprintln(w, "/start jcarr actually doing START", me.Hostname)
|
||||
start := r.URL.Query().Get("start")
|
||||
|
@ -162,11 +152,9 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
cmd := []string{"virsh", "create", xml}
|
||||
|
||||
fmt.Fprintln(w, "Handling URL:", tmp, "start droplet")
|
||||
log.Warn("cmd :", cmd)
|
||||
fmt.Fprintln(w, "Handling start droplet", cmd)
|
||||
|
||||
fmt.Fprintln(w, "Handling URL:", tmp, "start droplet")
|
||||
fmt.Fprintln(w, "cmd: ", cmd)
|
||||
err, ok, output := shell.RunCmd("/home/", cmd)
|
||||
shell.Run(cmd)
|
||||
if ok {
|
||||
|
@ -180,24 +168,13 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if tmp == "/favicon.ico" {
|
||||
if route == "/favicon.ico" {
|
||||
writeFile(w, "ipv6.png")
|
||||
return
|
||||
}
|
||||
if tmp == "/uptime" {
|
||||
writeFile(w, "uptime.html")
|
||||
return
|
||||
}
|
||||
|
||||
// used for uptime monitor checking (like Kuma)
|
||||
if tmp == "/uptime" {
|
||||
writeFile(w, "uptime.html")
|
||||
return
|
||||
}
|
||||
log.Warn("BAD URL =", tmp)
|
||||
fmt.Fprintln(w, "BAD ZOOT")
|
||||
// badurl(w, r.URL.String())
|
||||
// fmt.Fprintln(w, "BAD", tmp)
|
||||
log.Warn("BAD URL =", route)
|
||||
fmt.Fprintln(w, "BAD URL =", route)
|
||||
}
|
||||
|
||||
func writeFile(w http.ResponseWriter, filename string) {
|
||||
|
|
Loading…
Reference in New Issue