mirror of
https://code.dumpstack.io/tools/appvm.git
synced 2024-11-23 16:41:29 +00:00
Add flag for build vm to appvm generate
This commit is contained in:
parent
4ce1c5643f
commit
88718323f0
39
appvm.go
39
appvm.go
|
@ -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,
|
||||
|
|
22
generate.go
22
generate.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue