change name to virtigolib
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
5c3543864d
commit
2ab607246e
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
||||||
|
|
||||||
package virtigoxml
|
package virtigolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
@ -27,7 +27,7 @@ func AddDomainDroplet(cluster *pb.Cluster, domcfg *libvirtxml.Domain) (*pb.Dropl
|
||||||
if d == nil {
|
if d == nil {
|
||||||
d = cluster.AddDroplet(domcfg.UUID, domcfg.Name, 2, 2*1024*1024)
|
d = cluster.AddDroplet(domcfg.UUID, domcfg.Name, 2, 2*1024*1024)
|
||||||
d.StartState = pb.DropletState_OFF
|
d.StartState = pb.DropletState_OFF
|
||||||
d.CurrentState = pb.DropletState_UNKNOWN
|
d.Current.State = pb.DropletState_UNKNOWN
|
||||||
|
|
||||||
// if the domcfg doesn't have a uuid, make a new one here
|
// if the domcfg doesn't have a uuid, make a new one here
|
||||||
if d.Uuid == "" {
|
if d.Uuid == "" {
|
||||||
|
@ -36,7 +36,7 @@ func AddDomainDroplet(cluster *pb.Cluster, domcfg *libvirtxml.Domain) (*pb.Dropl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
alle, err = updateDroplet(cluster, d, domcfg)
|
alle, err = updateDroplet(d, domcfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("updateDroplet() failed for", d.Hostname)
|
log.Info("updateDroplet() failed for", d.Hostname)
|
||||||
return d, alle, errors.New("update failed for " + domcfg.Name)
|
return d, alle, errors.New("update failed for " + domcfg.Name)
|
||||||
|
@ -85,7 +85,7 @@ func findDomain(c *pb.Cluster, domcfg *libvirtxml.Domain) (*pb.Droplet, error) {
|
||||||
return found, nil
|
return found, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateDroplet(cluster *pb.Cluster, d *pb.Droplet, domcfg *libvirtxml.Domain) ([]*pb.Event, error) {
|
func updateDroplet(d *pb.Droplet, domcfg *libvirtxml.Domain) ([]*pb.Event, error) {
|
||||||
var alle []*pb.Event
|
var alle []*pb.Event
|
||||||
|
|
||||||
if d == nil {
|
if d == nil {
|
||||||
|
@ -108,10 +108,10 @@ func updateDroplet(cluster *pb.Cluster, d *pb.Droplet, domcfg *libvirtxml.Domain
|
||||||
if (domcfg.OS != nil) && (domcfg.OS.Type != nil) {
|
if (domcfg.OS != nil) && (domcfg.OS.Type != nil) {
|
||||||
// OS Type: &{Arch:x86_64 Machine:pc-i440fx-5.2 Type:hvm}
|
// OS Type: &{Arch:x86_64 Machine:pc-i440fx-5.2 Type:hvm}
|
||||||
t := domcfg.OS.Type
|
t := domcfg.OS.Type
|
||||||
if d.QemuArch != t.Arch {
|
if d.PreferredArch != t.Arch {
|
||||||
e := d.NewChangeEvent("Droplet.QemuArch", d.QemuArch, t.Arch)
|
e := d.NewChangeEvent("Droplet.QemuArch", d.PreferredArch, t.Arch)
|
||||||
alle = append(alle, e)
|
alle = append(alle, e)
|
||||||
d.QemuArch = t.Arch
|
d.PreferredArch = t.Arch
|
||||||
}
|
}
|
||||||
if d.QemuMachine != t.Machine {
|
if d.QemuMachine != t.Machine {
|
||||||
e := d.NewChangeEvent("Droplet.QemuMachine", d.QemuMachine, t.Machine)
|
e := d.NewChangeEvent("Droplet.QemuMachine", d.QemuMachine, t.Machine)
|
||||||
|
@ -156,7 +156,7 @@ func updateDroplet(cluster *pb.Cluster, d *pb.Droplet, domcfg *libvirtxml.Domain
|
||||||
return alle, errors.New("not kvm")
|
return alle, errors.New("not kvm")
|
||||||
}
|
}
|
||||||
|
|
||||||
nete, err := updateNetwork(cluster, d, domcfg)
|
nete, err := updateNetwork(d, domcfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("updateNetwork() failed", err)
|
log.Info("updateNetwork() failed", err)
|
||||||
return alle, err
|
return alle, err
|
||||||
|
@ -166,7 +166,7 @@ func updateDroplet(cluster *pb.Cluster, d *pb.Droplet, domcfg *libvirtxml.Domain
|
||||||
alle = append(alle, e)
|
alle = append(alle, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
nete, err = updateDisk(cluster, d, domcfg)
|
nete, err = updateDisk(d, domcfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return alle, err
|
return alle, err
|
||||||
}
|
}
|
||||||
|
@ -180,11 +180,6 @@ func updateDroplet(cluster *pb.Cluster, d *pb.Droplet, domcfg *libvirtxml.Domain
|
||||||
return alle, nil
|
return alle, nil
|
||||||
}
|
}
|
||||||
log.Info("libvirt xml import worked. droplet changed", domcfg.Name)
|
log.Info("libvirt xml import worked. droplet changed", domcfg.Name)
|
||||||
|
|
||||||
// append each change event
|
|
||||||
for _, e := range alle {
|
|
||||||
cluster.E.Events = append(cluster.E.Events, e)
|
|
||||||
}
|
|
||||||
return alle, nil
|
return alle, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +214,7 @@ func updateMemory(d *pb.Droplet, domcfg *libvirtxml.Domain) (*pb.Event, error) {
|
||||||
return e, nil
|
return e, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateNetwork(cluster *pb.Cluster, d *pb.Droplet, domcfg *libvirtxml.Domain) ([]*pb.Event, error) {
|
func updateNetwork(d *pb.Droplet, domcfg *libvirtxml.Domain) ([]*pb.Event, error) {
|
||||||
var allEvents []*pb.Event
|
var allEvents []*pb.Event
|
||||||
if (d == nil) || (domcfg == nil) {
|
if (d == nil) || (domcfg == nil) {
|
||||||
return nil, errors.New("domcfg == nil")
|
return nil, errors.New("domcfg == nil")
|
||||||
|
@ -343,7 +338,7 @@ func updateNetwork(cluster *pb.Cluster, d *pb.Droplet, domcfg *libvirtxml.Domain
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// returns false if something went wrong
|
// returns false if something went wrong
|
||||||
func updateDisk(cluster *pb.Cluster, d *pb.Droplet, domcfg *libvirtxml.Domain) ([]*pb.Event, error) {
|
func updateDisk(d *pb.Droplet, domcfg *libvirtxml.Domain) ([]*pb.Event, error) {
|
||||||
var alle []*pb.Event
|
var alle []*pb.Event
|
||||||
|
|
||||||
if (d == nil) || (domcfg == nil) {
|
if (d == nil) || (domcfg == nil) {
|
||||||
|
|
2
disks.go
2
disks.go
|
@ -1,4 +1,4 @@
|
||||||
package virtigoxml
|
package virtigolib
|
||||||
|
|
||||||
/*
|
/*
|
||||||
makes a droplet hard disk record
|
makes a droplet hard disk record
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
// there might be something interesting in a VM
|
// there might be something interesting in a VM
|
||||||
// 'standard' here means what I think is standard
|
// 'standard' here means what I think is standard
|
||||||
|
|
||||||
package virtigoxml
|
package virtigolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
||||||
|
|
||||||
|
package virtigolib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
||||||
|
"go.wit.com/log"
|
||||||
|
"libvirt.org/go/libvirtxml"
|
||||||
|
)
|
||||||
|
|
||||||
|
// import a libvirt xml domain
|
||||||
|
func ImportXML(domcfg *libvirtxml.Domain) (*pb.Droplet, []*pb.Event, error) {
|
||||||
|
var alle []*pb.Event
|
||||||
|
var d *pb.Droplet
|
||||||
|
if domcfg == nil {
|
||||||
|
return nil, alle, errors.New("domcfg == nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
d = new(pb.Droplet)
|
||||||
|
d.Hostname = domcfg.Name
|
||||||
|
d.Uuid = domcfg.UUID
|
||||||
|
d.StartState = pb.DropletState_OFF
|
||||||
|
d.Current.State = pb.DropletState_UNKNOWN
|
||||||
|
|
||||||
|
alle, err := updateDroplet(d, domcfg)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("updateDroplet() failed for", d.Hostname)
|
||||||
|
return d, alle, errors.New("update failed for " + domcfg.Name)
|
||||||
|
}
|
||||||
|
log.Info("added new droplet", domcfg.Name, domcfg.UUID)
|
||||||
|
s, err := DumpNonStandardXML(domcfg)
|
||||||
|
if err != nil {
|
||||||
|
reason := s + "\n"
|
||||||
|
reason = fmt.Sprintln("DumpNonStandardXML() on", domcfg.Name, "failed for", err)
|
||||||
|
log.Info(reason)
|
||||||
|
return d, alle, errors.New(reason)
|
||||||
|
}
|
||||||
|
return d, alle, nil
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
||||||
|
|
||||||
package virtigoxml
|
package virtigolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
|
2
spice.go
2
spice.go
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
||||||
|
|
||||||
package virtigoxml
|
package virtigolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
Loading…
Reference in New Issue