This function parses the "size" parameter of a disk specification and returns the size in MB. The "size" parameter defaults to GB, but the unit can be explicitly set with either a G (for GB) or M (for MB). It returns the disk size in MB.
(s string)
| 163 | // the unit can be explicitly set with either a G (for GB) or M (for |
| 164 | // MB). It returns the disk size in MB. |
| 165 | func getDiskSizeMB(s string) (int, error) { |
| 166 | if s == "" { |
| 167 | return 0, nil |
| 168 | } |
| 169 | sz := len(s) |
| 170 | if strings.HasSuffix(s, "M") { |
| 171 | return strconv.Atoi(s[:sz-1]) |
| 172 | } |
| 173 | if strings.HasSuffix(s, "G") { |
| 174 | s = s[:sz-1] |
| 175 | } |
| 176 | |
| 177 | i, err := strconv.Atoi(s) |
| 178 | if err != nil { |
| 179 | return 0, err |
| 180 | } |
| 181 | return 1024 * i, nil |
| 182 | } |
| 183 | |
| 184 | func convertMBtoGB(i int) int { |
| 185 | if i < 1024 { |
no outgoing calls
no test coverage detected