github.com/naphatkrit/deis@v1.12.3/client/parser/limits.go (about) 1 package parser 2 3 import ( 4 "github.com/deis/deis/client/cmd" 5 docopt "github.com/docopt/docopt-go" 6 ) 7 8 // Limits routes limits commands to their specific function 9 func Limits(argv []string) error { 10 usage := ` 11 Valid commands for limits: 12 13 limits:list list resource limits for an app 14 limits:set set resource limits for an app 15 limits:unset unset resource limits for an app 16 17 Use 'deis help [command]' to learn more. 18 ` 19 20 switch argv[0] { 21 case "limits:list": 22 return limitsList(argv) 23 case "limits:set": 24 return limitSet(argv) 25 case "limits:unset": 26 return limitUnset(argv) 27 default: 28 if printHelp(argv, usage) { 29 return nil 30 } 31 32 if argv[0] == "limits" { 33 argv[0] = "limits:list" 34 return limitsList(argv) 35 } 36 37 PrintUsage() 38 return nil 39 } 40 } 41 42 func limitsList(argv []string) error { 43 usage := ` 44 Lists resource limits for an application. 45 46 Usage: deis limits:list [options] 47 48 Options: 49 -a --app=<app> 50 the uniquely identifiable name of the application. 51 ` 52 53 args, err := docopt.Parse(usage, argv, true, "", false, true) 54 55 if err != nil { 56 return err 57 } 58 59 return cmd.LimitsList(safeGetValue(args, "--app")) 60 } 61 62 func limitSet(argv []string) error { 63 usage := ` 64 Sets resource limits for an application. 65 66 A resource limit is a finite resource within a container which we can apply 67 restrictions to either through the scheduler or through the Docker API. This limit 68 is applied to each individual container, so setting a memory limit of 1G for an 69 application means that each container gets 1G of memory. 70 71 Usage: deis limits:set [options] <type>=<limit>... 72 73 Arguments: 74 <type> 75 the process type as defined in your Procfile, such as 'web' or 'worker'. 76 Note that Dockerfile apps have a default 'cmd' process type. 77 <limit> 78 The limit to apply to the process type. By default, this is set to --memory. 79 You can only set one type of limit per call. 80 81 With --memory, units are represented in Bytes (B), Kilobytes (K), Megabytes 82 (M), or Gigabytes (G). For example, 'deis limit:set cmd=1G' will restrict all 83 "cmd" processes to a maximum of 1 Gigabyte of memory each. 84 85 With --cpu, units are represented in the number of cpu shares. For example, 86 'deis limit:set --cpu cmd=1024' will restrict all "cmd" processes to a 87 maximum of 1024 cpu shares. 88 89 Options: 90 -a --app=<app> 91 the uniquely identifiable name for the application. 92 -c --cpu 93 limits cpu shares. 94 -m --memory 95 limits memory. [default: true] 96 ` 97 98 args, err := docopt.Parse(usage, argv, true, "", false, true) 99 100 if err != nil { 101 return err 102 } 103 104 app := safeGetValue(args, "--app") 105 limits := args["<type>=<limit>"].([]string) 106 limitType := "memory" 107 108 if args["--cpu"].(bool) { 109 limitType = "cpu" 110 } 111 112 return cmd.LimitsSet(app, limits, limitType) 113 } 114 115 func limitUnset(argv []string) error { 116 usage := ` 117 Unsets resource limits for an application. 118 119 Usage: deis limits:unset [options] [--memory | --cpu] <type>... 120 121 Arguments: 122 <type> 123 the process type as defined in your Procfile, such as 'web' or 'worker'. 124 Note that Dockerfile apps have a default 'cmd' process type. 125 126 Options: 127 -a --app=<app> 128 the uniquely identifiable name for the application. 129 -c --cpu 130 limits cpu shares. 131 -m --memory 132 limits memory. [default: true] 133 ` 134 135 args, err := docopt.Parse(usage, argv, true, "", false, true) 136 137 if err != nil { 138 return err 139 } 140 141 app := safeGetValue(args, "--app") 142 limits := args["<type>"].([]string) 143 limitType := "memory" 144 145 if args["--cpu"].(bool) { 146 limitType = "cpu" 147 } 148 149 return cmd.LimitsUnset(app, limits, limitType) 150 }