diff --git a/dump.go b/dump.go index 78f125a..7c6e1bd 100644 --- a/dump.go +++ b/dump.go @@ -53,6 +53,13 @@ func dumpDroplets(w http.ResponseWriter, full bool) { fmt.Fprintln(w, header, "(should be on). todo: start() here") continue } + + if d.LocalOnly != "" { + // this is supposed to be ON and needs to be turned on + fmt.Fprintln(w, header, "this libvirt/domain/xml needs to be imported") + continue + } + if full { var filenames string for _, disk := range d.Disks { diff --git a/http.go b/http.go index d3e2df4..875f782 100644 --- a/http.go +++ b/http.go @@ -68,8 +68,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, result) return } - log.Info("virtigo import ends here") - fmt.Fprintln(w, "virtigo import ends here") + log.Info("virtigo import ended here with error = nil") + fmt.Fprintln(w, "virtigo import ends here with error = nil") return } @@ -90,6 +90,20 @@ func okHandler(w http.ResponseWriter, r *http.Request) { return } + if route == "/dumpdroplet" { + hostname := r.URL.Query().Get("hostname") + 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 + } + if route == "/dumpdroplets" { dumpDroplets(w, false) return diff --git a/importDomain.go b/importDomain.go index c50ef60..f71d0b0 100644 --- a/importDomain.go +++ b/importDomain.go @@ -19,8 +19,8 @@ func importDomain(w http.ResponseWriter, r *http.Request) (string, error) { fmt.Fprintln(w, result) return "", errors.New(result) } - log.Warn("name is", name) - fmt.Fprintln(w, "name is", name) + log.Warn("importDomain() START name is", name) + fmt.Fprintln(w, "importDomain() START name is", name) d := me.cluster.FindDropletByName(name) if d == nil { @@ -29,22 +29,43 @@ func importDomain(w http.ResponseWriter, r *http.Request) (string, error) { fmt.Fprintln(w, result) return result, errors.New(result) } - start := fmt.Sprintf("%-9s %-20s", d.Current.Hypervisor, name) - if d.Current.State != pb.DropletState_OFF { - result := "libvirt domain " + name + " found on " + d.Current.Hypervisor - log.Info(result) - fmt.Fprintln(w, result) - } + start := d.SprintHeader() if d.LocalOnly == "" { - result := start + " local duplicate defined (need to resolve this)" + result := start + " LocalOnly is blank. THIS SHOULD NEVER HAPPEN." log.Log(WARN, result) fmt.Fprintln(w, result) - return result, nil + return result, errors.New(result) } - result := start + "about to attempt import " + result := start + " local FOUND! LocalOnly = " + d.LocalOnly + log.Log(WARN, result) + fmt.Fprintln(w, result) + if d.Current.State != pb.DropletState_OFF { + result := "error: libvirt domain " + name + " is not off" + log.Info(result) + fmt.Fprintln(w, 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) + if h == nil { + result = "unknown hypervisor = " + d.Current.Hypervisor + log.Log(WARN, result) + fmt.Fprintln(w, result) + return result, errors.New(result) + } + result = "finally ready to h.start(d)" + log.Log(WARN, result) + fmt.Fprintln(w, result) return result, nil + + ok, output := h.start(d) + if ok { + return result + output, nil + } + return result + output, errors.New("start " + name + " on hypervisor " + h.pb.Hostname) } diff --git a/poll.go b/poll.go index 87bd4f3..46313eb 100644 --- a/poll.go +++ b/poll.go @@ -11,6 +11,15 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" ) +func findHypervisorByName(name string) *HyperT { + for _, h := range me.hypers { + if h.pb.Hostname == name { + return h + } + } + return nil +} + func (h *HyperT) pollHypervisor() { url := "http://" + h.pb.Hostname + ":2520/vms" log.Log(POLL, "wget url =", url)