getting down to the nitty gritty

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-01 11:17:52 -05:00
parent 2c1c3482fe
commit 301fe567e2
3 changed files with 20 additions and 21 deletions

View File

@ -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
}

View File

@ -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 = ""

View File

@ -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
}