[2/3 blivet] Add method to set the default disklabel (#1078537)

Brian C. Lane bcl at redhat.com
Wed Jun 18 23:27:04 UTC 2014


platform.setDefaultDiskLabel(label) will move the disklabel to the front
of the list if it is supported on the current platform and return True.
If it isn't supported it will return False and leave the list as is.
---
 blivet/platform.py | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/blivet/platform.py b/blivet/platform.py
index 498d08c..058848a 100644
--- a/blivet/platform.py
+++ b/blivet/platform.py
@@ -65,10 +65,10 @@ class Platform(object):
         self.update_from_flags()
 
     def update_from_flags(self):
-        if flags.gpt and "gpt" in self._disklabel_types:
-            # move GPT to the top of the list
-            self._disklabel_types.remove("gpt")
-            self._disklabel_types.insert(0, "gpt")
+        if flags.gpt:
+            if not self.setDefaultDiskLabelType("gpt"):
+                log.warn("GPT is not a supported disklabel on this platform. Using default "
+                         "disklabel %s instead.", self.defaultDiskLabelType)
 
     def __call__(self):
         return self
@@ -83,6 +83,26 @@ class Platform(object):
         """The default disklabel type for this architecture."""
         return self.diskLabelTypes[0]
 
+    def setDefaultDiskLabelType(self, disklabel):
+        """Make the disklabel the default
+
+           :param string disklabel: The disklabel type to set as default
+           :returns: True if successful False if disklabel not supported
+
+           If the disklabel is not supported on the platform it will return
+           False and make no change to the disklabel list.
+
+           If it is supported it will move it to the start of the list,
+           making it the default.
+        """
+        if disklabel not in self._disklabel_types:
+            return False
+
+        self._disklabel_types.remove(disklabel)
+        self._disklabel_types.insert(0, disklabel)
+        log.debug("Default disklabel has been set to %s", disklabel)
+        return True
+
     @property
     def bootStage1ConstraintDict(self):
         d = {"device_types": self._boot_stage1_device_types,
-- 
1.9.3



More information about the anaconda-patches mailing list