2024-10-31 06:46:16 -05:00
|
|
|
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
|
|
|
|
|
|
|
package virtigolib
|
|
|
|
|
|
|
|
import (
|
2024-11-01 10:22:30 -05:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
2024-10-31 06:46:16 -05:00
|
|
|
"go.wit.com/log"
|
|
|
|
"libvirt.org/go/libvirtxml"
|
|
|
|
)
|
|
|
|
|
2024-11-01 10:22:30 -05:00
|
|
|
// 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)
|
2024-10-31 06:46:16 -05:00
|
|
|
if domcfg == nil {
|
2024-11-01 10:22:30 -05:00
|
|
|
return d, errors.New("domcfg == nil")
|
2024-11-01 04:49:01 -05:00
|
|
|
}
|
2024-10-31 06:46:16 -05:00
|
|
|
|
2024-11-01 10:22:30 -05:00
|
|
|
_, err := MergelibvirtDomain(d, domcfg)
|
2024-10-31 06:46:16 -05:00
|
|
|
if err != nil {
|
2024-11-01 10:22:30 -05:00
|
|
|
return d, errors.New("Merge *libvirt.Domain failed " + domcfg.Name)
|
2024-10-31 06:46:16 -05:00
|
|
|
}
|
|
|
|
s, err := DumpNonStandardXML(domcfg)
|
2024-11-01 10:22:30 -05:00
|
|
|
d.Current.FullXml = s
|
2024-10-31 06:46:16 -05:00
|
|
|
if err != nil {
|
|
|
|
reason := s + "\n"
|
|
|
|
reason = fmt.Sprintln("DumpNonStandardXML() on", domcfg.Name, "failed for", err)
|
2024-11-01 10:22:30 -05:00
|
|
|
log.Warn(reason)
|
|
|
|
return d, err
|
2024-10-31 06:46:16 -05:00
|
|
|
}
|
2024-11-01 10:22:30 -05:00
|
|
|
return d, nil
|
2024-10-31 06:46:16 -05:00
|
|
|
}
|
2024-11-01 06:21:27 -05:00
|
|
|
|
|
|
|
func MergeXml(d *libvirtxml.Domain, xml string) error {
|
|
|
|
err := d.Unmarshal(xml)
|
|
|
|
if err != nil {
|
|
|
|
log.Info("Marshal failed on file", xml)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|