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) {
|
if !isAppvmConfigurationExists(appvmPath, name) {
|
||||||
log.Println("No configuration exists for app, " +
|
log.Println("No configuration exists for app, " +
|
||||||
"trying to generate")
|
"trying to generate")
|
||||||
err := generate(l, name, "", "")
|
err := generate(name, "", "", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Can't auto generate")
|
log.Println("Can't auto generate")
|
||||||
return
|
return
|
||||||
@ -435,19 +435,6 @@ func main() {
|
|||||||
log.Fatal(err)
|
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")
|
kingpin.Command("list", "List applications")
|
||||||
autoballonCommand := kingpin.Command("autoballoon", "Automatically adjust/reduce app vm memory")
|
autoballonCommand := kingpin.Command("autoballoon", "Automatically adjust/reduce app vm memory")
|
||||||
minMemory := autoballonCommand.Flag("min-memory", "Set minimal memory (megabytes)").Default("1024").Uint64()
|
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()
|
generateName := generateCommand.Arg("name", "Nix package name").Required().String()
|
||||||
generateBin := generateCommand.Arg("bin", "Binary").Default("").String()
|
generateBin := generateCommand.Arg("bin", "Binary").Default("").String()
|
||||||
generateVMName := generateCommand.Flag("vm", "Use VM Name").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")
|
searchCommand := kingpin.Command("search", "Search for application")
|
||||||
searchName := searchCommand.Arg("name", "Application name").Required().String()
|
searchName := searchCommand.Arg("name", "Application name").Required().String()
|
||||||
|
|
||||||
kingpin.Command("sync", "Synchronize remote repos for applications")
|
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() {
|
switch kingpin.Parse() {
|
||||||
case "list":
|
case "list":
|
||||||
list(l)
|
list(l)
|
||||||
case "search":
|
case "search":
|
||||||
search(*searchName)
|
search(*searchName)
|
||||||
case "generate":
|
case "generate":
|
||||||
generate(l, *generateName, *generateBin, *generateVMName)
|
generate(*generateName, *generateBin, *generateVMName,
|
||||||
|
*generateBuildVM)
|
||||||
case "start":
|
case "start":
|
||||||
start(l, *startName,
|
start(l, *startName,
|
||||||
!*startQuiet, !*startOffline, *startStateless,
|
!*startQuiet, !*startOffline, *startStateless,
|
||||||
|
22
generate.go
22
generate.go
@ -8,8 +8,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/digitalocean/go-libvirt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var template = `
|
var template = `
|
||||||
@ -78,7 +76,7 @@ func filterDotfiles(files []os.FileInfo) (notHiddenFiles []os.FileInfo) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func generate(l *libvirt.Libvirt, pkg, bin, vmname string) (err error) {
|
func generate(pkg, bin, vmname string, build bool) (err error) {
|
||||||
// TODO refactor
|
// TODO refactor
|
||||||
var name, channel string
|
var name, channel string
|
||||||
|
|
||||||
@ -190,5 +188,23 @@ func generate(l *libvirt.Libvirt, pkg, bin, vmname string) (err error) {
|
|||||||
|
|
||||||
fmt.Print(appNixConfig + "\n")
|
fmt.Print(appNixConfig + "\n")
|
||||||
log.Println("Configuration file is saved to", appFilename)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user