showResizeStorageModal displays a modal for resizing a storage volume.
(app *App, vm *api.VM)
| 1019 | |
| 1020 | // showResizeStorageModal displays a modal for resizing a storage volume. |
| 1021 | func 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 |
no test coverage detected