MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / parseConfigSizeBytes

Function parseConfigSizeBytes

pkg/api/vm_config.go:241–277  ·  view source on GitHub ↗
(raw string)

Source from the content-addressed store, hash-verified

239}
240
241func parseConfigSizeBytes(raw string) (int64, bool) {
242 parts := strings.Split(raw, ",")
243 for _, part := range parts {
244 part = strings.TrimSpace(part)
245 if !strings.HasPrefix(part, "size=") {
246 continue
247 }
248
249 value := strings.TrimPrefix(part, "size=")
250 if value == "" {
251 return 0, false
252 }
253
254 multiplier := int64(1024 * 1024 * 1024)
255 switch suffix := strings.ToUpper(value[len(value)-1:]); suffix {
256 case "K":
257 multiplier = 1024
258 value = value[:len(value)-1]
259 case "M":
260 multiplier = 1024 * 1024
261 value = value[:len(value)-1]
262 case "G":
263 value = value[:len(value)-1]
264 case "T":
265 multiplier = 1024 * 1024 * 1024 * 1024
266 value = value[:len(value)-1]
267 }
268
269 size, err := strconv.ParseInt(value, 10, 64)
270 if err != nil {
271 return 0, false
272 }
273 return size * multiplier, true
274 }
275
276 return 0, false
277}
278
279// buildConfigPayload builds the payload for updating VM/LXC config.
280func buildConfigPayload(vmType string, config *VMConfig) map[string]interface{} {

Callers 1

parseVMConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected