parent
720c2e6576
commit
0076d3cb2d
11
http.go
11
http.go
|
@ -91,16 +91,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/dumpdroplet" {
|
if route == "/dumpdroplet" {
|
||||||
hostname := r.URL.Query().Get("hostname")
|
me.cluster.DumpDroplet(w, r)
|
||||||
d := me.cluster.FindDropletByName(hostname)
|
|
||||||
if d == nil {
|
|
||||||
log.Log(WARN, "can not find droplet hostname=", hostname)
|
|
||||||
fmt.Fprintln(w, "can not find droplet hostname=", hostname)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
t := d.FormatTEXT()
|
|
||||||
log.Log(WARN, t)
|
|
||||||
fmt.Fprintln(w, t)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,11 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
pb "go.wit.com/lib/protobuf/virtbuf"
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
"libvirt.org/go/libvirtxml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// attempts to create a new virtual machine
|
// attempts to create a new virtual machine
|
||||||
|
@ -14,7 +16,7 @@ import (
|
||||||
func importDomain(w http.ResponseWriter, r *http.Request) (string, error) {
|
func importDomain(w http.ResponseWriter, r *http.Request) (string, error) {
|
||||||
name := r.URL.Query().Get("domainName")
|
name := r.URL.Query().Get("domainName")
|
||||||
if name == "" {
|
if name == "" {
|
||||||
result := "start failed. name is blank " + r.URL.Path
|
result := "importDomain() failed. name is blank " + r.URL.Path
|
||||||
log.Warn(result)
|
log.Warn(result)
|
||||||
fmt.Fprintln(w, result)
|
fmt.Fprintln(w, result)
|
||||||
return "", errors.New(result)
|
return "", errors.New(result)
|
||||||
|
@ -36,35 +38,87 @@ func importDomain(w http.ResponseWriter, r *http.Request) (string, error) {
|
||||||
fmt.Fprintln(w, result)
|
fmt.Fprintln(w, result)
|
||||||
return result, errors.New(result)
|
return result, errors.New(result)
|
||||||
}
|
}
|
||||||
result := start + " local FOUND! LocalOnly = " + d.LocalOnly
|
|
||||||
log.Log(WARN, result)
|
|
||||||
fmt.Fprintln(w, result)
|
|
||||||
if d.Current.State != pb.DropletState_OFF {
|
if d.Current.State != pb.DropletState_OFF {
|
||||||
result := "error: libvirt domain " + name + " is not off"
|
result := "error: libvirt domain " + name + " is not off"
|
||||||
log.Info(result)
|
log.Info(result)
|
||||||
fmt.Fprintln(w, result)
|
fmt.Fprintln(w, result)
|
||||||
return result, errors.New(result)
|
return result, errors.New(result)
|
||||||
}
|
}
|
||||||
result = start + "about to attempt import "
|
|
||||||
result += "(" + d.LocalOnly + ")"
|
|
||||||
result += " " + d.Hostname
|
|
||||||
log.Log(WARN, result)
|
|
||||||
fmt.Fprintln(w, result)
|
|
||||||
|
|
||||||
h := findHypervisorByName(d.Current.Hypervisor)
|
h := findHypervisorByName(d.Current.Hypervisor)
|
||||||
if h == nil {
|
if h == nil {
|
||||||
result = "unknown hypervisor = " + d.Current.Hypervisor
|
result := "unknown hypervisor = " + d.Current.Hypervisor
|
||||||
log.Log(WARN, result)
|
log.Log(WARN, result)
|
||||||
fmt.Fprintln(w, result)
|
fmt.Fprintln(w, result)
|
||||||
return result, errors.New(result)
|
return result, errors.New(result)
|
||||||
}
|
}
|
||||||
result = "finally ready to h.start(d)"
|
|
||||||
|
// attempt to get the domain record from virtigo
|
||||||
|
xml, err := postImportDomain(h.pb.Hostname, name)
|
||||||
|
if err != nil {
|
||||||
|
log.Log(WARN, err)
|
||||||
|
fmt.Fprintln(w, err)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
domcfg := &libvirtxml.Domain{}
|
||||||
|
err = domcfg.Unmarshal(string(xml))
|
||||||
|
if err != nil {
|
||||||
|
log.Info("Marshal failed", name, err)
|
||||||
|
log.Warn(string(xml))
|
||||||
|
fmt.Fprintln(w, string(xml))
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := fmt.Sprintln("marshal worked", domcfg.Name, domcfg.UUID)
|
||||||
log.Log(WARN, result)
|
log.Log(WARN, result)
|
||||||
fmt.Fprintln(w, result)
|
fmt.Fprintln(w, result)
|
||||||
|
|
||||||
ok, output := h.start(d)
|
return result, nil
|
||||||
if ok {
|
|
||||||
return result + output, nil
|
|
||||||
}
|
}
|
||||||
return result + output, errors.New("start " + name + " on hypervisor " + h.pb.Hostname)
|
|
||||||
|
// this must be bool in string because accumulated output is sometimes
|
||||||
|
// written to STDOUT, sometimes to http
|
||||||
|
func (h *HyperT) importDomain(d *pb.Droplet) (bool, string) {
|
||||||
|
ready, result := me.cluster.DropletReady(d)
|
||||||
|
if !ready {
|
||||||
|
return false, result
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "http://" + h.pb.Hostname + ":2520/import?domain=" + d.Hostname
|
||||||
|
var msg string
|
||||||
|
var data []byte
|
||||||
|
msg = d.FormatJSON()
|
||||||
|
data = []byte(msg) // Convert the string to []byte
|
||||||
|
req, err := httpPost(url, data)
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Sprintln("error:", err)
|
||||||
|
}
|
||||||
|
log.Info("http post url:", url)
|
||||||
|
log.Info("http post data:", msg)
|
||||||
|
|
||||||
|
result = "EVENT import droplet url: " + url + "\n"
|
||||||
|
result += "EVENT import droplet response: " + string(req)
|
||||||
|
|
||||||
|
// increment the counter for a start attempt working
|
||||||
|
d.Current.StartAttempts += 1
|
||||||
|
|
||||||
|
// mark the cluster as unstable so droplet starts can be throttled
|
||||||
|
me.unstable = time.Now()
|
||||||
|
|
||||||
|
return true, result
|
||||||
|
}
|
||||||
|
|
||||||
|
func postImportDomain(hostname string, name string) ([]byte, error) {
|
||||||
|
url := "http://" + hostname + ":2520/import?domain=" + hostname
|
||||||
|
var msg string
|
||||||
|
var data []byte
|
||||||
|
msg = "import " + name
|
||||||
|
data = []byte(msg) // Convert the string to []byte
|
||||||
|
req, err := httpPost(url, data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return req, nil
|
||||||
}
|
}
|
||||||
|
|
5
poll.go
5
poll.go
|
@ -49,7 +49,7 @@ func (h *HyperT) pollHypervisor() {
|
||||||
log.Log(WARN, name, "local Adding new entry with AddDropletLocal()")
|
log.Log(WARN, name, "local Adding new entry with AddDropletLocal()")
|
||||||
log.Log(WARN, name, "local Adding new entry with AddDropletLocal()")
|
log.Log(WARN, name, "local Adding new entry with AddDropletLocal()")
|
||||||
me.cluster.AddDropletLocal(name, h.pb.Hostname)
|
me.cluster.AddDropletLocal(name, h.pb.Hostname)
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
start := d.SprintHeader()
|
start := d.SprintHeader()
|
||||||
h.lastDroplets[name] = time.Now()
|
h.lastDroplets[name] = time.Now()
|
||||||
|
@ -78,7 +78,8 @@ func (h *HyperT) pollHypervisor() {
|
||||||
|
|
||||||
// this should mean a droplet is running where the config file says it probably should be running
|
// this should mean a droplet is running where the config file says it probably should be running
|
||||||
if d.PreferredHypervisor == h.pb.Hostname {
|
if d.PreferredHypervisor == h.pb.Hostname {
|
||||||
log.Log(EVENT, start, "poll shows new droplet", d.Hostname, "(matches config hypervisor", h.pb.Hostname+")")
|
log.Log(EVENT, start, "poll shows new droplet", d.Hostname,
|
||||||
|
"(matches config hypervisor", h.pb.Hostname+")")
|
||||||
d.Current.Hypervisor = h.pb.Hostname
|
d.Current.Hypervisor = h.pb.Hostname
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue