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

Vratislav Podzimek vpodzime at redhat.com
Thu Jun 19 08:14:38 UTC 2014


On Wed, 2014-06-18 at 16:27 -0700, Brian C. Lane wrote:
> 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)
Could ever happen that the chosen disklabel won't be in the list, but we
would still like to insert it to the first place? If not, then these all
look good to me.

-- 
Vratislav Podzimek

Anaconda Rider | RHCE | Red Hat, Inc. | Brno - Czech Republic




More information about the anaconda-patches mailing list