summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-18 06:00:05 -0500
committerJeff Carr <[email protected]>2024-10-18 06:00:05 -0500
commit14dadbcf3ce8d732354d2c4ef30f3374f80950f9 (patch)
tree73babb209f97782673ee640d538d1cada64fde00
parentf5fb6736f60947ad493a0eac17b468177aa40139 (diff)
write out xml file for virsh create (maybe?)
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--Makefile1
-rw-r--r--main.go5
-rw-r--r--resources/xml/go.wit.com.xml191
-rw-r--r--resources/xml/jcarr.xml4
-rw-r--r--resources/xml/memory.xml4
-rw-r--r--resources/xml/network.xml10
-rw-r--r--resources/xml/qcow.xml11
-rw-r--r--resources/xml/spice.xml9
-rw-r--r--resources/xml/standard.x86.xml173
-rw-r--r--xml.go58
10 files changed, 464 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index a954867..8450c66 100644
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,7 @@ all:
GO111MODULE=off go build -v -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}"
./virtigo --version
./virtigo --hosts farm01 farm02 farm03
+ ./virtigo --start jcarr
start-all-droplets:
curl --silent http://localhost:8080/start?start=git.wit.org
diff --git a/main.go b/main.go
index 671c935..1c62669 100644
--- a/main.go
+++ b/main.go
@@ -49,9 +49,10 @@ func main() {
d := findDroplet(argv.Start)
if d == nil {
log.Info("droplet is unknown:", argv.Start)
- } else {
- log.Info("start droplet here:", d.Hostname)
+ os.Exit(0)
}
+ log.Info("start droplet here:", d.Hostname)
+ makeXml(d)
os.Exit(0)
}
diff --git a/resources/xml/go.wit.com.xml b/resources/xml/go.wit.com.xml
new file mode 100644
index 0000000..b4f7bbc
--- /dev/null
+++ b/resources/xml/go.wit.com.xml
@@ -0,0 +1,191 @@
+<domain type='kvm'>
+ <name>go.wit.com</name>
+ <uuid>9e795cd7-7142-4757-bef2-f607b4f9944f</uuid>
+ <metadata>
+ <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
+ <libosinfo:os id="http://debian.org/debian/12"/>
+ </libosinfo:libosinfo>
+ </metadata>
+ <memory unit='KiB'>2097152</memory>
+ <currentMemory unit='KiB'>2097152</currentMemory>
+ <vcpu placement='static'>2</vcpu>
+ <resource>
+ <partition>/machine</partition>
+ </resource>
+ <os>
+ <type arch='x86_64' machine='pc-q35-9.0'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <features>
+ <acpi/>
+ <apic/>
+ <vmport state='off'/>
+ </features>
+ <cpu mode='host-passthrough' check='none' migratable='on'/>
+ <clock offset='utc'>
+ <timer name='rtc' tickpolicy='catchup'/>
+ <timer name='pit' tickpolicy='delay'/>
+ <timer name='hpet' present='no'/>
+ </clock>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <pm>
+ <suspend-to-mem enabled='no'/>
+ <suspend-to-disk enabled='no'/>
+ </pm>
+ <devices>
+ <emulator>/usr/bin/qemu-system-x86_64</emulator>
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='qcow2' />
+ <source file='/home/go.wit.com.qcow2'/>
+ <backingStore/>
+ <target dev='sda' bus='sata'/>
+ <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+ </disk>
+ <controller type='usb' index='0' model='qemu-xhci' ports='15'>
+ <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
+ </controller>
+ <controller type='pci' index='0' model='pcie-root'/>
+ <controller type='pci' index='1' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='1' port='0x10'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0' multifunction='on'/>
+ </controller>
+ <controller type='pci' index='2' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='2' port='0x11'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x1'/>
+ </controller>
+ <controller type='pci' index='3' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='3' port='0x12'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x2'/>
+ </controller>
+ <controller type='pci' index='4' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='4' port='0x13'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x3'/>
+ </controller>
+ <controller type='pci' index='5' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='5' port='0x14'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x4'/>
+ </controller>
+ <controller type='pci' index='6' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='6' port='0x15'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x5'/>
+ </controller>
+ <controller type='pci' index='7' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='7' port='0x16'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x6'/>
+ </controller>
+ <controller type='pci' index='8' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='8' port='0x17'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x7'/>
+ </controller>
+ <controller type='pci' index='9' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='9' port='0x18'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0' multifunction='on'/>
+ </controller>
+ <controller type='pci' index='10' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='10' port='0x19'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x1'/>
+ </controller>
+ <controller type='pci' index='11' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='11' port='0x1a'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x2'/>
+ </controller>
+ <controller type='pci' index='12' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='12' port='0x1b'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x3'/>
+ </controller>
+ <controller type='pci' index='13' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='13' port='0x1c'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x4'/>
+ </controller>
+ <controller type='pci' index='14' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='14' port='0x1d'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x5'/>
+ </controller>
+ <controller type='pci' index='15' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='15' port='0x1e'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x6'/>
+ </controller>
+ <controller type='pci' index='16' model='pcie-to-pci-bridge'>
+ <model name='pcie-pci-bridge'/>
+ <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
+ </controller>
+ <controller type='sata' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
+ </controller>
+ <controller type='virtio-serial' index='0'>
+ <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
+ </controller>
+ <controller type='scsi' index='0' model='lsilogic'>
+ <address type='pci' domain='0x0000' bus='0x10' slot='0x01' function='0x0'/>
+ </controller>
+ <interface type='bridge'>
+ <mac address='22:22:22:22:22:22'/>
+ <source bridge='worldbr'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
+ </interface>
+ <serial type='pty'>
+ <target type='isa-serial' port='0'>
+ <model name='isa-serial'/>
+ </target>
+ </serial>
+ <console type='pty'>
+ <target type='serial' port='0'/>
+ </console>
+ <channel type='unix'>
+ <target type='virtio' name='org.qemu.guest_agent.0'/>
+ <address type='virtio-serial' controller='0' bus='0' port='1'/>
+ </channel>
+ <channel type='spicevmc'>
+ <target type='virtio' name='com.redhat.spice.0'/>
+ <address type='virtio-serial' controller='0' bus='0' port='2'/>
+ </channel>
+ <input type='tablet' bus='usb'>
+ <address type='usb' bus='0' port='1'/>
+ </input>
+ <input type='mouse' bus='ps2'/>
+ <graphics type='spice' autoport='yes'>
+ <listen type='address'/>
+ <image compression='off'/>
+ </graphics>
+ <sound model='ich9'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x1b' function='0x0'/>
+ </sound>
+ <video>
+ <model type='virtio' heads='1' primary='yes'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
+ </video>
+ <redirdev bus='usb' type='spicevmc'>
+ <address type='usb' bus='0' port='2'/>
+ </redirdev>
+ <redirdev bus='usb' type='spicevmc'>
+ <address type='usb' bus='0' port='3'/>
+ </redirdev>
+ <memballoon model='virtio'>
+ <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
+ </memballoon>
+ <rng model='virtio'>
+ <backend model='random'>/dev/urandom</backend>
+ <address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/>
+ </rng>
+ </devices>
+ <seclabel type='dynamic' model='apparmor' relabel='yes'/>
+</domain>
+
diff --git a/resources/xml/jcarr.xml b/resources/xml/jcarr.xml
new file mode 100644
index 0000000..0e55c25
--- /dev/null
+++ b/resources/xml/jcarr.xml
@@ -0,0 +1,4 @@
+<domain type='kvm'>
+ <name>jcarr</name>
+ <uuid>c8684902-c405-4f31-b532-128c277056cc</uuid>
+</domain>
diff --git a/resources/xml/memory.xml b/resources/xml/memory.xml
new file mode 100644
index 0000000..5a5447e
--- /dev/null
+++ b/resources/xml/memory.xml
@@ -0,0 +1,4 @@
+<domain type='kvm'>
+ <memory unit='MiB'>2048</memory>
+ <vcpu placement='static'>4</vcpu>
+</domain>
diff --git a/resources/xml/network.xml b/resources/xml/network.xml
new file mode 100644
index 0000000..1be01d8
--- /dev/null
+++ b/resources/xml/network.xml
@@ -0,0 +1,10 @@
+<domain type='kvm'>
+ <devices>
+ <interface type='bridge'>
+ <mac address='22:22:22:22:22:22'/>
+ <source bridge='worldbr'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
+ </interface>
+ </devices>
+</domain>
diff --git a/resources/xml/qcow.xml b/resources/xml/qcow.xml
new file mode 100644
index 0000000..a131c7f
--- /dev/null
+++ b/resources/xml/qcow.xml
@@ -0,0 +1,11 @@
+<domain type='kvm'>
+ <devices>
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='qcow2' />
+ <source file='/home/nfs/blank.qcow2'/>
+ <backingStore/>
+ <target dev='sda' bus='sata'/>
+ <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+ </disk>
+ </devices>
+</domain>
diff --git a/resources/xml/spice.xml b/resources/xml/spice.xml
new file mode 100644
index 0000000..07a27a2
--- /dev/null
+++ b/resources/xml/spice.xml
@@ -0,0 +1,9 @@
+<domain type='kvm' id='2'>
+ <devices>
+ <graphics type='spice' port='5900' autoport='no' listen='0.0.0.0'>
+ <listen type='address' address='0.0.0.0'/>
+ <image compression='off'/>
+ </graphics>
+ </devices>
+</domain>
+
diff --git a/resources/xml/standard.x86.xml b/resources/xml/standard.x86.xml
new file mode 100644
index 0000000..7256cbc
--- /dev/null
+++ b/resources/xml/standard.x86.xml
@@ -0,0 +1,173 @@
+<domain type='kvm'>
+ <metadata>
+ <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
+ <libosinfo:os id="http://debian.org/debian/12"/>
+ </libosinfo:libosinfo>
+ </metadata>
+ <resource>
+ <partition>/machine</partition>
+ </resource>
+ <os>
+ <type arch='x86_64' machine='pc-q35-9.0'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <features>
+ <acpi/>
+ <apic/>
+ <vmport state='off'/>
+ </features>
+ <cpu mode='host-passthrough' check='none' migratable='on'/>
+ <clock offset='utc'>
+ <timer name='rtc' tickpolicy='catchup'/>
+ <timer name='pit' tickpolicy='delay'/>
+ <timer name='hpet' present='no'/>
+ </clock>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <pm>
+ <suspend-to-mem enabled='no'/>
+ <suspend-to-disk enabled='no'/>
+ </pm>
+ <devices>
+ <emulator>/usr/bin/qemu-system-x86_64</emulator>
+ <controller type='usb' index='0' model='qemu-xhci' ports='15'>
+ <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
+ </controller>
+ <controller type='pci' index='0' model='pcie-root'/>
+ <controller type='pci' index='1' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='1' port='0x10'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0' multifunction='on'/>
+ </controller>
+ <controller type='pci' index='2' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='2' port='0x11'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x1'/>
+ </controller>
+ <controller type='pci' index='3' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='3' port='0x12'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x2'/>
+ </controller>
+ <controller type='pci' index='4' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='4' port='0x13'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x3'/>
+ </controller>
+ <controller type='pci' index='5' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='5' port='0x14'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x4'/>
+ </controller>
+ <controller type='pci' index='6' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='6' port='0x15'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x5'/>
+ </controller>
+ <controller type='pci' index='7' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='7' port='0x16'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x6'/>
+ </controller>
+ <controller type='pci' index='8' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='8' port='0x17'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x7'/>
+ </controller>
+ <controller type='pci' index='9' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='9' port='0x18'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0' multifunction='on'/>
+ </controller>
+ <controller type='pci' index='10' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='10' port='0x19'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x1'/>
+ </controller>
+ <controller type='pci' index='11' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='11' port='0x1a'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x2'/>
+ </controller>
+ <controller type='pci' index='12' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='12' port='0x1b'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x3'/>
+ </controller>
+ <controller type='pci' index='13' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='13' port='0x1c'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x4'/>
+ </controller>
+ <controller type='pci' index='14' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='14' port='0x1d'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x5'/>
+ </controller>
+ <controller type='pci' index='15' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='15' port='0x1e'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x6'/>
+ </controller>
+ <controller type='pci' index='16' model='pcie-to-pci-bridge'>
+ <model name='pcie-pci-bridge'/>
+ <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
+ </controller>
+ <controller type='sata' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
+ </controller>
+ <controller type='virtio-serial' index='0'>
+ <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
+ </controller>
+ <controller type='scsi' index='0' model='lsilogic'>
+ <address type='pci' domain='0x0000' bus='0x10' slot='0x01' function='0x0'/>
+ </controller>
+ <serial type='pty'>
+ <target type='isa-serial' port='0'>
+ <model name='isa-serial'/>
+ </target>
+ </serial>
+ <console type='pty'>
+ <target type='serial' port='0'/>
+ </console>
+ <channel type='unix'>
+ <target type='virtio' name='org.qemu.guest_agent.0'/>
+ <address type='virtio-serial' controller='0' bus='0' port='1'/>
+ </channel>
+ <channel type='spicevmc'>
+ <target type='virtio' name='com.redhat.spice.0'/>
+ <address type='virtio-serial' controller='0' bus='0' port='2'/>
+ </channel>
+ <input type='tablet' bus='usb'>
+ <address type='usb' bus='0' port='1'/>
+ </input>
+ <input type='mouse' bus='ps2'/>
+ <graphics type='spice' autoport='yes'>
+ <listen type='address'/>
+ <image compression='off'/>
+ </graphics>
+ <sound model='ich9'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x1b' function='0x0'/>
+ </sound>
+ <video>
+ <model type='virtio' heads='1' primary='yes'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
+ </video>
+ <redirdev bus='usb' type='spicevmc'>
+ <address type='usb' bus='0' port='2'/>
+ </redirdev>
+ <redirdev bus='usb' type='spicevmc'>
+ <address type='usb' bus='0' port='3'/>
+ </redirdev>
+ <memballoon model='virtio'>
+ <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
+ </memballoon>
+ <rng model='virtio'>
+ <backend model='random'>/dev/urandom</backend>
+ <address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/>
+ </rng>
+ </devices>
+ <seclabel type='dynamic' model='apparmor' relabel='yes'/>
+</domain>
+
diff --git a/xml.go b/xml.go
new file mode 100644
index 0000000..2b1e7bb
--- /dev/null
+++ b/xml.go
@@ -0,0 +1,58 @@
+// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
+
+package main
+
+import (
+ "fmt"
+ "os"
+
+ "go.wit.com/log"
+ "libvirt.org/go/libvirtxml"
+)
+
+func makeXml(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")
+
+ 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)
+
+ xmldoc, err := domcfg.Marshal()
+
+ if err != nil {
+ fmt.Println("can't make xml file error:\n", err)
+ return
+ }
+
+ // fmt.Printf("Virt type %s\n", xmldoc)
+
+ outfile := "/tmp/" + d.Hostname + ".xml"
+ regfile, _ := os.OpenFile(outfile, os.O_RDWR|os.O_CREATE, 0666)
+ fmt.Fprintln(regfile, xmldoc)
+
+ log.Info("File is in", outfile)
+}
+
+func addDefaults(d *libvirtxml.Domain, filename string) {
+ fullname := "resources/xml/" + filename + ".xml"
+ pfile, err := resources.ReadFile(fullname)
+ if err != nil {
+ log.Println("ERROR:", err)
+ return
+ }
+
+ err = d.Unmarshal(string(pfile))
+ if err != nil {
+ log.Info("Marshal failed on file", filename)
+ return
+ }
+}