Add flag for build vm to appvm generate

This commit is contained in:
dump_stack() 2020-01-09 22:59:45 +00:00
parent 4ce1c5643f
commit 88718323f0
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 43 additions and 18 deletions

View File

@ -254,7 +254,7 @@ func start(l *libvirt.Libvirt, name string, verbose, online, stateless bool,
if !isAppvmConfigurationExists(appvmPath, name) {
log.Println("No configuration exists for app, " +
"trying to generate")
err := generate(l, name, "", "")
err := generate(name, "", "", false)
if err != nil {
log.Println("Can't auto generate")
return
@ -435,19 +435,6 @@ func main() {
log.Fatal(err)
}
c, err := net.DialTimeout("unix", "/var/run/libvirt/libvirt-sock", time.Second)
if err != nil {
log.Fatal(err)
}
l := libvirt.New(c)
if err := l.Connect(); err != nil {
log.Fatal(err)
}
defer l.Disconnect()
cleanupStatelessVMs(l)
kingpin.Command("list", "List applications")
autoballonCommand := kingpin.Command("autoballoon", "Automatically adjust/reduce app vm memory")
minMemory := autoballonCommand.Flag("min-memory", "Set minimal memory (megabytes)").Default("1024").Uint64()
@ -468,19 +455,41 @@ func main() {
generateName := generateCommand.Arg("name", "Nix package name").Required().String()
generateBin := generateCommand.Arg("bin", "Binary").Default("").String()
generateVMName := generateCommand.Flag("vm", "Use VM Name").Default("").String()
generateBuildVM := generateCommand.Flag("build", "Build VM").Bool()
searchCommand := kingpin.Command("search", "Search for application")
searchName := searchCommand.Arg("name", "Application name").Required().String()
kingpin.Command("sync", "Synchronize remote repos for applications")
var l *libvirt.Libvirt
if kingpin.Parse() != "generate" {
c, err := net.DialTimeout(
"unix",
"/var/run/libvirt/libvirt-sock",
time.Second,
)
if err != nil {
log.Fatal(err)
}
l = libvirt.New(c)
if err := l.Connect(); err != nil {
log.Fatal(err)
}
defer l.Disconnect()
cleanupStatelessVMs(l)
}
switch kingpin.Parse() {
case "list":
list(l)
case "search":
search(*searchName)
case "generate":
generate(l, *generateName, *generateBin, *generateVMName)
generate(*generateName, *generateBin, *generateVMName,
*generateBuildVM)
case "start":
start(l, *startName,
!*startQuiet, !*startOffline, *startStateless,

View File

@ -8,8 +8,6 @@ import (
"os"
"os/exec"
"strings"
"github.com/digitalocean/go-libvirt"
)
var template = `
@ -78,7 +76,7 @@ func filterDotfiles(files []os.FileInfo) (notHiddenFiles []os.FileInfo) {
return
}
func generate(l *libvirt.Libvirt, pkg, bin, vmname string) (err error) {
func generate(pkg, bin, vmname string, build bool) (err error) {
// TODO refactor
var name, channel string
@ -190,5 +188,23 @@ func generate(l *libvirt.Libvirt, pkg, bin, vmname string) (err error) {
fmt.Print(appNixConfig + "\n")
log.Println("Configuration file is saved to", appFilename)
if build {
err = os.Chdir(configDir)
if err != nil {
return
}
if vmname != "" {
_, _, _, err = generateVM(vmname, true)
} else {
_, _, _, err = generateVM(name, true)
}
if err != nil {
return
}
}
return
}