[node-patches] Change in ovirt-node[master]: Validate sizes on storage installer page and calculate free ...

rbarry at redhat.com rbarry at redhat.com
Fri Aug 9 17:59:12 UTC 2013


Ryan Barry has uploaded a new change for review.

Change subject: Validate sizes on storage installer page and calculate free space
......................................................................

Validate sizes on storage installer page and calculate free space

Make sure users cannot proceed with values which are too large.
Additionally, dynamically update either the size of the data
partition or remaining free space, depending on whether a
checkbox to fill remaining space with the data partition is
selected or not.

Change-Id: Ibde087a31909d26aef8e00b58d895567e87b12cd
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=918961
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=867843
Signed-off-by: Ryan Barry <rbarry at redhat.com>
---
M src/ovirt/node/installer/core/storage_vol_page.py
1 file changed, 77 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/81/17881/1

diff --git a/src/ovirt/node/installer/core/storage_vol_page.py b/src/ovirt/node/installer/core/storage_vol_page.py
index 718cb02..d81d5df 100644
--- a/src/ovirt/node/installer/core/storage_vol_page.py
+++ b/src/ovirt/node/installer/core/storage_vol_page.py
@@ -23,10 +23,14 @@
 Storage Volume page of the installer
 """
 from ovirt.node import plugins, ui, valid
+from ovirt.node.exceptions import InvalidData
+import re
 
 
 class Plugin(plugins.NodePlugin):
     _model = {}
+    _free_space = 0
+    _fill = True
 
     def name(self):
         return "Storage Sizes"
@@ -37,6 +41,8 @@
     def model(self):
         if not self._model:
             self._model = self.__get_default_sizes()
+            self._model["storage.data_size"] = "%s" %\
+                                               self.__calculate_free_space()
             self.logger.debug("Predefined sizes: %s" % self._model)
         return self._model
 
@@ -54,16 +60,22 @@
                 "storage.logging_size":
                 valid.Number(bounds=[min_logging, None]) | is_zero,
                 "storage.data_size":
-                valid.Number(bounds=[0, None]),
+                valid.Number(bounds=[-1, None]),
                 }
 
     def ui_content(self):
         ws = [ui.Header("header[0]", "Storage Volumes"),
-              ui.Label("label[0]", "Please enter the sizes for the " +
+              ui.KeywordLabel("storage.drive_size", "Drive size: "),]
+
+        if not self._fill:
+            ws.extend([ui.KeywordLabel("storage.free_space",
+                                       "Remaining Space: ")])
+
+        ws.extend([ui.Label("label[0]", "Please enter the sizes for the " +
                        "following partitions in MB"),
-              ui.Divider("divider[0]"),
+              ui.Checkbox("storage.fill_data", "Fill disk with Data " +
+                          "partition", True),
               ui.Entry("storage.efi_size", "UEFI/Bios:", enabled=False),
-              ui.Divider("divider[1]"),
               ui.Entry("storage.root_size", "Root & RootBackup:",
                        enabled=False),
               ui.Label("label[1]", "(2 partitions at 512MB each)"),
@@ -71,8 +83,13 @@
               ui.Entry("storage.swap_size", "Swap:"),
               ui.Entry("storage.config_size", "Config:"),
               ui.Entry("storage.logging_size", "Logging:"),
-              ui.Entry("storage.data_size", "Data:"),
-              ]
+              ui.Entry("storage.data_size", "Data:", enabled=not self._fill),
+              ])
+
+        if not self._fill:
+            ws.extend([ui.Label("label[2]", "(-1 fills all free space)")])
+
+        self.logger.debug(dir(self._model))
         self.widgets.add(ws)
         page = ui.Page("storage", ws)
         page.buttons = [ui.QuitButton("button.quit", "Quit"),
@@ -82,6 +99,28 @@
 
     def on_change(self, changes):
         self._model.update(changes)
+
+        if "storage.fill_data" in changes:
+            if self._fill is not changes["storage.fill_data"]:
+                self._fill = changes["storage.fill_data"]
+                self.application.show(self.ui_content())
+        size_keys = ["storage.efi_size", "storage.root_size",
+                     "storage.swap_size", "storage.config_size",
+                     "storage.logging_size"]
+        if not self._fill:
+            size_keys.append("storage.data_size")
+        if changes.contains_any(size_keys):
+            self._free_space = self.__calculate_free_space()
+            if "storage.free_space"  in self.widgets:
+                self.widgets["storage.free_space"].text("%s MB" %
+                                                        self._free_space)
+            if self._fill:
+                self.widgets["storage.data_size"].text("%s" % self._free_space)
+            if self._free_space < 0:
+                if self._fill:
+                    raise InvalidData("Data partition must be at least 0 MB")
+                else:
+                    raise InvalidData("Free space must not be negative")
 
     def on_merge(self, effective_changes):
         changes = self.pending_changes(False)
@@ -108,11 +147,43 @@
                     }
         from ovirtnode.storage import Storage
         stor = Storage()
+        self._drive_size = stor.get_drive_size(self.__get_install_drive())
         sizes = {"storage.efi_size": "%s" % stor.EFI_SIZE,
                  "storage.root_size": "%s" % stor.ROOT_SIZE,
                  "storage.swap_size": "%s" % stor.SWAP_SIZE,
                  "storage.config_size": "%s" % stor.CONFIG_SIZE,
                  "storage.logging_size": "%s" % stor.LOGGING_SIZE,
                  "storage.data_size": "%s" % stor.DATA_SIZE,
+                 "storage.free_space": "%s MB" % self._drive_size,
+                 "storage.drive_size": "%s MB" % self._drive_size
                  }
         return sizes
+
+    def __get_install_drive(self):
+        app = self.application
+        return app.plugins()["Data Device"].model()[
+            "installation.device.current"]
+
+    def __calculate_free_space(self):
+
+        # Get these from the model because users can't change them and they
+        # may change in the future. Root size is doubled to account for
+        # rootbackup
+        free_space = self._drive_size - (int(self._model["storage.root_size"])
+                                         * 2 + int(self._model[
+            "storage.efi_size"]))
+
+        size_keys = ["storage.swap_size", "storage.config_size",
+                     "storage.logging_size"]
+
+        if int(self._model["storage.data_size"]) > -1 and not self._fill:
+            size_keys.append("storage.data_size")
+
+        for key in size_keys:
+            free_space -= int(self._model[key])
+
+        if int(self._model["storage.data_size"]) == -1 and free_space > 0:
+            free_space = 0
+
+        return free_space
+


-- 
To view, visit http://gerrit.ovirt.org/17881
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibde087a31909d26aef8e00b58d895567e87b12cd
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Ryan Barry <rbarry at redhat.com>



More information about the node-patches mailing list