From eab1a35ca532d8e938bb1599de84c00e3dc85843 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 1 Nov 2024 08:31:13 -0500 Subject: [PATCH] import worked Signed-off-by: Jeff Carr --- addDroplet.go | 5 +++-- dumpNonStandardXML.go | 31 +++++++++++++++++++++++++++++++ importXML.go | 22 +++++++++------------- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/addDroplet.go b/addDroplet.go index 6a4285e..db786a5 100644 --- a/addDroplet.go +++ b/addDroplet.go @@ -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 { log.Info("updateDroplet() failed for", d.Hostname) 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 } -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 if d == nil { diff --git a/dumpNonStandardXML.go b/dumpNonStandardXML.go index e92d44b..3feba22 100644 --- a/dumpNonStandardXML.go +++ b/dumpNonStandardXML.go @@ -475,5 +475,36 @@ func DumpNonStandardXML(domcfg *libvirtxml.Domain) (string, error) { 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) } diff --git a/importXML.go b/importXML.go index ec665fe..e1425ce 100644 --- a/importXML.go +++ b/importXML.go @@ -3,32 +3,27 @@ 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) { +/* +func badImportXML(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 - if d.Current == nil { - d.Current = new(pb.Current) + d, err = c.InitDroplet(domcfg.Name) + if err != nil { + // use merge instead + os.Exit(-1) } - d.Current.State = pb.DropletState_UNKNOWN + d.Uuid = domcfg.UUID - alle, err := updateDroplet(d, domcfg) + alle, err := MergelibvirtDomain(d, domcfg) if err != nil { log.Info("updateDroplet() failed for", d.Hostname) 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 } +*/ func MergeXml(d *libvirtxml.Domain, xml string) error { err := d.Unmarshal(xml)