예제 #1
0
    def _new_mdarray(self, members, raid_name=""):

        if raid_name == "":
            raid_name = self._spec_dict["name"]

        # calculate and verify active and spare devices counts
        active_count = len(members)
        spare_count = 0

        requested_actives = self._spec_dict.get("raid_device_count")
        requested_spares = self._spec_dict.get("raid_spare_count")

        if requested_actives is not None and requested_spares is not None:
            if (requested_actives + requested_spares != len(members)
                    or requested_actives < 0 or requested_spares < 0):
                raise BlivetAnsibleError(
                    "failed to set up '%s': cannot create RAID "
                    "with %s members (%s active and %s spare)" %
                    (self._spec_dict["name"], len(members), requested_actives,
                     requested_spares))

        if requested_actives is not None:
            active_count = requested_actives
            spare_count = len(members) - active_count

        if requested_spares is not None:
            spare_count = requested_spares
            active_count = len(members) - spare_count

        # get chunk_size
        chunk_size = self._spec_dict.get("raid_chunk_size")
        chunk_size = Size(chunk_size) if chunk_size is not None else None

        # chunk size should be divisible by 4 KiB but mdadm ignores that. why?
        if chunk_size is not None and chunk_size % Size("4 KiB") != Size(0):
            raise BlivetAnsibleError("chunk size must be multiple of 4 KiB")

        try:
            raid_array = self._blivet.new_mdarray(
                name=raid_name,
                level=self._spec_dict["raid_level"],
                member_devices=active_count,
                total_devices=len(members),
                parents=members,
                chunk_size=chunk_size,
                metadata_version=self._spec_dict.get("raid_metadata_version"),
                fmt=self._get_format())
        except ValueError as e:
            raise BlivetAnsibleError("cannot create RAID '%s': %s" %
                                     (raid_name, str(e)))

        return raid_array
예제 #2
0
    def _create(self):
        if self._device:
            return

        parent = self._blivet_pool._device
        if parent is None:
            raise BlivetAnsibleError(
                "failed to find pool '%s' for volume '%s'" %
                (self._blivet_pool['name'], self._volume['name']))

        try:
            size = Size(self._volume['size'])
        except Exception:
            raise BlivetAnsibleError(
                "invalid size '%s' specified for volume '%s'" %
                (self._volume['size'], self._volume['name']))

        fmt = self._get_format()
        if size > parent.free_space:
            raise BlivetAnsibleError(
                "specified size for volume '%s' exceeds available space in pool '%s' (%s)"
                % (size, parent.name, parent.free_space))

        try:
            device = self._blivet.new_lv(name=self._volume['name'],
                                         parents=[parent],
                                         size=size,
                                         fmt=fmt)
        except Exception:
            raise BlivetAnsibleError("failed to set up volume '%s'" %
                                     self._volume['name'])

        self._blivet.create_device(device)
        self._device = device
예제 #3
0
    def _create(self):
        if self._device:
            return

        if self._blivet_pool:
            parent = self._blivet_pool._device
        else:
            parent = self._blivet.devicetree.resolve_device(
                self._volume['pool'])

        if parent is None:
            raise BlivetAnsibleError(
                "failed to find pool '%s' for volume '%s'" %
                (self._blivet_pool['name'], self._volume['name']))

        size = Size("256 MiB")
        try:
            device = self._blivet.new_partition(parents=[parent],
                                                size=size,
                                                grow=True,
                                                fmt=self._get_format())
        except Exception:
            raise BlivetAnsibleError("failed set up volume '%s'" %
                                     self._volume['name'])

        self._blivet.create_device(device)
        try:
            do_partitioning(self._blivet)
        except Exception:
            raise BlivetAnsibleError(
                "partition allocation failed for volume '%s'" %
                self._volume['name'])

        self._device = device
예제 #4
0
    def _resize(self):
        """ Schedule actions as needed to ensure the device has the desired size. """
        try:
            size = Size(self._volume['size'])
        except Exception:
            raise BlivetAnsibleError(
                "invalid size specification for volume '%s': '%s'" %
                (self._volume['name'], self._volume['size']))

        if size and self._device.size != size:
            try:
                self._device.format.update_size_info()
            except AttributeError:
                pass

            if not self._device.resizable:
                return

            if self._device.format.resizable:
                self._device.format.update_size_info()

            if not self._device.min_size <= size <= self._device.max_size:
                raise BlivetAnsibleError(
                    "volume '%s' cannot be resized to '%s'" %
                    (self._volume['name'], size))

            try:
                self._blivet.resize_device(self._device, size)
            except ValueError as e:
                raise BlivetAnsibleError(
                    "volume '%s' cannot be resized from %s to %s: %s" %
                    (self._device.name, self._device.size, size, str(e)))
