예제 #1
0
파일: create.go 프로젝트: senior7515/lxc
func main() {
	c := lxc.NewContainer(name)

	if !c.Defined() {
		fmt.Printf("Creating container...\n")
		c.Create("ubuntu", []string{"amd64", "quantal"})
	} else {
		fmt.Printf("Container is already created...\n")
	}
}
예제 #2
0
파일: destroy.go 프로젝트: senior7515/lxc
func main() {
	c := lxc.NewContainer(name)

	if c.Defined() {
		fmt.Printf("Destroying container...\n")
		c.Destroy()
	} else {
		fmt.Printf("No such container...\n")
	}
}
예제 #3
0
파일: shutdown.go 프로젝트: senior7515/lxc
func main() {
	c := lxc.NewContainer(name)

	if c.Defined() {
		if c.Running() {
			fmt.Printf("Shutting down the container...\n")
			c.Shutdown(30)
		} else {
			fmt.Printf("Container is already stopped...\n")
		}
	} else {
		fmt.Printf("No such container...\n")
	}
}
예제 #4
0
파일: unfreeze.go 프로젝트: senior7515/lxc
func main() {
	c := lxc.NewContainer(name)

	if c.Defined() {
		if c.State() == lxc.FROZEN {
			fmt.Printf("Unfreezing the container...\n")
			c.Unfreeze()
			c.Wait(lxc.RUNNING, 10)
		} else {
			fmt.Printf("Container is not running...\n")
		}
	} else {
		fmt.Printf("No such container...\n")
	}
}
예제 #5
0
파일: start.go 프로젝트: senior7515/lxc
func main() {
	c := lxc.NewContainer(name)

	if c.Defined() {
		if !c.Running() {
			fmt.Printf("Starting the container...\n")
			c.SetDaemonize()
			c.Start(false, nil)
		} else {
			fmt.Printf("Container is already running...\n")
		}
	} else {
		fmt.Printf("No such container...\n")
	}
}
예제 #6
0
파일: freeze.go 프로젝트: senior7515/lxc
func main() {
	c := lxc.NewContainer(name)

	if c.Defined() {
		if c.Running() {
			fmt.Printf("Freezing the container...\n")
			c.Freeze()
			c.Wait(lxc.FROZEN, 10)
		} else {
			fmt.Printf("Container is not running...\n")
		}
	} else {
		fmt.Printf("No such container...\n")
	}
}
예제 #7
0
func main() {
	var wg sync.WaitGroup

	for i := 0; i < 10; i++ {
		wg.Add(1)
		go func(i int) {
			z := lxc.NewContainer(strconv.Itoa(i))

			fmt.Printf("Destroying the container (%d)...\n", i)
			if !z.Destroy() {
				fmt.Printf("Destroying the container (%d) failed...\n", i)
			}
			wg.Done()
		}(i)
	}
	wg.Wait()
}
예제 #8
0
func main() {
	var wg sync.WaitGroup

	for i := 0; i < 10; i++ {
		wg.Add(1)
		go func(i int) {
			z := lxc.NewContainer(strconv.Itoa(i))

			fmt.Printf("Creating the container (%d)...\n", i)
			if !z.Create("ubuntu", []string{"amd64", "quantal"}) {
				fmt.Printf("Creating the container (%d) failed...\n", i)
			}
			wg.Done()
		}(i)
	}
	wg.Wait()
}
예제 #9
0
func main() {
	var wg sync.WaitGroup

	for i := 0; i < 10; i++ {
		wg.Add(1)
		go func(i int) {
			z := lxc.NewContainer(strconv.Itoa(i))

			if z.Defined() && z.Running() {
				fmt.Printf("Stopping the container (%d)...\n", i)
				if !z.Stop() {
					fmt.Printf("Stopping the container (%d) failed...\n", i)
				}
			}
			wg.Done()
		}(i)
	}
	wg.Wait()
}
예제 #10
0
파일: stats.go 프로젝트: senior7515/lxc
func main() {
	c := lxc.NewContainer(name)

	if c.Running() {
		// mem
		mem_used, _ := c.MemoryUsageInBytes()
		fmt.Printf("mem_used: %s\n", mem_used)

		mem_limit, _ := c.MemoryLimitInBytes()
		fmt.Printf("mem_limit: %s\n", mem_limit)

		// swap
		swap_used, _ := c.SwapUsageInBytes()
		fmt.Printf("memsw_used: %s\n", swap_used)

		swap_limit, _ := c.SwapLimitInBytes()
		fmt.Printf("memsw_used: %s\n", swap_limit)
	} else {
		fmt.Printf("Container is not running...\n")
	}
}
예제 #11
0
func main() {
	var wg sync.WaitGroup

	for i := 0; i < 100; i++ {
		wg.Add(1)
		go func(i int) {
			name := strconv.Itoa(rand.Intn(10))

			z := lxc.NewContainer(name)

			// sleep for a while to simulate some dummy work
			time.Sleep(time.Millisecond * time.Duration(rand.Intn(500)))

			if z.Defined() {
				if !z.Running() {
					z.SetDaemonize()
					//					fmt.Printf("Starting the container (%s)...\n", name)
					if !z.Start(false, nil) {
						fmt.Printf("Starting the container (%s) failed...\n", name)
					}
				} else {
					//					fmt.Printf("Stopping the container (%s)...\n", name)
					if !z.Stop() {
						fmt.Printf("Stopping the container (%s) failed...\n", name)
					}
				}
			} else {
				if !z.Create("ubuntu", []string{"amd64", "quantal"}) {
					fmt.Printf("Creating the container (%s) failed...\n", name)
				}
			}
			wg.Done()
		}(i)
	}
	wg.Wait()
}