Allow 'flat_xor_hd_4' from external API
Add 'hd' argument back to the internal API
This commit is contained in:
parent
0103f6886f
commit
51737a984f
|
@ -34,13 +34,13 @@ pyver = float('%s.%s' % sys.version_info[:2])
|
|||
|
||||
class ECPyECLibDriver(object):
|
||||
|
||||
def __init__(self, k, m, ec_type,
|
||||
def __init__(self, k, m, hd, ec_type,
|
||||
chksum_type=PyECLib_FRAGHDRCHKSUM_Types.none):
|
||||
self.k = k
|
||||
self.m = m
|
||||
self.hd = hd
|
||||
self.ec_type = ec_type
|
||||
self.chksum_type = chksum_type
|
||||
hd = m
|
||||
|
||||
self.inline_chksum = 0
|
||||
self.algsig_chksum = 0
|
||||
|
@ -50,16 +50,11 @@ class ECPyECLibDriver(object):
|
|||
|
||||
name = self.ec_type.name
|
||||
|
||||
if name == "flat_xor_hd" or name == "flat_xor_hd_3":
|
||||
hd = 3
|
||||
if name == "flat_xor_hd_4":
|
||||
hd = 4
|
||||
|
||||
self.handle = pyeclib_c.init(
|
||||
self.k,
|
||||
self.m,
|
||||
ec_type.value,
|
||||
hd,
|
||||
self.hd,
|
||||
self.inline_chksum,
|
||||
self.algsig_chksum)
|
||||
|
||||
|
@ -141,9 +136,10 @@ class ECPyECLibDriver(object):
|
|||
|
||||
class ECNullDriver(object):
|
||||
|
||||
def __init__(self, k, m, ec_type=None, chksum_type=None):
|
||||
def __init__(self, k, m, hd, ec_type=None, chksum_type=None):
|
||||
self.k = k
|
||||
self.m = m
|
||||
self.hd = hd
|
||||
|
||||
def encode(self, data_bytes):
|
||||
pass
|
||||
|
@ -177,7 +173,7 @@ class ECNullDriver(object):
|
|||
#
|
||||
class ECStripingDriver(object):
|
||||
|
||||
def __init__(self, k, m, ec_type=None, chksum_type=None):
|
||||
def __init__(self, k, m, hd, ec_type=None, chksum_type=None):
|
||||
"""Stripe an arbitrary-sized string into k fragments
|
||||
:param k: the number of data fragments to stripe
|
||||
:param m: the number of parity fragments to stripe
|
||||
|
@ -189,6 +185,7 @@ class ECStripingDriver(object):
|
|||
raise ECDriverError("This driver only supports m=0")
|
||||
|
||||
self.m = m
|
||||
self.hd = hd
|
||||
|
||||
def encode(self, data_bytes):
|
||||
"""Stripe an arbitrary-sized string into k fragments
|
||||
|
|
|
@ -117,6 +117,7 @@ class ECDriver(object):
|
|||
def __init__(self, *args, **kwargs):
|
||||
self.k = -1
|
||||
self.m = -1
|
||||
self.hd = -1
|
||||
self.ec_type = None
|
||||
self.chksum_type = None
|
||||
for (key, value) in kwargs.items():
|
||||
|
@ -133,11 +134,14 @@ class ECDriver(object):
|
|||
raise ECDriverError(
|
||||
"Invalid number of data fragments (m)")
|
||||
elif key == "ec_type":
|
||||
if value in ["flat_xor_hd_3", "flat_xor_hd_4"]:
|
||||
if value in ["flat_xor_hd", "flat_xor_hd_3", "flat_xor_hd_4"]:
|
||||
if value == "flat_xor_hd" or value == "flat_xor_hd_3":
|
||||
self.hd = 3
|
||||
elif value == "flat_xor_hd_4":
|
||||
self.hd = 4
|
||||
value = "flat_xor_hd"
|
||||
if PyECLib_EC_Types.has_enum(value):
|
||||
self.ec_type = \
|
||||
PyECLib_EC_Types.get_by_name(value)
|
||||
self.ec_type = PyECLib_EC_Types.get_by_name(value)
|
||||
else:
|
||||
raise ECBackendNotSupported(
|
||||
"%s is not a valid EC type for PyECLib!" % value)
|
||||
|
@ -149,6 +153,9 @@ class ECDriver(object):
|
|||
raise ECDriverError(
|
||||
"%s is not a valid checksum type for PyECLib!" % value)
|
||||
|
||||
if self.hd == -1:
|
||||
self.hd = self.m
|
||||
|
||||
self.library_import_str = kwargs.pop('library_import_str',
|
||||
'pyeclib.core.ECPyECLibDriver')
|
||||
#
|
||||
|
@ -158,6 +165,7 @@ class ECDriver(object):
|
|||
self.library_import_str,
|
||||
k=self.k,
|
||||
m=self.m,
|
||||
hd=self.hd,
|
||||
ec_type=self.ec_type,
|
||||
chksum_type=self.chksum_type)
|
||||
#
|
||||
|
|
|
@ -150,11 +150,17 @@ class TestPyECLibDriver(unittest.TestCase):
|
|||
chksum_type=csum))
|
||||
pyeclib_drivers.append(ECDriver(k=8, m=4, ec_type=_type2,
|
||||
chksum_type=csum))
|
||||
_type3 = 'flat_xor_hd'
|
||||
if _type3 in _available_backends:
|
||||
pyeclib_drivers.append(ECDriver(k=12, m=6, ec_type=_type3,
|
||||
_type3_1 = 'flat_xor_hd'
|
||||
if _type3_1 in _available_backends:
|
||||
pyeclib_drivers.append(ECDriver(k=12, m=6, ec_type=_type3_1,
|
||||
chksum_type=csum))
|
||||
pyeclib_drivers.append(ECDriver(k=10, m=5, ec_type=_type3,
|
||||
pyeclib_drivers.append(ECDriver(k=10, m=5, ec_type=_type3_1,
|
||||
chksum_type=csum))
|
||||
_type3_2 = 'flat_xor_hd_4'
|
||||
if _type3_2 in _available_backends:
|
||||
pyeclib_drivers.append(ECDriver(k=12, m=6, ec_type=_type3_2,
|
||||
chksum_type=csum))
|
||||
pyeclib_drivers.append(ECDriver(k=10, m=5, ec_type=_type3_2,
|
||||
chksum_type=csum))
|
||||
_type4 = 'shss'
|
||||
if _type4 in _available_backends:
|
||||
|
|
Loading…
Reference in New Issue