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) fmt.Fprintln(w, result)
return return
} }
log.Info("virtigo import ended here with error = nil") log.Info("virtigo import worked")
fmt.Fprintln(w, "virtigo import ends here with error = nil") fmt.Fprintln(w, "virtigo import worked")
return return
} }

View File

@ -18,9 +18,10 @@ import (
// attempts to import the *libvirt.Domain directly from the hypervisor // attempts to import the *libvirt.Domain directly from the hypervisor
func importDomain(w http.ResponseWriter, r *http.Request) (string, error) { func importDomain(w http.ResponseWriter, r *http.Request) (string, error) {
var result string
domainName := r.URL.Query().Get("domainName") domainName := r.URL.Query().Get("domainName")
if domainName == "" { if domainName == "" {
result := "importDomain() 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)
@ -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() // a LocalOnly record should already have been created by hypervisor.Poll()
d := me.cluster.FindDropletByName(domainName) d := me.cluster.FindDropletByName(domainName)
if d == nil { 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) log.Info(result)
fmt.Fprintln(w, result) fmt.Fprintln(w, result)
return result, errors.New(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 it's not local only, don't attempt this for now
if d.LocalOnly == "" { 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) log.Log(WARN, result)
fmt.Fprintln(w, result) fmt.Fprintln(w, result)
return result, errors.New(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 // get the hypervisor record for what it's worth
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)
@ -65,40 +66,37 @@ func importDomain(w http.ResponseWriter, r *http.Request) (string, error) {
// exports and builds a libvirt.Domain from the hypervisor // exports and builds a libvirt.Domain from the hypervisor
domcfg, err := ExportLibvirtDomain(h.pb, domainName) domcfg, err := ExportLibvirtDomain(h.pb, domainName)
if err != nil { if err != nil {
reason := fmt.Sprintf("ExportLibvirtDomain() failed", err) result = fmt.Sprintf("ExportLibvirtDomain() failed", err)
log.Warn(reason) log.Warn(result)
fmt.Fprintln(w, reason) fmt.Fprintln(w, result)
return "", err return "", err
} }
// merges and updates the droplet protobuf based on the libvirt XML // merges and updates the droplet protobuf based on the libvirt XML
events, err := virtigolib.MergelibvirtDomain(d, domcfg) events, err := virtigolib.MergelibvirtDomain(d, domcfg)
if err != nil { if err != nil {
reason := fmt.Sprintf("MerglibvirtDomain() failed for", d.Hostname, err) result = fmt.Sprintf("MerglibvirtDomain() failed for", d.Hostname, err)
log.Warn(reason) log.Warn(result)
fmt.Fprintln(w, reason) fmt.Fprintln(w, result)
return "", errors.New(reason) return "", errors.New(result)
} }
// check what was non-standard and make a note of it. Save it in the protobuf // check what was non-standard and make a note of it. Save it in the protobuf
s, err := virtigolib.DumpNonStandardXML(domcfg) s, err := virtigolib.DumpNonStandardXML(domcfg)
if err != nil { if err != nil {
reason := s + "\n" result = s + "\n"
reason = fmt.Sprintln("DumpNonStandardXML() on", domcfg.Name, "failed for", err) result = fmt.Sprintln("DumpNonStandardXML() on", domcfg.Name, "failed for", err)
log.Info(reason) log.Info(result)
return "", err return "", err
} }
if s != "" { result += s
log.Warn("bad XML:", s)
os.Exit(0)
}
// everything worked. add the events // everything worked. add the events
for _, e := range events { for _, e := range events {
me.cluster.AddEvent(e) me.cluster.AddEvent(e)
} }
result := fmt.Sprintln("importDomain() worked") result += fmt.Sprintln("importDomain() worked")
// remote LocalOnly flag // remote LocalOnly flag
d.LocalOnly = "" d.LocalOnly = ""

View File

@ -123,6 +123,7 @@ func (h *HyperT) pollHypervisor() {
} }
if d.Current.State == pb.DropletState_OFF { if d.Current.State == pb.DropletState_OFF {
log.Info(header, "droplet timed out and is off. remove from h.lastDroplets[] slice") log.Info(header, "droplet timed out and is off. remove from h.lastDroplets[] slice")
delete(h.lastDroplets, name)
continue continue
} }