virtigod/start.go

47 lines
1.1 KiB
Go

// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
package main
import (
"errors"
pb "go.wit.com/lib/protobuf/virtbuf"
"go.wit.com/lib/virtigolib"
"go.wit.com/log"
"libvirt.org/go/libvirtxml"
)
func newStart(start string, d *pb.Droplet) error {
if d == nil {
log.Info("log.Info: droplet is unknown:", start)
return errors.New("droplet is unknown: " + start)
}
log.Info("start droplet here:", d.Hostname)
domcfg := &libvirtxml.Domain{}
mergeXML(domcfg, "standard.x86")
// ignore spice if it's not set
if d.SpicePort == 0 {
log.Info("spice port was not set. spice disabled")
} else {
mergeXML(domcfg, "spice")
if err := virtigolib.SetSpicePort(d, domcfg); err != nil {
return err
}
}
mergeXML(domcfg, "qcow")
return virtigolib.GenerateDropletXml(me.dirs, d, domcfg, start)
}
func mergeXML(domcfg *libvirtxml.Domain, filename string) error {
fullname := "resources/xml/" + filename + ".xml"
pfile, err := resources.ReadFile(fullname)
if err != nil {
log.Println("ERROR:", err)
return err
}
return virtigolib.AddDefaultXml(domcfg, string(pfile))
}