start simple xml handling

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-18 07:40:06 -05:00
parent 14dadbcf3c
commit c9ccf688c2
6 changed files with 31 additions and 8 deletions

View File

@ -7,7 +7,7 @@ REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE=
all:
GO111MODULE=off go build -v -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}"
./virtigo --version
./virtigo --hosts farm01 farm02 farm03
# ./virtigo --hosts farm01 farm02 farm03
./virtigo --start jcarr
start-all-droplets:

View File

@ -33,6 +33,7 @@ func (args) Version() string {
var INFO *log.LogFlag
var POLL *log.LogFlag
var WARN *log.LogFlag
var SPEW *log.LogFlag
var EVENT *log.LogFlag
func init() {
@ -41,6 +42,6 @@ func init() {
INFO = log.NewFlag("INFO", false, full, short, "general virtigo")
POLL = log.NewFlag("POLL", false, full, short, "virtigo polling")
WARN = log.NewFlag("WARN", true, full, short, "bad things")
SPEW = log.NewFlag("SPEW", true, full, short, "bad things")
EVENT = log.NewFlag("EVENT", true, full, short, "hypeprvisor/droplet events")
}

View File

@ -52,7 +52,7 @@ func main() {
os.Exit(0)
}
log.Info("start droplet here:", d.Hostname)
makeXml(d)
makeStandardXml(d)
os.Exit(0)
}

View File

@ -1,4 +1,6 @@
<domain type='kvm'>
<name>jcarr</name>
<uuid>c8684902-c405-4f31-b532-128c277056cc</uuid>
<memory unit='GiB'>4</memory>
<vcpu placement='static'>8</vcpu>
</domain>

24
xml.go
View File

@ -10,21 +10,41 @@ import (
"libvirt.org/go/libvirtxml"
)
func makeXml(d *DropletT) {
func makeStandardXml(d *DropletT) {
log.Info("create new xml file for:", d.Hostname)
domcfg := &libvirtxml.Domain{}
addDefaults(domcfg, d.Hostname)
addDefaults(domcfg, "standard.x86")
addDefaults(domcfg, "memory")
addDefaults(domcfg, "network")
addDefaults(domcfg, "spice")
addDefaults(domcfg, "qcow")
addDefaults(domcfg, d.Hostname)
fmt.Printf("Virt type %s\n", domcfg.Type)
fmt.Printf("Virt name %s\n", domcfg.Name)
fmt.Printf("Virt UUID %s\n", domcfg.UUID)
fmt.Printf("Virt Memory %s\n", domcfg.Memory)
// domcfg.Memory = 3333
fmt.Printf("Virt Devices %s\n", domcfg.Devices.Disks)
// log.Spew(domcfg.Devices)
// fmt.Printf("Virt Devices %s\n", domcfg.DiskDriver)
log.Info("DISKS")
log.Info("DISKS")
log.Info("")
// structure DomainDeviceList shows what can be done as a range
for i, x := range domcfg.Devices.Disks {
// Create a new DomainDiskSourceFile struct
newSource := &libvirtxml.DomainDiskSourceFile{
File: "mynew.qcow2", // Set the file name here
}
// Assign it to the disk's source
domcfg.Devices.Disks[i].Source.File = newSource
// fmt.Printf("Disk Source %s\n", name)
fmt.Printf("Disk Device %s\n", x.Source.File)
}
xmldoc, err := domcfg.Marshal()