def _create_logical_volume(self, size): """Creates a logical volume with a minimum size. :param size: size of the logical volume in bytes :returns: string -- the name of the new logical volume. :raises: PowerVMNoSpaceLeftOnVolumeGroup """ vgs = self.run_vios_command(self.command.lsvg()) cmd = self.command.lsvg('%s -field vgname freepps -fmt :' % ' '.join(vgs)) output = self.run_vios_command(cmd) found_vg = None # If it's not a multiple of 1MB we get the next # multiple and use it as the megabyte_size. megabyte = 1024 * 1024 if (size % megabyte) != 0: megabyte_size = int(size / megabyte) + 1 else: megabyte_size = size / megabyte # Search for a volume group with enough free space for # the new logical volume. for vg in output: # Returned output example: 'rootvg:396 (25344 megabytes)' match = re.search(r'^(\w+):\d+\s\((\d+).+$', vg) if match is None: continue vg_name, avail_size = match.groups() if megabyte_size <= int(avail_size): found_vg = vg_name break if not found_vg: LOG.error( _('Could not create logical volume. ' 'No space left on any volume group.')) raise exception.PowerVMNoSpaceLeftOnVolumeGroup() cmd = self.command.mklv('%s %sB' % (found_vg, size / 512)) lv_name = self.run_vios_command(cmd)[0] return lv_name
def fake_create_logical_volume(size): raise exception.PowerVMNoSpaceLeftOnVolumeGroup()