rename to virtigolib
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
cc092bd895
commit
a345a813d8
50
http.go
50
http.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -8,8 +9,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.wit.com/lib/gui/shell"
|
"go.wit.com/lib/gui/shell"
|
||||||
|
"go.wit.com/lib/virtigolib"
|
||||||
pb "go.wit.com/lib/protobuf/virtbuf"
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
"libvirt.org/go/libvirtxml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// remove '?' part and trailing '/'
|
// remove '?' part and trailing '/'
|
||||||
|
@ -53,11 +56,37 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if tmp == "/vms" {
|
if tmp == "/vms" {
|
||||||
s := pollHypervisor(hv)
|
s := pollHypervisor(me.hv)
|
||||||
fmt.Fprint(w, s)
|
fmt.Fprint(w, s)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tmp == "/import" {
|
||||||
|
domname := r.URL.Query().Get("import")
|
||||||
|
fmt.Fprint(w, "import domain:", domname)
|
||||||
|
|
||||||
|
xmldoc, err := virshDumpXML(w, r, domname)
|
||||||
|
|
||||||
|
domcfg := &libvirtxml.Domain{}
|
||||||
|
err = domcfg.Unmarshal(xmldoc)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(w, "domain.Unmarshal XML failed")
|
||||||
|
fmt.Fprintln(w, "error =", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// importDomain(w, r, domcfg)
|
||||||
|
// importDomain(w http.ResponseWriter, r *http.Request, dom *libvirtxml.Domain) {
|
||||||
|
d, _, err := virtigolib.ImportXML(domcfg)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(w, "ImportXML failed for", domname, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Fprintln(w, "ImportXML worked for", domname)
|
||||||
|
fmt.Fprintln(w, "should send the protobuf to virtigo here", domname)
|
||||||
|
d.Current.FullXml = xmldoc
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if tmp == "/cluster" {
|
if tmp == "/cluster" {
|
||||||
log.Info("/cluster jcarr actually doing START")
|
log.Info("/cluster jcarr actually doing START")
|
||||||
fmt.Fprintln(w, "/cluster jcarr actually doing START")
|
fmt.Fprintln(w, "/cluster jcarr actually doing START")
|
||||||
|
@ -201,3 +230,22 @@ func startHTTP() {
|
||||||
log.Println("Error starting server:", err)
|
log.Println("Error starting server:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func virshDumpXML(w http.ResponseWriter, r *http.Request, name string) (string, error) {
|
||||||
|
cmd := []string{"virsh", "dumpxml", "--security-info", name}
|
||||||
|
|
||||||
|
fmt.Fprintln(w, "virsh dumpxml", name)
|
||||||
|
log.Warn("cmd :", cmd)
|
||||||
|
fmt.Fprintln(w, "cmd: ", cmd)
|
||||||
|
err, ok, output := shell.RunCmd("/home/", cmd)
|
||||||
|
shell.Run(cmd)
|
||||||
|
if !ok {
|
||||||
|
fmt.Fprintln(w, "START FAILED", me.Hostname)
|
||||||
|
fmt.Fprintln(w, "error =", err)
|
||||||
|
result := fmt.Sprintln("virsh dumpxml failed:", err)
|
||||||
|
return output, errors.New(result)
|
||||||
|
}
|
||||||
|
fmt.Fprintln(w, "START OK", me.Hostname)
|
||||||
|
fmt.Fprintln(w, output)
|
||||||
|
return output, nil
|
||||||
|
}
|
||||||
|
|
|
@ -76,35 +76,3 @@ func pollHypervisor(hv *hypervisor.Hypervisor) string {
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func displayBlockDevices(domain *qemu.Domain) {
|
|
||||||
// var []blks string
|
|
||||||
blockDevices, err := domain.BlockDevices()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Error getting blockDevices: %v\n", blockDevices)
|
|
||||||
}
|
|
||||||
fmt.Printf("\n[ BlockDevices ]\n")
|
|
||||||
fmt.Printf("========================================================================\n")
|
|
||||||
fmt.Printf("%20s %8s %30s\n", "Device", "Driver", "File")
|
|
||||||
fmt.Printf("========================================================================\n")
|
|
||||||
for _, blockDevice := range blockDevices {
|
|
||||||
fmt.Printf("%20s %8s %30s\n",
|
|
||||||
blockDevice.Device, blockDevice.Inserted.Driver, blockDevice.Inserted.File)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func displayPCIDevices(domain *qemu.Domain) {
|
|
||||||
pciDevices, err := domain.PCIDevices()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Error getting PCIDevices: %v\n", pciDevices)
|
|
||||||
}
|
|
||||||
fmt.Printf("\n[ PCIDevices ]\n")
|
|
||||||
fmt.Printf("======================================\n")
|
|
||||||
fmt.Printf("%10s %20s\n", "[ID]", "[Description]")
|
|
||||||
fmt.Printf("======================================\n")
|
|
||||||
for _, pciDevice := range pciDevices {
|
|
||||||
fmt.Printf("[%10s] [%20s]\n", pciDevice.QdevID, pciDevice.ClassInfo.Desc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
7
main.go
7
main.go
|
@ -26,7 +26,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version string
|
var Version string
|
||||||
var hv *hypervisor.Hypervisor
|
|
||||||
|
|
||||||
//go:embed resources/*
|
//go:embed resources/*
|
||||||
var resources embed.FS
|
var resources embed.FS
|
||||||
|
@ -46,15 +45,15 @@ func main() {
|
||||||
|
|
||||||
// fmt.Printf("\nConnecting to %s://%s\n", *network, *address)
|
// fmt.Printf("\nConnecting to %s://%s\n", *network, *address)
|
||||||
newConn := func() (net.Conn, error) {
|
newConn := func() (net.Conn, error) {
|
||||||
|
// return net.DialTimeout("tcp", "hyper02:16514", *timeout)
|
||||||
// return net.DialTimeout(*network, *address, *timeout)
|
// return net.DialTimeout(*network, *address, *timeout)
|
||||||
return net.DialTimeout("unix", "/var/run/libvirt/libvirt-sock", 2*time.Second)
|
return net.DialTimeout("unix", "/var/run/libvirt/libvirt-sock", 2*time.Second)
|
||||||
// return net.DialTimeout("tcp", "farm02:16514", *timeout)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
driver := hypervisor.NewRPCDriver(newConn)
|
driver := hypervisor.NewRPCDriver(newConn)
|
||||||
hv = hypervisor.New(driver)
|
me.hv = hypervisor.New(driver)
|
||||||
|
|
||||||
pollHypervisor(hv)
|
pollHypervisor(me.hv)
|
||||||
|
|
||||||
startHTTP()
|
startHTTP()
|
||||||
}
|
}
|
||||||
|
|
8
start.go
8
start.go
|
@ -6,7 +6,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
pb "go.wit.com/lib/protobuf/virtbuf"
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
||||||
"go.wit.com/lib/virtigoxml"
|
"go.wit.com/lib/virtigolib"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
"libvirt.org/go/libvirtxml"
|
"libvirt.org/go/libvirtxml"
|
||||||
)
|
)
|
||||||
|
@ -25,13 +25,13 @@ func newStart(start string, d *pb.Droplet) error {
|
||||||
log.Info("spice port was not set. spice disabled")
|
log.Info("spice port was not set. spice disabled")
|
||||||
} else {
|
} else {
|
||||||
mergeXML(domcfg, "spice")
|
mergeXML(domcfg, "spice")
|
||||||
if err := virtigoxml.SetSpicePort(d, domcfg); err != nil {
|
if err := virtigolib.SetSpicePort(d, domcfg); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mergeXML(domcfg, "qcow")
|
mergeXML(domcfg, "qcow")
|
||||||
|
|
||||||
return virtigoxml.GenerateDropletXml(me.dirs, d, domcfg, start)
|
return virtigolib.GenerateDropletXml(me.dirs, d, domcfg, start)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeXML(domcfg *libvirtxml.Domain, filename string) error {
|
func mergeXML(domcfg *libvirtxml.Domain, filename string) error {
|
||||||
|
@ -42,5 +42,5 @@ func mergeXML(domcfg *libvirtxml.Domain, filename string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return virtigoxml.AddDefaultXml(domcfg, string(pfile))
|
return virtigolib.AddDefaultXml(domcfg, string(pfile))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "github.com/digitalocean/go-qemu/hypervisor"
|
||||||
|
|
||||||
var me *Virtigod
|
var me *Virtigod
|
||||||
|
|
||||||
// this app's variables
|
// this app's variables
|
||||||
type Virtigod struct {
|
type Virtigod struct {
|
||||||
Hostname string
|
Hostname string
|
||||||
dirs []string
|
dirs []string
|
||||||
|
hv *hypervisor.Hypervisor
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue