1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
// Copyright © 2013, 2014, The Go-LXC Authors. All rights reserved.
// Use of this source code is governed by a LGPLv2.1
// license that can be found in the LICENSE file.
// +build linux,cgo
package main
import (
"flag"
"log"
"github.com/lxc/go-lxc"
)
var (
lxcpath string
name string
clear bool
x86 bool
regular bool
)
func init() {
flag.StringVar(&lxcpath, "lxcpath", lxc.DefaultConfigPath(), "Use specified container path")
flag.StringVar(&name, "name", "rubik", "Name of the original container")
flag.BoolVar(&clear, "clear", false, "Attach with clear environment")
flag.BoolVar(&x86, "x86", false, "Attach using x86 personality")
flag.BoolVar(®ular, "regular", false, "Attach using a regular user")
flag.Parse()
}
func main() {
c, err := lxc.NewContainer(name, lxcpath)
if err != nil {
log.Fatalf("ERROR: %s\n", err.Error())
}
defer c.Release()
options := lxc.DefaultAttachOptions
options.ClearEnv = false
if clear {
options.ClearEnv = true
}
if x86 {
options.Arch = lxc.X86
}
if regular {
options.UID = 1000
options.GID = 1000
}
log.Printf("AttachShell\n")
err = c.AttachShell(options)
if err != nil {
log.Fatalf("ERROR: %s\n", err.Error())
}
log.Printf("RunCommand\n")
_, err = c.RunCommand([]string{"id"}, options)
if err != nil {
log.Fatalf("ERROR: %s\n", err.Error())
}
}
|