예제 #5
0
파일: blivet.py 프로젝트: manngupta/storage
    def _create_members(self):
        """ Schedule actions as needed to ensure pool member devices exist. """
        members = list()
        for disk in self._disks:
            if not disk.isleaf or disk.format.type is not None:
                if safe_mode and not packages_only:
                    raise BlivetAnsibleError("cannot remove existing formatting and/or devices on disk '%s' (pool '%s') in safe mode" % (disk.name, self._pool['name']))
                else:
                    self._blivet.devicetree.recursive_remove(disk)

            if use_partitions:
                label = get_format("disklabel", device=disk.path)
                self._blivet.format_device(disk, label)
                member = self._blivet.new_partition(parents=[disk], size=Size("256MiB"), grow=True)
                self._blivet.create_device(member)
            else:
                member = disk

            self._blivet.format_device(member, self._get_format())
            members.append(member)

        if use_partitions:
            try:
                do_partitioning(self._blivet)
            except Exception:
                raise BlivetAnsibleError("failed to allocation partitions for pool '%s'" % self._pool['name'])

        return members
    def _create_members(self):
        """ Schedule actions as needed to ensure pool member devices exist. """
        members = list()
        for disk in self._disks:
            if not disk.isleaf:
                self._blivet.devicetree.recursive_remove(disk)

            if use_partitions:
                label = get_format("disklabel", device=disk.path)
                self._blivet.format_device(disk, label)
                member = self._blivet.new_partition(parents=[disk], size=Size("256MiB"), grow=True)
                self._blivet.create_device(member)
            else:
                member = disk

            self._blivet.format_device(member, self._get_format())
            members.append(member)

        if use_partitions:
            try:
                do_partitioning(self._blivet)
            except Exception:
                # FAIL: problem allocating partitions for pool backing devices
                raise BlivetAnsibleError("failed to allocation partitions for pool '%s'" % self._pool['name'])

        return members
예제 #7
0
파일: blivet.py 프로젝트: vidurous/storage
    def _create(self):
        global safe_mode

        if self._device:
            return

        raid_name = self._volume["name"]
        member_names = self._volume["disks"]
        raid_level = self._volume["raid_level"]
        members_count, active_count = self._process_device_numbers(len(member_names),
                                                                   self._volume.get("raid_device_count"),
                                                                   self._volume.get("raid_spare_count"))

        chunk_size = Size(self._volume.get("raid_chunk_size", MD_CHUNK_SIZE))
        metadata_version = self._volume.get("raid_metadata_version", "default")

        # chunk size should be divisible by 4 KiB but mdadm ignores that. why?
        if chunk_size % Size("4 KiB") != Size(0):
            raise BlivetAnsibleError("chunk size must be multiple of 4 KiB")

        if safe_mode:
            raise BlivetAnsibleError("cannot create new RAID '%s' in safe mode" % safe_mode)

        # begin creating the devices
        members = self._create_raid_members(member_names)

        if use_partitions:
            try:
                do_partitioning(self._blivet)
            except Exception as e:
                raise BlivetAnsibleError("failed to allocate partitions for mdraid '%s': %s" % (raid_name, str(e)))

        try:
            raid_array = self._blivet.new_mdarray(name=raid_name,
                                                  level=raid_level,
                                                  member_devices=active_count,
                                                  total_devices=members_count,
                                                  parents=members,
                                                  chunk_size=chunk_size,
                                                  metadata_version=metadata_version,
                                                  fmt=self._get_format())
        except ValueError as e:
            raise BlivetAnsibleError("cannot create RAID '%s': %s" % (raid_name, str(e)))

        self._blivet.create_device(raid_array)

        self._device = raid_array
예제 #8
0
파일: blivet.py 프로젝트: vidurous/storage
    def _create_members(self):
        """ Schedule actions as needed to ensure pool member devices exist. """
        members = list()

        for disk in self._disks:
            if not disk.isleaf or disk.format.type is not None:
                if safe_mode:
                    raise BlivetAnsibleError("cannot remove existing formatting and/or devices on disk '%s' (pool '%s') in safe mode" % (disk.name, self._pool['name']))
                else:
                    self._blivet.devicetree.recursive_remove(disk)

            if use_partitions:
                label = get_format("disklabel", device=disk.path)
                self._blivet.format_device(disk, label)
                member = self._blivet.new_partition(parents=[disk], size=Size("256MiB"), grow=True)
                self._blivet.create_device(member)
            else:
                member = disk

            if self._is_raid:
                self._blivet.format_device(member, fmt=get_format("mdmember"))
            else:
                self._blivet.format_device(member, self._get_format())
            members.append(member)


        if self._is_raid:
            raid_name = "%s-1" % self._pool['name']
            raid_level = self._pool['raid_level']

            try:
                raid_array = self._blivet.new_mdarray(name=raid_name, level=raid_level,
                                                  member_devices=len(members),
                                                  total_devices=(len(members)),
                                                  parents=members,
                                                  fmt=self._get_format())
            except ValueError as e:
                raise BlivetAnsibleError("cannot create RAID '%s': %s" % (raid_name, str(e)))

            self._blivet.create_device(raid_array)
            result = [raid_array]
        else:
            result = members

        if use_partitions:
            try:
                do_partitioning(self._blivet)
            except Exception:
                raise BlivetAnsibleError("failed to allocate partitions for pool '%s'" % self._pool['name'])

        return result