From 301fe567e2318c318c073226475f83941e5da6be Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 1 Nov 2024 11:17:52 -0500 Subject: [PATCH] getting down to the nitty gritty Signed-off-by: Jeff Carr --- http.go | 4 ++-- importDomain.go | 36 +++++++++++++++++------------------- poll.go | 1 + 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/http.go b/http.go index 727bc99..363ab71 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 ended here with error = nil") - fmt.Fprintln(w, "virtigo import ends here with error = nil") + log.Info("virtigo import worked") + fmt.Fprintln(w, "virtigo import worked") return } diff --git a/importDomain.go b/importDomain.go index 9e55f6b..50dfd90 100644 --- a/importDomain.go +++ b/importDomain.go @@ -18,9 +18,10 @@ import ( // attempts to import the *libvirt.Domain directly from the hypervisor func importDomain(w http.ResponseWriter, r *http.Request) (string, error) { + var result string domainName := r.URL.Query().Get("domainName") if domainName == "" { - result := "importDomain() failed. name is blank " + r.URL.Path + result = "importDomain() failed. name is blank " + r.URL.Path log.Warn(result) fmt.Fprintln(w, result) return "", errors.New(result) @@ -29,7 +30,7 @@ func importDomain(w http.ResponseWriter, r *http.Request) (string, error) { // a LocalOnly record should already have been created by hypervisor.Poll() d := me.cluster.FindDropletByName(domainName) if d == nil { - result := "libvirt domain " + domainName + " could not be found on any hypervisor" + result = "libvirt domain " + domainName + " could not be found on any hypervisor" log.Info(result) fmt.Fprintln(w, result) return result, errors.New(result) @@ -37,7 +38,7 @@ func importDomain(w http.ResponseWriter, r *http.Request) (string, error) { // if it's not local only, don't attempt this for now if d.LocalOnly == "" { - result := "LocalOnly is blank. SKIP. merge not supported yet." + result = "LocalOnly is blank. SKIP. merge not supported yet." log.Log(WARN, result) fmt.Fprintln(w, result) return result, errors.New(result) @@ -56,7 +57,7 @@ func importDomain(w http.ResponseWriter, r *http.Request) (string, error) { // get the hypervisor record for what it's worth h := findHypervisorByName(d.Current.Hypervisor) if h == nil { - result := "unknown hypervisor = " + d.Current.Hypervisor + result = "unknown hypervisor = " + d.Current.Hypervisor log.Log(WARN, result) fmt.Fprintln(w, result) return result, errors.New(result) @@ -65,40 +66,37 @@ func importDomain(w http.ResponseWriter, r *http.Request) (string, error) { // exports and builds a libvirt.Domain from the hypervisor domcfg, err := ExportLibvirtDomain(h.pb, domainName) if err != nil { - reason := fmt.Sprintf("ExportLibvirtDomain() failed", err) - log.Warn(reason) - fmt.Fprintln(w, reason) + result = fmt.Sprintf("ExportLibvirtDomain() failed", err) + log.Warn(result) + fmt.Fprintln(w, result) return "", err } // merges and updates the droplet protobuf based on the libvirt XML events, err := virtigolib.MergelibvirtDomain(d, domcfg) if err != nil { - reason := fmt.Sprintf("MerglibvirtDomain() failed for", d.Hostname, err) - log.Warn(reason) - fmt.Fprintln(w, reason) - return "", errors.New(reason) + result = fmt.Sprintf("MerglibvirtDomain() failed for", d.Hostname, err) + log.Warn(result) + fmt.Fprintln(w, result) + return "", errors.New(result) } // check what was non-standard and make a note of it. Save it in the protobuf s, err := virtigolib.DumpNonStandardXML(domcfg) if err != nil { - reason := s + "\n" - reason = fmt.Sprintln("DumpNonStandardXML() on", domcfg.Name, "failed for", err) - log.Info(reason) + result = s + "\n" + result = fmt.Sprintln("DumpNonStandardXML() on", domcfg.Name, "failed for", err) + log.Info(result) return "", err } - if s != "" { - log.Warn("bad XML:", s) - os.Exit(0) - } + result += s // everything worked. add the events for _, e := range events { me.cluster.AddEvent(e) } - result := fmt.Sprintln("importDomain() worked") + result += fmt.Sprintln("importDomain() worked") // remote LocalOnly flag d.LocalOnly = "" diff --git a/poll.go b/poll.go index b575889..4051356 100644 --- a/poll.go +++ b/poll.go @@ -123,6 +123,7 @@ func (h *HyperT) pollHypervisor() { } if d.Current.State == pb.DropletState_OFF { log.Info(header, "droplet timed out and is off. remove from h.lastDroplets[] slice") + delete(h.lastDroplets, name) continue }