[blivet:master] Adjust RaidLevel hierarchy so that all raid level objects extend RAIDLevel
David Lehman
dlehman at redhat.com
Fri May 9 19:14:21 UTC 2014
On 05/09/2014 11:51 AM, mulhern wrote:
> Signed-off-by: mulhern <amulhern at redhat.com>
> ---
> blivet/devicelibs/raid.py | 41 +++++++++++++++++++++++++++++------------
> 1 file changed, 29 insertions(+), 12 deletions(-)
>
> diff --git a/blivet/devicelibs/raid.py b/blivet/devicelibs/raid.py
> index 3d750fe..5840ef0 100644
> --- a/blivet/devicelibs/raid.py
> +++ b/blivet/devicelibs/raid.py
> @@ -34,9 +34,29 @@ def div_up(a,b):
> return (a + (b - 1))//b
>
> class RAIDLevel(object):
> + """An abstract class which is the parent of all classes which represent
> + a RAID level.
> +
> + It ensures that RAIDLevel objects will really be singleton objects
> + by overriding copy methods.
> + """
> + __metaclass__ = abc.ABCMeta
> +
> + name = abc.abstractproperty(doc="The canonical name for this level")
> +
> + def __str__(self):
> + return self.name
> +
> + def __copy__(self):
> + return self
> +
> + def __deepcopy__(self):
> + return self
> +
> +class RAIDn(RAIDLevel):
>
> """An abstract class which is the parent of classes which represent a
> - RAID level. A better word would be classification, since 'level'
> + numeric RAID level. A better word would be classification, since 'level'
> implies an ordering, but level is the canonical word.
>
> The abstract properties of the class are:
> @@ -322,7 +342,7 @@ class RAIDLevels(object):
>
> ALL_LEVELS = RAIDLevels()
>
> -class RAID0(RAIDLevel):
> +class RAID0(RAIDn):
>
> level = property(lambda s: "0")
> min_members = property(lambda s: 2)
> @@ -346,7 +366,7 @@ class RAID0(RAIDLevel):
> RAID0 = RAID0()
> ALL_LEVELS.addRaidLevel(RAID0)
>
> -class RAID1(RAIDLevel):
> +class RAID1(RAIDn):
> level = property(lambda s: "1")
> min_members = property(lambda s: 2)
> nick = property(lambda s: "mirror")
> @@ -369,7 +389,7 @@ class RAID1(RAIDLevel):
> RAID1 = RAID1()
> ALL_LEVELS.addRaidLevel(RAID1)
>
> -class RAID4(RAIDLevel):
> +class RAID4(RAIDn):
> level = property(lambda s: "4")
> min_members = property(lambda s: 3)
> nick = property(lambda s: None)
> @@ -392,7 +412,7 @@ class RAID4(RAIDLevel):
> RAID4 = RAID4()
> ALL_LEVELS.addRaidLevel(RAID4)
>
> -class RAID5(RAIDLevel):
> +class RAID5(RAIDn):
> level = property(lambda s: "5")
> min_members = property(lambda s: 3)
> nick = property(lambda s: None)
> @@ -415,7 +435,7 @@ class RAID5(RAIDLevel):
> RAID5 = RAID5()
> ALL_LEVELS.addRaidLevel(RAID5)
>
> -class RAID6(RAIDLevel):
> +class RAID6(RAIDn):
> level = property(lambda s: "6")
> min_members = property(lambda s: 4)
> nick = property(lambda s: None)
> @@ -438,7 +458,7 @@ class RAID6(RAIDLevel):
> RAID6 = RAID6()
> ALL_LEVELS.addRaidLevel(RAID6)
>
> -class RAID10(RAIDLevel):
> +class RAID10(RAIDn):
> level = property(lambda s: "10")
> min_members = property(lambda s: 4)
> nick = property(lambda s: None)
> @@ -461,7 +481,7 @@ class RAID10(RAIDLevel):
> RAID10 = RAID10()
> ALL_LEVELS.addRaidLevel(RAID10)
>
> -class Container(object):
> +class Container(RAIDLevel):
> name = "container"
> names = [name]
> min_members = 1
> @@ -474,13 +494,10 @@ class Container(object):
> def get_size(self, member_sizes, num_members=None, chunk_size=None, superblock_size_func=None):
> return sum(member_sizes)
>
> - def __str__(self):
> - return self.name
> -
> Container = Container()
> ALL_LEVELS.addRaidLevel(Container)
>
> -class LinearRAID(object):
> +class LinearRAID(RAIDLevel):
>
> name = "linear"
> names = [name, 'single', 'none']
LinearRAID should have almost all the methods of RAIDn with the
exception of get_base_member_size, shouldn't it? Container can be
different since we don't create those, but I think the only difference
between linear and the numeric levels is the requirement that all member
have the same size.
David
More information about the anaconda-patches
mailing list