Generate appvm at start automatically if not exists

This commit is contained in:
Mikhail Klementev 2020-01-02 15:29:20 +00:00
parent 7e4aa33a0a
commit 04b2cf63ce
No known key found for this signature in database
GPG key ID: BE44DA8C062D87DC
2 changed files with 29 additions and 3 deletions

View file

@ -196,9 +196,31 @@ func stupidProgressBar() {
}
}
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}
func isAppvmConfigurationExists(appvmPath, name string) bool {
return fileExists(appvmPath + "/nix/" + name + ".nix")
}
func start(l *libvirt.Libvirt, name string, verbose bool) {
appvmPath := configDir
if !isAppvmConfigurationExists(appvmPath, name) {
log.Println("No configuration exists for app, " +
"trying to generate")
err := generate(l, name, "", "")
if err != nil {
log.Println("Can't auto generate")
return
}
}
// Copy templates
err := prepareTemplates(appvmPath)
if err != nil {