2024-10-26 10:34:04 -05:00
|
|
|
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-10-26 12:32:37 -05:00
|
|
|
"errors"
|
2024-10-26 10:34:04 -05:00
|
|
|
|
2024-10-26 19:34:32 -05:00
|
|
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
2024-10-31 06:50:17 -05:00
|
|
|
"go.wit.com/lib/virtigolib"
|
2024-10-26 10:34:04 -05:00
|
|
|
"go.wit.com/log"
|
|
|
|
"libvirt.org/go/libvirtxml"
|
|
|
|
)
|
|
|
|
|
2024-10-26 19:34:32 -05:00
|
|
|
func newStart(start string, d *pb.Droplet) error {
|
2024-10-26 10:34:04 -05:00
|
|
|
if d == nil {
|
2024-10-26 20:09:33 -05:00
|
|
|
log.Info("log.Info: droplet is unknown:", start)
|
2024-10-26 12:32:37 -05:00
|
|
|
return errors.New("droplet is unknown: " + start)
|
2024-10-26 10:34:04 -05:00
|
|
|
}
|
|
|
|
log.Info("start droplet here:", d.Hostname)
|
|
|
|
domcfg := &libvirtxml.Domain{}
|
|
|
|
|
2024-10-26 21:02:05 -05:00
|
|
|
mergeXML(domcfg, "standard.x86")
|
2024-10-27 05:43:01 -05:00
|
|
|
// ignore spice if it's not set
|
|
|
|
if d.SpicePort == 0 {
|
|
|
|
log.Info("spice port was not set. spice disabled")
|
|
|
|
} else {
|
|
|
|
mergeXML(domcfg, "spice")
|
2024-10-31 06:50:17 -05:00
|
|
|
if err := virtigolib.SetSpicePort(d, domcfg); err != nil {
|
2024-10-27 05:43:01 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2024-10-26 21:02:05 -05:00
|
|
|
mergeXML(domcfg, "qcow")
|
2024-10-26 10:34:04 -05:00
|
|
|
|
2024-10-31 06:50:17 -05:00
|
|
|
return virtigolib.GenerateDropletXml(me.dirs, d, domcfg, start)
|
2024-10-26 10:34:04 -05:00
|
|
|
}
|
|
|
|
|
2024-10-26 21:02:05 -05:00
|
|
|
func mergeXML(domcfg *libvirtxml.Domain, filename string) error {
|
2024-10-26 10:34:04 -05:00
|
|
|
fullname := "resources/xml/" + filename + ".xml"
|
|
|
|
pfile, err := resources.ReadFile(fullname)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("ERROR:", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-10-31 06:50:17 -05:00
|
|
|
return virtigolib.AddDefaultXml(domcfg, string(pfile))
|
2024-10-26 10:34:04 -05:00
|
|
|
}
|