Source code for oio.blob.utils
# Copyright (C) 2015-2020 OpenIO SAS, as part of OpenIO SDS
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from six import iteritems
from oio.common import exceptions as exc
from oio.common.xattr import read_user_xattr
from oio.common.constants import chunk_xattr_keys, chunk_xattr_keys_optional, \
volume_xattr_keys, CHUNK_XATTR_CONTENT_FULLPATH_PREFIX
from oio.common.fullpath import decode_fullpath
from oio.common.utils import cid_from_name
[docs]def check_volume(volume_path):
"""
Check if `volume_path` points to a rawx directory.
:returns: the namespace name and the service ID
:raises oio.common.exceptions.OioException: when the specified path
does not belong to a rawx service or misses some attributes.
"""
return check_volume_for_service_type(volume_path, "rawx")
[docs]def check_volume_for_service_type(volume_path, required_type):
"""
Check if `volume_path` points to a directory for the specified service
type.
:returns: the namespace name and the service ID
:raises oio.common.exceptions.OioException: when the specified path
does not belong to a service from the specified type or is missing
some attributes.
"""
msg_pfx = 'Invalid volume path [%s]: ' % volume_path
meta = read_user_xattr(volume_path)
server_type = meta.get(volume_xattr_keys['type'])
if server_type is None:
raise exc.OioException(msg_pfx + 'missing %s xattr' %
volume_xattr_keys['type'])
if server_type != required_type:
raise exc.OioException(
msg_pfx + 'service is a {0}, not a {1}'.format(server_type,
required_type))
namespace = meta.get(volume_xattr_keys['namespace'])
server_id = meta.get(volume_xattr_keys['id'])
if server_id is None:
raise exc.OioException(msg_pfx + 'missing %s xattr' %
volume_xattr_keys['id'])
elif namespace is None:
raise exc.OioException(msg_pfx + 'missing %s xattr' %
volume_xattr_keys['namespace'])
return namespace, server_id