mirror of
https://code.dumpstack.io/tools/appvm.git
synced 2024-11-23 16:41:29 +00:00
Generate appvm at start automatically if not exists
This commit is contained in:
parent
7e4aa33a0a
commit
04b2cf63ce
22
appvm.go
22
appvm.go
|
@ -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 {
|
||||
|
|
10
generate.go
10
generate.go
|
@ -71,7 +71,7 @@ func filterDotfiles(files []os.FileInfo) (notHiddenFiles []os.FileInfo) {
|
|||
return
|
||||
}
|
||||
|
||||
func generate(l *libvirt.Libvirt, pkg, bin, vmname string) {
|
||||
func generate(l *libvirt.Libvirt, pkg, bin, vmname string) (err error) {
|
||||
var name string
|
||||
|
||||
if strings.Contains(pkg, ".") {
|
||||
|
@ -79,7 +79,8 @@ func generate(l *libvirt.Libvirt, pkg, bin, vmname string) {
|
|||
} else {
|
||||
log.Println("Package name does not contains channel")
|
||||
log.Println("Trying to guess")
|
||||
channel, err := guessChannel()
|
||||
var channel string
|
||||
channel, err = guessChannel()
|
||||
if err != nil {
|
||||
log.Println("Cannot guess channel")
|
||||
log.Println("Check nix-channel --list")
|
||||
|
@ -91,7 +92,9 @@ func generate(l *libvirt.Libvirt, pkg, bin, vmname string) {
|
|||
}
|
||||
|
||||
if !isPackageExists(name) {
|
||||
log.Println("Package", name, "does not exists")
|
||||
s := "Package " + name + " does not exists"
|
||||
err = errors.New(s)
|
||||
log.Println(s)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -177,4 +180,5 @@ func generate(l *libvirt.Libvirt, pkg, bin, vmname string) {
|
|||
|
||||
fmt.Print(appNixConfig + "\n")
|
||||
log.Println("Configuration file is saved to", appFilename)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue