Use the check_backend_available function.

Eliminates the spurrious syslog messages and is a cleaner mechanism
for querying all of the available backends on a system.
This commit is contained in:
Timur Alperovich 2016-03-07 15:09:20 -08:00
parent f44df21404
commit 4f278195a4
2 changed files with 25 additions and 11 deletions

View File

@ -26,6 +26,7 @@ from .enum import Enum
from .enum import unique from .enum import unique
from .utils import create_instance from .utils import create_instance
from .utils import positive_int_value from .utils import positive_int_value
from pyeclib_c import check_backend_available
def PyECLibVersion(z, y, x): def PyECLibVersion(z, y, x):
@ -476,18 +477,14 @@ ALL_EC_TYPES = [
def _PyECLibValidECTypes(): def _PyECLibValidECTypes():
available_ec_types = [] available_ec_types = []
for _type in ALL_EC_TYPES: for _type in ALL_EC_TYPES:
driver = None if _type.startswith('flat_xor_hd'):
try: int_type = PyECLib_EC_Types.get_by_name('flat_xor_hd')
if _type is 'shss': else:
_m = 4 int_type = PyECLib_EC_Types.get_by_name(_type)
else: if not int_type:
_m = 5
driver = ECDriver(k=10, m=_m, ec_type=_type, validate=True)
if driver:
available_ec_types.append(_type)
except:
# ignore any errors, assume backend not available
continue continue
if check_backend_available(int_type.value):
available_ec_types.append(_type)
return available_ec_types return available_ec_types

View File

@ -1172,6 +1172,22 @@ exit:
return ret_obj; return ret_obj;
} }
static PyObject*
pyeclib_c_check_backend_available(PyObject *self, PyObject *args)
{
const ec_backend_id_t backend_id;
if (!PyArg_ParseTuple(args, "i", &backend_id)) {
pyeclib_c_seterr(-EINVALIDPARAMS, "pyeclib_c_check_backend_available ERROR: ");
return NULL;
}
if (liberasurecode_backend_available(backend_id)) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
static PyMethodDef PyECLibMethods[] = { static PyMethodDef PyECLibMethods[] = {
{"init", pyeclib_c_init, METH_VARARGS, "Initialize a new erasure encoder/decoder"}, {"init", pyeclib_c_init, METH_VARARGS, "Initialize a new erasure encoder/decoder"},
@ -1182,6 +1198,7 @@ static PyMethodDef PyECLibMethods[] = {
{"get_segment_info", pyeclib_c_get_segment_info, METH_VARARGS, "Return segment and fragment size information needed when encoding a segmented stream"}, {"get_segment_info", pyeclib_c_get_segment_info, METH_VARARGS, "Return segment and fragment size information needed when encoding a segmented stream"},
{"get_metadata", pyeclib_c_get_metadata, METH_VARARGS, "Get the integrity checking metadata for a fragment"}, {"get_metadata", pyeclib_c_get_metadata, METH_VARARGS, "Get the integrity checking metadata for a fragment"},
{"check_metadata", pyeclib_c_check_metadata, METH_VARARGS, "Check the integrity checking metadata for a set of fragments"}, {"check_metadata", pyeclib_c_check_metadata, METH_VARARGS, "Check the integrity checking metadata for a set of fragments"},
{"check_backend_available", pyeclib_c_check_backend_available, METH_VARARGS, "Check if a backend is available"},
{NULL, NULL, 0, NULL} /* Sentinel */ {NULL, NULL, 0, NULL} /* Sentinel */
}; };