ready for import local domain request to hypervisors

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-31 15:43:25 -05:00
parent b4ef8b76b1
commit b28ae96cd4
3 changed files with 44 additions and 5 deletions

View File

@ -60,7 +60,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
if route == "/import" { if route == "/import" {
log.Info("virtigo import starts here") log.Info("virtigo import starts here")
fmt.Fprintln(w, "virtigo import starts here") fmt.Fprintln(w, "virtigo import starts here")
result, err := create(w, r) result, err := importDomain(w, r)
if err != nil { if err != nil {
log.Info("virtigo import failed") log.Info("virtigo import failed")
log.Info(result) log.Info(result)

35
importDomain.go Normal file
View File

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

12
poll.go
View File

@ -36,11 +36,15 @@ func (h *HyperT) pollHypervisor() {
if state == "OFF" { if state == "OFF" {
d := me.cluster.FindDropletByName(name) d := me.cluster.FindDropletByName(name)
if d == nil { if d == nil {
log.Log(WARN, "locally defined:", h.pb.Hostname, fields, "not imported") log.Log(WARN, "locally defined domain:", h.pb.Hostname, fields)
} else { log.Log(WARN, "neeed to add a local droplet protobuf")
log.Log(WARN, "locally defined:", h.pb.Hostname, fields, d.Hostname) 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 continue
} }
h.lastDroplets[name] = time.Now() h.lastDroplets[name] = time.Now()