Skip to content

Instantly share code, notes, and snippets.

@influx6
Created May 28, 2015 20:53
Show Gist options
  • Save influx6/e1f36f047b049cd6b779 to your computer and use it in GitHub Desktop.
Save influx6/e1f36f047b049cd6b779 to your computer and use it in GitHub Desktop.
lxc container
package main
import (
"flag"
"log"
"gopkg.in/lxc/go-lxc.v2"
"fmt"
)
var (
lxcpath string
template string
name string
)
func init() {
flag.StringVar(&lxcpath, "lxcpath", lxc.DefaultConfigPath(), "Use specified container path")
flag.StringVar(&template, "template", "busybox", "Template to use")
flag.StringVar(&name, "name", "rubik", "Name of the container")
flag.Parse()
}
func main() {
log.Printf("Creating new container %s from template %s", name, template)
c1, err := lxc.NewContainer(template)
if err != nil {
fmt.Println(err)
return
}
if (!c1.Defined()) {
fmt.Println("C1 not defined")
}
name := "test2"
err = c1.Clone(name, lxc.CloneOptions{Backend: lxc.Aufs, Snapshot: true, KeepName: true})
if err != nil {
fmt.Println(err)
return
}
c2, err := lxc.NewContainer(name)
if err != nil {
fmt.Println(err)
return
}
defer lxc.Release(c2)
log.Printf("Creating container...\n")
c2.SetVerbosity(lxc.Verbose)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment