瀏覽代碼

Renamed Container property Ram to Memory before it is too late

Sam Alba 12 年之前
父節點
當前提交
948961831a
共有 3 個文件被更改,包括 26 次插入26 次删除
  1. 7 7
      container.go
  2. 9 9
      container_test.go
  3. 10 10
      lxc_template.go

+ 7 - 7
container.go

@@ -51,13 +51,13 @@ type Container struct {
 }
 }
 
 
 type Config struct {
 type Config struct {
-	Hostname  string
-	User      string
-	Ram       int64 // Memory limit (in bytes)
-	RamSwap   int64 // Total memory usage (ram + swap); set `-1' to disable swap
-	Ports     []int
-	Tty       bool // Attach standard streams to a tty, including stdin if it is not closed.
-	OpenStdin bool // Open stdin
+	Hostname   string
+	User       string
+	Memory     int64 // Memory limit (in bytes)
+	MemorySwap int64 // Total memory usage (memory + swap); set `-1' to disable swap
+	Ports      []int
+	Tty        bool // Attach standard streams to a tty, including stdin if it is not closed.
+	OpenStdin  bool // Open stdin
 }
 }
 
 
 type NetworkSettings struct {
 type NetworkSettings struct {

+ 9 - 9
container_test.go

@@ -24,7 +24,7 @@ func TestStart(t *testing.T) {
 		[]string{"-al"},
 		[]string{"-al"},
 		[]string{testLayerPath},
 		[]string{testLayerPath},
 		&Config{
 		&Config{
-			Ram: 33554432,
+			Memory: 33554432,
 		},
 		},
 	)
 	)
 	if err != nil {
 	if err != nil {
@@ -60,7 +60,7 @@ func TestRun(t *testing.T) {
 		[]string{"-al"},
 		[]string{"-al"},
 		[]string{testLayerPath},
 		[]string{testLayerPath},
 		&Config{
 		&Config{
-			Ram: 33554432,
+			Memory: 33554432,
 		},
 		},
 	)
 	)
 	if err != nil {
 	if err != nil {
@@ -589,11 +589,11 @@ func TestLXCConfig(t *testing.T) {
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
-	// Ram is allocated randomly for testing
+	// Memory is allocated randomly for testing
 	rand.Seed(time.Now().UTC().UnixNano())
 	rand.Seed(time.Now().UTC().UnixNano())
-	ramMin := 33554432
-	ramMax := 536870912
-	ram := ramMin + rand.Intn(ramMax-ramMin)
+	memMin := 33554432
+	memMax := 536870912
+	mem := memMin + rand.Intn(memMax-memMin)
 	container, err := docker.Create(
 	container, err := docker.Create(
 		"config_test",
 		"config_test",
 		"/bin/true",
 		"/bin/true",
@@ -601,7 +601,7 @@ func TestLXCConfig(t *testing.T) {
 		[]string{testLayerPath},
 		[]string{testLayerPath},
 		&Config{
 		&Config{
 			Hostname: "foobar",
 			Hostname: "foobar",
-			Ram:      int64(ram),
+			Memory:   int64(mem),
 		},
 		},
 	)
 	)
 	if err != nil {
 	if err != nil {
@@ -611,9 +611,9 @@ func TestLXCConfig(t *testing.T) {
 	container.generateLXCConfig()
 	container.generateLXCConfig()
 	grepFile(t, container.lxcConfigPath, "lxc.utsname = foobar")
 	grepFile(t, container.lxcConfigPath, "lxc.utsname = foobar")
 	grepFile(t, container.lxcConfigPath,
 	grepFile(t, container.lxcConfigPath,
-		fmt.Sprintf("lxc.cgroup.memory.limit_in_bytes = %d", ram))
+		fmt.Sprintf("lxc.cgroup.memory.limit_in_bytes = %d", mem))
 	grepFile(t, container.lxcConfigPath,
 	grepFile(t, container.lxcConfigPath,
-		fmt.Sprintf("lxc.cgroup.memory.memsw.limit_in_bytes = %d", ram*2))
+		fmt.Sprintf("lxc.cgroup.memory.memsw.limit_in_bytes = %d", mem*2))
 }
 }
 
 
 func BenchmarkRunSequencial(b *testing.B) {
 func BenchmarkRunSequencial(b *testing.B) {

+ 10 - 10
lxc_template.go

@@ -85,10 +85,10 @@ lxc.mount.entry = /etc/resolv.conf {{$ROOTFS}}/etc/resolv.conf none bind,ro 0 0
 lxc.cap.drop = audit_control audit_write mac_admin mac_override mknod net_raw setfcap setpcap sys_admin sys_boot sys_module sys_nice sys_pacct sys_rawio sys_resource sys_time sys_tty_config
 lxc.cap.drop = audit_control audit_write mac_admin mac_override mknod net_raw setfcap setpcap sys_admin sys_boot sys_module sys_nice sys_pacct sys_rawio sys_resource sys_time sys_tty_config
 
 
 # limits
 # limits
-{{if .Config.Ram}}
-lxc.cgroup.memory.limit_in_bytes = {{.Config.Ram}}
-lxc.cgroup.memory.soft_limit_in_bytes = {{.Config.Ram}}
-{{with $ramSwap := getRamSwap .Config}}
+{{if .Config.Memory}}
+lxc.cgroup.memory.limit_in_bytes = {{.Config.Memory}}
+lxc.cgroup.memory.soft_limit_in_bytes = {{.Config.Memory}}
+{{with $ramSwap := getMemorySwap .Config}}
 lxc.cgroup.memory.memsw.limit_in_bytes = {{$ramSwap}}
 lxc.cgroup.memory.memsw.limit_in_bytes = {{$ramSwap}}
 {{end}}
 {{end}}
 {{end}}
 {{end}}
@@ -96,19 +96,19 @@ lxc.cgroup.memory.memsw.limit_in_bytes = {{$ramSwap}}
 
 
 var LxcTemplateCompiled *template.Template
 var LxcTemplateCompiled *template.Template
 
 
-func getRamSwap(config *Config) int64 {
-	// By default, RamSwap is set to twice the size of RAM.
-	// If you want to omit RamSwap, set it to `-1'.
-	if config.RamSwap < 0 {
+func getMemorySwap(config *Config) int64 {
+	// By default, MemorySwap is set to twice the size of RAM.
+	// If you want to omit MemorySwap, set it to `-1'.
+	if config.MemorySwap < 0 {
 		return 0
 		return 0
 	}
 	}
-	return config.Ram * 2
+	return config.Memory * 2
 }
 }
 
 
 func init() {
 func init() {
 	var err error
 	var err error
 	funcMap := template.FuncMap{
 	funcMap := template.FuncMap{
-		"getRamSwap": getRamSwap,
+		"getMemorySwap": getMemorySwap,
 	}
 	}
 	LxcTemplateCompiled, err = template.New("lxc").Funcs(funcMap).Parse(LxcTemplate)
 	LxcTemplateCompiled, err = template.New("lxc").Funcs(funcMap).Parse(LxcTemplate)
 	if err != nil {
 	if err != nil {