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