44 lines
941 B
Go
44 lines
941 B
Go
// 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"
|
|
)
|
|
|
|
// do a test import of a libvirt xml domain
|
|
func TestLibvirtDomain(domcfg *libvirtxml.Domain) (*pb.Droplet, error) {
|
|
d := new(pb.Droplet)
|
|
d.Current = new(pb.Current)
|
|
if domcfg == nil {
|
|
return d, errors.New("domcfg == nil")
|
|
}
|
|
|
|
_, err := MergelibvirtDomain(d, domcfg)
|
|
if err != nil {
|
|
return d, errors.New("Merge *libvirt.Domain failed " + domcfg.Name)
|
|
}
|
|
s, err := DumpNonStandardXML(domcfg)
|
|
d.Current.FullXml = s
|
|
if err != nil {
|
|
reason := s + "\n"
|
|
reason = fmt.Sprintln("DumpNonStandardXML() on", domcfg.Name, "failed for", err)
|
|
log.Warn(reason)
|
|
return d, err
|
|
}
|
|
return d, nil
|
|
}
|
|
|
|
func MergeXml(d *libvirtxml.Domain, xml string) error {
|
|
err := d.Unmarshal(xml)
|
|
if err != nil {
|
|
log.Info("Marshal failed on file", xml)
|
|
}
|
|
return err
|
|
}
|