From b28ae96cd4c2801968ed883814b83357b77ed144 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 31 Oct 2024 15:43:25 -0500 Subject: [PATCH] ready for import local domain request to hypervisors Signed-off-by: Jeff Carr --- http.go | 2 +- importDomain.go | 35 +++++++++++++++++++++++++++++++++++ poll.go | 12 ++++++++---- 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 importDomain.go diff --git a/http.go b/http.go index fb697ff..d3e2df4 100644 --- a/http.go +++ b/http.go @@ -60,7 +60,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) { if route == "/import" { log.Info("virtigo import starts here") fmt.Fprintln(w, "virtigo import starts here") - result, err := create(w, r) + result, err := importDomain(w, r) if err != nil { log.Info("virtigo import failed") log.Info(result) diff --git a/importDomain.go b/importDomain.go new file mode 100644 index 0000000..59c6398 --- /dev/null +++ b/importDomain.go @@ -0,0 +1,35 @@ +package main + +import ( + "errors" + "fmt" + "net/http" + + "go.wit.com/log" +) + +// attempts to create a new virtual machine + +func importDomain(w http.ResponseWriter, r *http.Request) (string, error) { + name := r.URL.Query().Get("domainName") + if name == "" { + result := "start failed. name is blank " + r.URL.Path + log.Warn(result) + fmt.Fprintln(w, result) + return "", errors.New(result) + } + log.Warn("name is", name) + fmt.Fprintln(w, "name is", name) + + d := me.cluster.FindDropletByName(name) + if d == nil { + result := "libvirt domain " + name + " could not be found on any hypervisor" + log.Info(result) + fmt.Fprintln(w, result) + return result, errors.New(result) + } + result := "libvirt domain " + name + " found on " + d.Current.Hypervisor + log.Info(result) + fmt.Fprintln(w, result) + return result, nil +} diff --git a/poll.go b/poll.go index 8a0727c..4f225db 100644 --- a/poll.go +++ b/poll.go @@ -36,11 +36,15 @@ func (h *HyperT) pollHypervisor() { if state == "OFF" { d := me.cluster.FindDropletByName(name) if d == nil { - log.Log(WARN, "locally defined:", h.pb.Hostname, fields, "not imported") - } else { - log.Log(WARN, "locally defined:", h.pb.Hostname, fields, d.Hostname) + log.Log(WARN, "locally defined domain:", h.pb.Hostname, fields) + log.Log(WARN, "neeed to add a local droplet protobuf") + me.cluster.AddDropletLocal(name, h.pb.Hostname) + return } - // skip locally defined libvirt vms + if d.LocalOnly == "" { + log.Log(WARN, "ready to import", d.Hostname, "from", h.pb.Hostname) + } + log.Log(WARN, "duplicate local droplet", h.pb.Hostname, fields, "need to resolve this") continue } h.lastDroplets[name] = time.Now()