-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlimits.go
More file actions
150 lines (116 loc) · 3.47 KB
/
limits.go
File metadata and controls
150 lines (116 loc) · 3.47 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package parser
import (
"github.com/deis/workflow/client/cmd"
docopt "github.com/docopt/docopt-go"
)
// Limits routes limits commands to their specific function
func Limits(argv []string) error {
usage := `
Valid commands for limits:
limits:list list resource limits for an app
limits:set set resource limits for an app
limits:unset unset resource limits for an app
Use 'deis help [command]' to learn more.
`
switch argv[0] {
case "limits:list":
return limitsList(argv)
case "limits:set":
return limitSet(argv)
case "limits:unset":
return limitUnset(argv)
default:
if printHelp(argv, usage) {
return nil
}
if argv[0] == "limits" {
argv[0] = "limits:list"
return limitsList(argv)
}
PrintUsage()
return nil
}
}
func limitsList(argv []string) error {
usage := `
Lists resource limits for an application.
Usage: deis limits:list [options]
Options:
-a --app=<app>
the uniquely identifiable name of the application.
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
return cmd.LimitsList(safeGetValue(args, "--app"))
}
func limitSet(argv []string) error {
usage := `
Sets resource limits for an application.
A resource limit is a finite resource within a container which we can apply
restrictions to either through the scheduler or through the Docker API. This limit
is applied to each individual container, so setting a memory limit of 1G for an
application means that each container gets 1G of memory.
Usage: deis limits:set [options] <type>=<limit>...
Arguments:
<type>
the process type as defined in your Procfile, such as 'web' or 'worker'.
Note that Dockerfile apps have a default 'cmd' process type.
<limit>
The limit to apply to the process type. By default, this is set to --memory.
You can only set one type of limit per call.
With --memory, units are represented in Bytes (B), Kilobytes (K), Megabytes
(M), or Gigabytes (G). For example, 'deis limit:set cmd=1G' will restrict all
"cmd" processes to a maximum of 1 Gigabyte of memory each.
With --cpu, units are represented in the number of cpu shares. For example,
'deis limit:set --cpu cmd=1024' will restrict all "cmd" processes to a
maximum of 1024 cpu shares.
Options:
-a --app=<app>
the uniquely identifiable name for the application.
-c --cpu
limits cpu shares.
-m --memory
limits memory. [default: true]
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
app := safeGetValue(args, "--app")
limits := args["<type>=<limit>"].([]string)
limitType := "memory"
if args["--cpu"].(bool) {
limitType = "cpu"
}
return cmd.LimitsSet(app, limits, limitType)
}
func limitUnset(argv []string) error {
usage := `
Unsets resource limits for an application.
Usage: deis limits:unset [options] [--memory | --cpu] <type>...
Arguments:
<type>
the process type as defined in your Procfile, such as 'web' or 'worker'.
Note that Dockerfile apps have a default 'cmd' process type.
Options:
-a --app=<app>
the uniquely identifiable name for the application.
-c --cpu
limits cpu shares.
-m --memory
limits memory. [default: true]
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
app := safeGetValue(args, "--app")
limits := args["<type>"].([]string)
limitType := "memory"
if args["--cpu"].(bool) {
limitType = "cpu"
}
return cmd.LimitsUnset(app, limits, limitType)
}