forked from tych0/lxd-pkg-ubuntu
/
concurrent_create.go
49 lines (40 loc) · 921 Bytes
/
concurrent_create.go
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
// 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"
"runtime"
"strconv"
"sync"
"gopkg.in/lxc/go-lxc.v2"
)
var (
lxcpath string
)
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
flag.StringVar(&lxcpath, "lxcpath", lxc.DefaultConfigPath(), "Use specified container path")
flag.Parse()
}
func main() {
var wg sync.WaitGroup
options := lxc.BusyboxTemplateOptions
for i := 0; i < 10; i++ {
wg.Add(1)
go func(i int) {
c, err := lxc.NewContainer(strconv.Itoa(i), lxcpath)
if err != nil {
log.Fatalf("ERROR: %s\n", err.Error())
}
log.Printf("Creating the container (%d)...\n", i)
if err := c.Create(options); err != nil {
log.Fatalf("ERROR: %s\n", err.Error())
}
wg.Done()
}(i)
}
wg.Wait()
}