import eventlet
from oslo_config import cfg
from oslo_log import log as logging
-from oslo_utils import encodeutils
from oslo_utils import excutils
from oslo_utils import units
from six.moves import range
@property
def name(self):
- return encodeutils.safe_encode("backup.%s.meta" % self._backup_id)
+ return utils.convert_str("backup.%s.meta" % self._backup_id)
@property
def exists(self):
self.rbd_stripe_count = 0
self.rbd_stripe_unit = 0
- self._ceph_backup_user = encodeutils.safe_encode(CONF.backup_ceph_user)
- self._ceph_backup_pool = encodeutils.safe_encode(CONF.backup_ceph_pool)
- self._ceph_backup_conf = encodeutils.safe_encode(CONF.backup_ceph_conf)
+ self._ceph_backup_user = utils.convert_str(CONF.backup_ceph_user)
+ self._ceph_backup_pool = utils.convert_str(CONF.backup_ceph_pool)
+ self._ceph_backup_conf = utils.convert_str(CONF.backup_ceph_conf)
def _validate_string_args(self, *args):
"""Ensure all args are non-None and non-empty."""
conffile=self._ceph_backup_conf)
try:
client.connect()
- pool_to_open = encodeutils.safe_encode(pool or
- self._ceph_backup_pool)
+ pool_to_open = utils.convert_str(pool or self._ceph_backup_pool)
ioctx = client.open_ioctx(pool_to_open)
return client, ioctx
except self.rados.Error:
"""
# Ensure no unicode
if diff_format:
- return encodeutils.safe_encode("volume-%s.backup.base" % volume_id)
+ return utils.convert_str("volume-%s.backup.base" % volume_id)
else:
if backup_id is None:
msg = _("Backup id required")
raise exception.InvalidParameterValue(msg)
- return encodeutils.safe_encode("volume-%s.backup.%s" %
- (volume_id, backup_id))
+ return utils.convert_str("volume-%s.backup.%s"
+ % (volume_id, backup_id))
def _discard_bytes(self, volume, offset, length):
"""Trim length bytes from offset.
# Since we have deleted the base image we can delete the source
# volume backup snapshot.
- src_name = encodeutils.safe_encode(volume_id)
+ src_name = utils.convert_str(volume_id)
if src_name in self.rbd.RBD().list(client.ioctx):
LOG.debug("Deleting source volume snapshot '%(snapshot)s' "
"for backup %(basename)s.",
if from_snap is not None:
cmd1.extend(['--from-snap', from_snap])
if src_snap:
- path = encodeutils.safe_encode("%s/%s@%s" %
- (src_pool, src_name, src_snap))
+ path = utils.convert_str("%s/%s@%s"
+ % (src_pool, src_name, src_snap))
else:
- path = encodeutils.safe_encode("%s/%s" % (src_pool, src_name))
-
+ path = utils.convert_str("%s/%s" % (src_pool, src_name))
cmd1.extend([path, '-'])
cmd2 = ['rbd', 'import-diff'] + dest_ceph_args
- rbd_path = encodeutils.safe_encode("%s/%s" % (dest_pool, dest_name))
+ rbd_path = utils.convert_str("%s/%s" % (dest_pool, dest_name))
cmd2.extend(['-', rbd_path])
ret, stderr = self._piped_execute(cmd1, cmd2)
return backup_snaps
def _get_new_snap_name(self, backup_id):
- return encodeutils.safe_encode("backup.%s.snap.%s" %
- (backup_id, time.time()))
+ return utils.convert_str("backup.%s.snap.%s"
+ % (backup_id, time.time()))
def _get_backup_snap_name(self, rbd_image, name, backup_id):
"""Return the name of the snapshot associated with backup_id.
with rbd_driver.RADOSClient(self, self._ceph_backup_pool) as client:
adjust_size = 0
base_image = self.rbd.Image(client.ioctx,
- encodeutils.safe_encode(backup_base),
+ utils.convert_str(backup_base),
read_only=True)
try:
if restore_length != base_image.size():
if adjust_size:
with rbd_driver.RADOSClient(self, src_pool) as client:
- restore_vol_encode = encodeutils.safe_encode(restore_vol)
+ restore_vol_encode = utils.convert_str(restore_vol)
dest_image = self.rbd.Image(client.ioctx, restore_vol_encode)
try:
LOG.debug("Adjusting restore vol size")
from eventlet import tpool
from oslo_config import cfg
from oslo_log import log as logging
-from oslo_utils import encodeutils
from oslo_utils import units
import six
from six.moves import urllib
"""RBD image metadata to be used with RBDImageIOWrapper."""
def __init__(self, image, pool, user, conf):
self.image = image
- self.pool = encodeutils.safe_encode(pool)
- self.user = encodeutils.safe_encode(user)
- self.conf = encodeutils.safe_encode(conf)
+ self.pool = utils.convert_str(pool)
+ self.user = utils.convert_str(user)
+ self.conf = utils.convert_str(conf)
class RBDImageIOWrapper(io.RawIOBase):
read_only=False):
client, ioctx = driver._connect_to_rados(pool)
if snapshot is not None:
- snapshot = encodeutils.safe_encode(snapshot)
+ snapshot = utils.convert_str(snapshot)
try:
self.volume = driver.rbd.Image(ioctx,
- encodeutils.safe_encode(name),
+ utils.convert_str(name),
snapshot=snapshot,
read_only=read_only)
except driver.rbd.Error:
'rbd_ceph_conf', 'rbd_pool']:
val = getattr(self.configuration, attr)
if val is not None:
- setattr(self.configuration, attr, encodeutils.safe_encode(val))
+ setattr(self.configuration, attr, utils.convert_str(val))
def check_for_setup_error(self):
"""Returns an error if prerequisites aren't met."""
clustername=self.configuration.rbd_cluster_name,
conffile=self.configuration.rbd_ceph_conf))
if pool is not None:
- pool = encodeutils.safe_encode(pool)
+ pool = utils.convert_str(pool)
else:
pool = self.configuration.rbd_pool
pool['name'] ==
self.configuration.rbd_pool][0]['stats']
stats['free_capacity_gb'] = (
- pool_stats['max_avail'] / units.Gi)
- used_capacity_gb = pool_stats['bytes_used'] / units.Gi
+ pool_stats['max_avail'] // units.Gi)
+ used_capacity_gb = pool_stats['bytes_used'] // units.Gi
stats['total_capacity_gb'] = (stats['free_capacity_gb']
+ used_capacity_gb)
except self.rados.Error:
and that clone has rbd_max_clone_depth clones behind it, the source
volume will be flattened.
"""
- src_name = encodeutils.safe_encode(src_vref['name'])
- dest_name = encodeutils.safe_encode(volume['name'])
+ src_name = utils.convert_str(src_vref['name'])
+ dest_name = utils.convert_str(volume['name'])
flatten_parent = False
# Do full copy if requested
with RADOSClient(self) as client:
self.RBDProxy().create(client.ioctx,
- encodeutils.safe_encode(volume['name']),
+ utils.convert_str(volume['name']),
size,
order,
old_format=False,
with RADOSClient(self, src_pool) as src_client:
with RADOSClient(self) as dest_client:
self.RBDProxy().clone(src_client.ioctx,
- encodeutils.safe_encode(src_image),
- encodeutils.safe_encode(src_snap),
+ utils.convert_str(src_image),
+ utils.convert_str(src_snap),
dest_client.ioctx,
- encodeutils.safe_encode(volume['name']),
+ utils.convert_str(volume['name']),
features=src_client.features)
def _resize(self, volume, **kwargs):
"""Deletes a logical volume."""
# NOTE(dosaboy): this was broken by commit cbe1d5f. Ensure names are
# utf-8 otherwise librbd will barf.
- volume_name = encodeutils.safe_encode(volume['name'])
+ volume_name = utils.convert_str(volume['name'])
with RADOSClient(self) as client:
try:
rbd_image = self.rbd.Image(client.ioctx, volume_name)
def create_snapshot(self, snapshot):
"""Creates an rbd snapshot."""
with RBDVolumeProxy(self, snapshot['volume_name']) as volume:
- snap = encodeutils.safe_encode(snapshot['name'])
+ snap = utils.convert_str(snapshot['name'])
volume.create_snap(snap)
volume.protect_snap(snap)
"""Deletes an rbd snapshot."""
# NOTE(dosaboy): this was broken by commit cbe1d5f. Ensure names are
# utf-8 otherwise librbd will barf.
- volume_name = encodeutils.safe_encode(snapshot['volume_name'])
- snap_name = encodeutils.safe_encode(snapshot['name'])
+ volume_name = utils.convert_str(snapshot['volume_name'])
+ snap_name = utils.convert_str(snapshot['name'])
with RBDVolumeProxy(self, volume_name) as volume:
try:
volume.unprotect_snap(snap_name)
if not location.startswith(prefix):
reason = _('Not stored in rbd')
raise exception.ImageUnacceptable(image_id=location, reason=reason)
- pieces = map(urllib.parse.unquote, location[len(prefix):].split('/'))
+ pieces = [urllib.parse.unquote(loc)
+ for loc in location[len(prefix):].split('/')]
if any(map(lambda p: p == '', pieces)):
reason = _('Blank components')
raise exception.ImageUnacceptable(image_id=location, reason=reason)
with RADOSClient(self) as client:
rbd_name = existing_ref['source-name']
self.RBDProxy().rename(client.ioctx,
- encodeutils.safe_encode(rbd_name),
- encodeutils.safe_encode(volume['name']))
+ utils.convert_str(rbd_name),
+ utils.convert_str(volume['name']))
def manage_existing_get_size(self, volume, existing_ref):
"""Return size of an existing image for manage_existing.
raise exception.ManageExistingInvalidReference(
existing_ref=existing_ref, reason=reason)
- rbd_name = encodeutils.safe_encode(existing_ref['source-name'])
+ rbd_name = utils.convert_str(existing_ref['source-name'])
with RADOSClient(self) as client:
# Raise an exception if we didn't find a suitable rbd image.