2024-10-31 06:46:16 -05:00
|
|
|
// 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
|
2024-11-01 04:49:01 -05:00
|
|
|
if d.Current == nil {
|
|
|
|
d.Current = new(pb.Current)
|
|
|
|
}
|
2024-10-31 06:46:16 -05:00
|
|
|
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
|
|
|
|
}
|