mirror of
https://code.dumpstack.io/tools/appvm.git
synced 2024-11-27 10:31:31 +00:00
Move out xml template
This commit is contained in:
parent
0823b2f028
commit
e5ccd6d913
74
appvm.go
74
appvm.go
|
@ -30,74 +30,6 @@ import (
|
|||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
var xmlTmpl = `
|
||||
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
||||
<name>%s</name>
|
||||
<memory unit='GiB'>2</memory>
|
||||
<currentMemory unit='GiB'>1</currentMemory>
|
||||
<vcpu>4</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc-i440fx-2.12'>hvm</type>
|
||||
<kernel>%s/kernel</kernel>
|
||||
<initrd>%s/initrd</initrd>
|
||||
<cmdline>loglevel=4 init=%s/init %s</cmdline>
|
||||
</os>
|
||||
<features>
|
||||
<acpi/>
|
||||
</features>
|
||||
<clock offset='utc'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<devices>
|
||||
<!-- Graphical console -->
|
||||
<graphics type='spice' autoport='yes'>
|
||||
<listen type='address'/>
|
||||
<image compression='off'/>
|
||||
</graphics>
|
||||
<!-- Guest additionals support -->
|
||||
<channel type='spicevmc'>
|
||||
<target type='virtio' name='com.redhat.spice.0'/>
|
||||
</channel>
|
||||
<!-- Fake (because -snapshot) writeback image -->
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2' cache='writeback' error_policy='report'/>
|
||||
<source file='%s'/>
|
||||
<target dev='vda' bus='virtio'/>
|
||||
</disk>
|
||||
<video>
|
||||
<model type='qxl' ram='524288' vram='524288' vgamem='262144' heads='1' primary='yes'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
|
||||
</video>
|
||||
<!-- filesystems -->
|
||||
<filesystem type='mount' accessmode='passthrough'>
|
||||
<source dir='/nix/store'/>
|
||||
<target dir='store'/>
|
||||
<readonly/>
|
||||
</filesystem>
|
||||
<filesystem type='mount' accessmode='mapped'>
|
||||
<source dir='%s'/>
|
||||
<target dir='xchg'/> <!-- workaround for nixpkgs/nixos/modules/virtualisation/qemu-vm.nix -->
|
||||
</filesystem>
|
||||
<filesystem type='mount' accessmode='mapped'>
|
||||
<source dir='%s'/>
|
||||
<target dir='shared'/> <!-- workaround for nixpkgs/nixos/modules/virtualisation/qemu-vm.nix -->
|
||||
</filesystem>
|
||||
<filesystem type='mount' accessmode='mapped'>
|
||||
<source dir='%s'/>
|
||||
<target dir='home'/>
|
||||
</filesystem>
|
||||
</devices>
|
||||
<qemu:commandline>
|
||||
<qemu:arg value='-device'/>
|
||||
<qemu:arg value='e1000,netdev=net0'/>
|
||||
<qemu:arg value='-netdev'/>
|
||||
<qemu:arg value='user,id=net0'/>
|
||||
<qemu:arg value='-snapshot'/>
|
||||
</qemu:commandline>
|
||||
</domain>
|
||||
`
|
||||
|
||||
func evalNix(expr string) (s string) {
|
||||
command := exec.Command("nix", "eval", "--raw", expr)
|
||||
bytes, _ := command.Output()
|
||||
|
@ -135,12 +67,6 @@ func getAppVMExpressionPath(name string) string {
|
|||
|
||||
}
|
||||
|
||||
func generateXML(name, vmNixPath, reginfo, img, sharedDir string) string {
|
||||
// TODO: Define XML in go
|
||||
return fmt.Sprintf(xmlTmpl, "appvm_"+name, vmNixPath, vmNixPath, vmNixPath,
|
||||
reginfo, img, sharedDir, sharedDir, sharedDir)
|
||||
}
|
||||
|
||||
func list(l *libvirt.Libvirt) {
|
||||
domains, err := l.Domains()
|
||||
if err != nil {
|
||||
|
|
80
xml.go
Normal file
80
xml.go
Normal file
|
@ -0,0 +1,80 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
// You may think that you want to rewrite to proper golang structures.
|
||||
// Believe me, you shouldn't.
|
||||
|
||||
func generateXML(name, vmNixPath, reginfo, img, sharedDir string) string {
|
||||
// TODO: Define XML in go
|
||||
return fmt.Sprintf(xmlTmpl, "appvm_"+name, vmNixPath, vmNixPath, vmNixPath,
|
||||
reginfo, img, sharedDir, sharedDir, sharedDir)
|
||||
}
|
||||
|
||||
var xmlTmpl = `
|
||||
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
||||
<name>%s</name>
|
||||
<memory unit='GiB'>2</memory>
|
||||
<currentMemory unit='GiB'>1</currentMemory>
|
||||
<vcpu>4</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc-i440fx-2.12'>hvm</type>
|
||||
<kernel>%s/kernel</kernel>
|
||||
<initrd>%s/initrd</initrd>
|
||||
<cmdline>loglevel=4 init=%s/init %s</cmdline>
|
||||
</os>
|
||||
<features>
|
||||
<acpi></acpi>
|
||||
</features>
|
||||
<clock offset='utc'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<devices>
|
||||
<!-- Graphical console -->
|
||||
<graphics type='spice' autoport='yes'>
|
||||
<listen type='address'/>
|
||||
<image compression='off'/>
|
||||
</graphics>
|
||||
<!-- Guest additionals support -->
|
||||
<channel type='spicevmc'>
|
||||
<target type='virtio' name='com.redhat.spice.0'/>
|
||||
</channel>
|
||||
<!-- Fake (because -snapshot) writeback image -->
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2' cache='writeback' error_policy='report'/>
|
||||
<source file='%s'/>
|
||||
<target dev='vda' bus='virtio'/>
|
||||
</disk>
|
||||
<video>
|
||||
<model type='qxl' ram='524288' vram='524288' vgamem='262144' heads='1' primary='yes'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
|
||||
</video>
|
||||
<!-- filesystems -->
|
||||
<filesystem type='mount' accessmode='passthrough'>
|
||||
<source dir='/nix/store'/>
|
||||
<target dir='store'/>
|
||||
<readonly/>
|
||||
</filesystem>
|
||||
<filesystem type='mount' accessmode='mapped'>
|
||||
<source dir='%s'/>
|
||||
<target dir='xchg'/> <!-- workaround for nixpkgs/nixos/modules/virtualisation/qemu-vm.nix -->
|
||||
</filesystem>
|
||||
<filesystem type='mount' accessmode='mapped'>
|
||||
<source dir='%s'/>
|
||||
<target dir='shared'/> <!-- workaround for nixpkgs/nixos/modules/virtualisation/qemu-vm.nix -->
|
||||
</filesystem>
|
||||
<filesystem type='mount' accessmode='mapped'>
|
||||
<source dir='%s'/>
|
||||
<target dir='home'/>
|
||||
</filesystem>
|
||||
</devices>
|
||||
<qemu:commandline>
|
||||
<qemu:arg value='-device'/>
|
||||
<qemu:arg value='e1000,netdev=net0'/>
|
||||
<qemu:arg value='-netdev'/>
|
||||
<qemu:arg value='user,id=net0'/>
|
||||
<qemu:arg value='-snapshot'/>
|
||||
</qemu:commandline>
|
||||
</domain>
|
||||
`
|
Loading…
Reference in a new issue