import worked

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-01 08:31:13 -05:00
parent 53a88a1c5c
commit eab1a35ca5
3 changed files with 43 additions and 15 deletions

View File

@ -36,7 +36,7 @@ func AddDomainDroplet(cluster *pb.NewCluster, domcfg *libvirtxml.Domain) (*pb.Dr
} }
} }
alle, err = updateDroplet(d, domcfg) alle, err = MergelibvirtDomain(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)
@ -87,7 +87,8 @@ func findDomain(c *pb.NewCluster, domcfg *libvirtxml.Domain) (*pb.Droplet, error
return found, nil return found, nil
} }
func updateDroplet(d *pb.Droplet, domcfg *libvirtxml.Domain) ([]*pb.Event, error) { // merges and updates the droplet protobuf based on the libvirt XML
func MergelibvirtDomain(d *pb.Droplet, domcfg *libvirtxml.Domain) ([]*pb.Event, error) {
var alle []*pb.Event var alle []*pb.Event
if d == nil { if d == nil {

View File

@ -475,5 +475,36 @@ func DumpNonStandardXML(domcfg *libvirtxml.Domain) (string, error) {
domcfg.Devices.Videos = nil domcfg.Devices.Videos = nil
} }
var normalAudio bool = true
if domcfg.Devices.Audios != nil {
for _, a := range domcfg.Devices.Audios {
if a.SPICE != nil {
// nothing to do for this
} else {
fmt.Printf("? Audio: %+v\n", a)
normalAudio = false
}
}
}
if normalAudio {
domcfg.Devices.Audios = nil
}
var normalWatchdog bool = true
if domcfg.Devices.Watchdogs != nil {
for _, dog := range domcfg.Devices.Watchdogs {
// fmt.Printf("? Watchdog: %+v\n", dog)
if dog.Model == "itco" {
// nothing to do for this
} else {
fmt.Printf("? Watchdog: %+v\n", dog)
normalWatchdog = false
}
}
}
if normalWatchdog {
domcfg.Devices.Watchdogs = nil
}
return finalEmptyCheck(domcfg) return finalEmptyCheck(domcfg)
} }

View File

@ -3,32 +3,27 @@
package virtigolib package virtigolib
import ( import (
"errors"
"fmt"
pb "go.wit.com/lib/protobuf/virtbuf"
"go.wit.com/log" "go.wit.com/log"
"libvirt.org/go/libvirtxml" "libvirt.org/go/libvirtxml"
) )
// import a libvirt xml domain // import a libvirt xml domain
func ImportXML(domcfg *libvirtxml.Domain) (*pb.Droplet, []*pb.Event, error) { /*
func badImportXML(domcfg *libvirtxml.Domain) (*pb.Droplet, []*pb.Event, error) {
var alle []*pb.Event var alle []*pb.Event
var d *pb.Droplet var d *pb.Droplet
if domcfg == nil { if domcfg == nil {
return nil, alle, errors.New("domcfg == nil") return nil, alle, errors.New("domcfg == nil")
} }
d = new(pb.Droplet) d, err = c.InitDroplet(domcfg.Name)
d.Hostname = domcfg.Name if err != nil {
d.Uuid = domcfg.UUID // use merge instead
d.StartState = pb.DropletState_OFF os.Exit(-1)
if d.Current == nil {
d.Current = new(pb.Current)
} }
d.Current.State = pb.DropletState_UNKNOWN d.Uuid = domcfg.UUID
alle, err := updateDroplet(d, domcfg) alle, err := MergelibvirtDomain(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)
@ -43,6 +38,7 @@ func ImportXML(domcfg *libvirtxml.Domain) (*pb.Droplet, []*pb.Event, error) {
} }
return d, alle, nil return d, alle, nil
} }
*/
func MergeXml(d *libvirtxml.Domain, xml string) error { func MergeXml(d *libvirtxml.Domain, xml string) error {
err := d.Unmarshal(xml) err := d.Unmarshal(xml)