Add --cli
switch that disables the GUI window. (#20)
This commit is contained in:
parent
a583335865
commit
e588479701
17
appvm.go
17
appvm.go
@ -173,14 +173,14 @@ func isRunning(l *libvirt.Libvirt, name string) bool {
|
|||||||
|
|
||||||
func generateAppVM(l *libvirt.Libvirt,
|
func generateAppVM(l *libvirt.Libvirt,
|
||||||
nixName, vmName, appvmPath, sharedDir string,
|
nixName, vmName, appvmPath, sharedDir string,
|
||||||
verbose, online bool) (err error) {
|
verbose, online, gui bool) (err error) {
|
||||||
|
|
||||||
realpath, reginfo, qcow2, err := generateVM(appvmPath, nixName, verbose)
|
realpath, reginfo, qcow2, err := generateVM(appvmPath, nixName, verbose)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
xml := generateXML(vmName, online, realpath, reginfo, qcow2, sharedDir)
|
xml := generateXML(vmName, online, gui, realpath, reginfo, qcow2, sharedDir)
|
||||||
_, err = l.DomainCreateXML(xml, libvirt.DomainStartValidate)
|
_, err = l.DomainCreateXML(xml, libvirt.DomainStartValidate)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -209,7 +209,7 @@ func isAppvmConfigurationExists(appvmPath, name string) bool {
|
|||||||
return fileExists(appvmPath + "/nix/" + name + ".nix")
|
return fileExists(appvmPath + "/nix/" + name + ".nix")
|
||||||
}
|
}
|
||||||
|
|
||||||
func start(l *libvirt.Libvirt, name string, verbose, online, stateless bool,
|
func start(l *libvirt.Libvirt, name string, verbose, online, gui, stateless bool,
|
||||||
args, open string) {
|
args, open string) {
|
||||||
|
|
||||||
appvmPath := configDir
|
appvmPath := configDir
|
||||||
@ -267,14 +267,16 @@ func start(l *libvirt.Libvirt, name string, verbose, online, stateless bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := generateAppVM(l, name, vmName, appvmPath, sharedDir,
|
err := generateAppVM(l, name, vmName, appvmPath, sharedDir,
|
||||||
verbose, online)
|
verbose, online, gui)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("virt-viewer", "-c", "qemu:///system", vmName)
|
if gui {
|
||||||
cmd.Start()
|
cmd := exec.Command("virt-viewer", "-c", "qemu:///system", vmName)
|
||||||
|
cmd.Start()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func stop(l *libvirt.Libvirt, name string) {
|
func stop(l *libvirt.Libvirt, name string) {
|
||||||
@ -450,6 +452,7 @@ func main() {
|
|||||||
startArgs := startCommand.Flag("args", "Command line arguments").String()
|
startArgs := startCommand.Flag("args", "Command line arguments").String()
|
||||||
startOpen := startCommand.Flag("open", "Pass file to application").String()
|
startOpen := startCommand.Flag("open", "Pass file to application").String()
|
||||||
startOffline := startCommand.Flag("offline", "Disconnect").Bool()
|
startOffline := startCommand.Flag("offline", "Disconnect").Bool()
|
||||||
|
startCli := startCommand.Flag("cli", "Disable graphics mode, enable serial").Bool()
|
||||||
startStateless := startCommand.Flag("stateless", "Do not use default state directory").Bool()
|
startStateless := startCommand.Flag("stateless", "Do not use default state directory").Bool()
|
||||||
|
|
||||||
stopName := kingpin.Command("stop", "Stop application").Arg("name", "Application name").Required().String()
|
stopName := kingpin.Command("stop", "Stop application").Arg("name", "Application name").Required().String()
|
||||||
@ -496,7 +499,7 @@ func main() {
|
|||||||
*generateBuildVM)
|
*generateBuildVM)
|
||||||
case "start":
|
case "start":
|
||||||
start(l, *startName,
|
start(l, *startName,
|
||||||
!*startQuiet, !*startOffline, *startStateless,
|
!*startQuiet, !*startOffline, !*startCli, *startStateless,
|
||||||
*startArgs, *startOpen)
|
*startArgs, *startOpen)
|
||||||
case "stop":
|
case "stop":
|
||||||
stop(l, *stopName)
|
stop(l, *stopName)
|
||||||
|
40
xml.go
40
xml.go
@ -5,9 +5,15 @@ import "fmt"
|
|||||||
// You may think that you want to rewrite to proper golang structures.
|
// You may think that you want to rewrite to proper golang structures.
|
||||||
// Believe me, you shouldn't.
|
// Believe me, you shouldn't.
|
||||||
|
|
||||||
func generateXML(vmName string, online bool,
|
func generateXML(vmName string, online, gui bool,
|
||||||
vmNixPath, reginfo, img, sharedDir string) string {
|
vmNixPath, reginfo, img, sharedDir string) string {
|
||||||
|
|
||||||
|
devices := ""
|
||||||
|
|
||||||
|
if gui {
|
||||||
|
devices = guiDevices
|
||||||
|
}
|
||||||
|
|
||||||
qemuParams := `
|
qemuParams := `
|
||||||
<qemu:commandline>
|
<qemu:commandline>
|
||||||
<qemu:arg value='-device'/>
|
<qemu:arg value='-device'/>
|
||||||
@ -27,9 +33,25 @@ func generateXML(vmName string, online bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf(xmlTmpl, vmName, vmNixPath, vmNixPath, vmNixPath,
|
return fmt.Sprintf(xmlTmpl, vmName, vmNixPath, vmNixPath, vmNixPath,
|
||||||
reginfo, img, sharedDir, sharedDir, sharedDir, qemuParams)
|
reginfo, img, sharedDir, sharedDir, sharedDir, devices, qemuParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var guiDevices = `
|
||||||
|
<!-- 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>
|
||||||
|
<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>
|
||||||
|
`
|
||||||
|
|
||||||
var xmlTmpl = `
|
var xmlTmpl = `
|
||||||
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
||||||
<name>%s</name>
|
<name>%s</name>
|
||||||
@ -50,25 +72,12 @@ var xmlTmpl = `
|
|||||||
<on_reboot>restart</on_reboot>
|
<on_reboot>restart</on_reboot>
|
||||||
<on_crash>destroy</on_crash>
|
<on_crash>destroy</on_crash>
|
||||||
<devices>
|
<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 -->
|
<!-- Fake (because -snapshot) writeback image -->
|
||||||
<disk type='file' device='disk'>
|
<disk type='file' device='disk'>
|
||||||
<driver name='qemu' type='qcow2' cache='writeback' error_policy='report'/>
|
<driver name='qemu' type='qcow2' cache='writeback' error_policy='report'/>
|
||||||
<source file='%s'/>
|
<source file='%s'/>
|
||||||
<target dev='vda' bus='virtio'/>
|
<target dev='vda' bus='virtio'/>
|
||||||
</disk>
|
</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 -->
|
<!-- filesystems -->
|
||||||
<filesystem type='mount' accessmode='passthrough'>
|
<filesystem type='mount' accessmode='passthrough'>
|
||||||
<source dir='/nix/store'/>
|
<source dir='/nix/store'/>
|
||||||
@ -87,6 +96,7 @@ var xmlTmpl = `
|
|||||||
<source dir='%s'/>
|
<source dir='%s'/>
|
||||||
<target dir='home'/>
|
<target dir='home'/>
|
||||||
</filesystem>
|
</filesystem>
|
||||||
|
%s
|
||||||
</devices>
|
</devices>
|
||||||
%s
|
%s
|
||||||
</domain>
|
</domain>
|
||||||
|
Loading…
Reference in New Issue
Block a user