diff options
| author | Jeff Carr <[email protected]> | 2024-11-01 11:17:52 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-01 11:17:52 -0500 |
| commit | 301fe567e2318c318c073226475f83941e5da6be (patch) | |
| tree | 7fd545d73597a705d4560669c0661347e9ac7114 /importDomain.go | |
| parent | 2c1c3482fe6b55cf8142e1ad9b2aab5813e44c44 (diff) | |
getting down to the nitty gritty
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'importDomain.go')
| -rw-r--r-- | importDomain.go | 36 |
1 files changed, 17 insertions, 19 deletions
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 = "" |
