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

Function showResizeStorageModal

internal/ui/components/vm_config.go:1021–1138  ·  view source on GitHub ↗

showResizeStorageModal displays a modal for resizing a storage volume.

(app *App, vm *api.VM)

Source from the content-addressed store, hash-verified

1019
1020// showResizeStorageModal displays a modal for resizing a storage volume.
1021func showResizeStorageModal(app *App, vm *api.VM) {
1022 modal := newStandardForm().SetHorizontal(false)
1023
1024 // Build list of storage devices (filter to only resizable volumes)
1025 var deviceNames []string
1026
1027 deviceMap := make(map[string]*api.StorageDevice)
1028
1029 for _, dev := range vm.StorageDevices {
1030 if dev.Size == "" {
1031 continue // must have a size
1032 }
1033
1034 if dev.Media == "cdrom" {
1035 continue // skip CD-ROM/ISO
1036 }
1037
1038 if strings.HasPrefix(dev.Device, "efidisk") || strings.HasPrefix(dev.Device, "scsihw") {
1039 continue // skip EFI/controller
1040 }
1041
1042 label := fmt.Sprintf("%s (%s, %s)", dev.Device, dev.Storage, dev.Size)
1043 deviceNames = append(deviceNames, label)
1044 deviceMap[label] = &dev
1045 }
1046
1047 selectedDevice := ""
1048 if len(deviceNames) > 0 {
1049 selectedDevice = deviceNames[0]
1050 }
1051
1052 modal.AddDropDown("Volume", deviceNames, 0, func(option string, idx int) {
1053 selectedDevice = option
1054 })
1055 modal.AddInputField("Expand by (GB)", "", 8, func(textToCheck string, lastChar rune) bool {
1056 if lastChar < '0' || lastChar > '9' {
1057 return false
1058 }
1059
1060 return true
1061 }, nil)
1062
1063 modal.AddButton("Resize", func() {
1064 // * Check if VM has pending operations
1065 if isPending, pendingOperation := models.GlobalState.IsVMPending(vm); isPending {
1066 app.showMessageSafe(fmt.Sprintf("Cannot resize storage while '%s' is in progress", pendingOperation))
1067 return
1068 }
1069
1070 amountField, ok := modal.GetFormItemByLabel("Expand by (GB)").(*tview.InputField)
1071 if !ok {
1072 app.showMessageSafe("Failed to get amount field.")
1073
1074 return
1075 }
1076
1077 amountStr := amountField.GetText()
1078

Callers 1

NewVMConfigPageFunction · 0.85

Calls 13

GetUILoggerFunction · 0.92
newStandardFormFunction · 0.85
IsVMPendingMethod · 0.80
showMessageSafeMethod · 0.80
ResizeVMStorageMethod · 0.80
QueueUpdateDrawMethod · 0.80
refreshVMDataAndTasksMethod · 0.80
removePageIfPresentMethod · 0.80
ShowErrorMethod · 0.65
ShowSuccessMethod · 0.65
ErrorMethod · 0.65
SetTitleMethod · 0.65

Tested by

no test coverage detected