def _extract_bytes(self, details): # Replace it with the byte amount real_size = self.SIZE_RE.search(details) if real_size: details = real_size.group(1) try: details = strutils.to_bytes(details) except TypeError: pass return details
def _calculate_count(size_in_m, blocksize): # Check if volume_dd_blocksize is valid try: # Rule out zero-sized/negative dd blocksize which # cannot be caught by strutils if blocksize.startswith(('-', '0')): raise ValueError bs = strutils.to_bytes(blocksize) except (ValueError, TypeError): msg = (_("Incorrect value error: %(blocksize)s, " "it may indicate that \'volume_dd_blocksize\' " "was configured incorrectly. Fall back to default.") % {'blocksize': blocksize}) LOG.warn(msg) # Fall back to default blocksize CONF.clear_override('volume_dd_blocksize') blocksize = CONF.volume_dd_blocksize bs = strutils.to_bytes(blocksize) count = math.ceil(size_in_m * units.MiB / float(bs)) return blocksize, int(count)
def _calculate_count(self, blocksize, size_in_g): # Check if volume_dd_blocksize is valid try: # Rule out zero-sized/negative dd blocksize which # cannot be caught by strutils if blocksize.startswith(("-", "0")): raise ValueError bs = strutils.to_bytes(blocksize) except (ValueError, TypeError): msg = _( "Incorrect value error: %(blocksize)s, " "it may indicate that 'volume_dd_blocksize' " "was configured incorrectly. Fall back to default." ) % {"blocksize": blocksize} LOG.warn(msg) # Fall back to default blocksize CONF.clear_override("volume_dd_blocksize", self.configuration.config_group) blocksize = self.configuration.volume_dd_blocksize bs = strutils.to_bytes(blocksize) count = math.ceil(size_in_g * units.GiB / float(bs)) return blocksize, int(count)
def _calculate_count(size_in_m): blocksize = CONF.volume_dd_blocksize # Check if volume_dd_blocksize is valid try: # Rule out zero-sized/negative dd blocksize which # cannot be caught by strutils if blocksize.startswith(('-', '0')): raise ValueError bs = strutils.to_bytes(blocksize) except (ValueError, TypeError): msg = (_("Incorrect value error: %(blocksize)s, " "it may indicate that \'volume_dd_blocksize\' " "was configured incorrectly. Fall back to default.") % { 'blocksize': blocksize }) LOG.warn(msg) # Fall back to default blocksize CONF.clear_override('volume_dd_blocksize') blocksize = CONF.volume_dd_blocksize bs = strutils.to_bytes(blocksize) count = math.ceil(size_in_m * units.MiB / float(bs)) return blocksize, int(count)