Пример #1
0
    def _create_btrfs_volume(self, user_input):
        actions = []
        device_name = self._pick_device_name(user_input.name)

        for parent, size in user_input.parents:
            # _create_partition needs user_input but we actually don't have it for individual
            # parent partitions so we need to 'create' it
            part_input = ProxyDataContainer(size=size,
                                            parents=[(parent, size)],
                                            filesystem="btrfs",
                                            encrypt=False,
                                            label=None,
                                            mountpoint=None,
                                            create_volume=False)
            part_actions = self._create_partition(part_input)

            # we need to try to create partitions immediately, if something
            # fails, fail now
            for ac in part_actions:
                self.storage.devicetree.actions.add(ac)
            actions.extend(part_actions)

        btrfs_parents = [ac.device for ac in actions if (ac.is_format and ac.is_create) and ac._format.type == "btrfs"]
        new_btrfs = BTRFSVolumeDevice(device_name, parents=btrfs_parents)
        new_btrfs.format = blivet.formats.get_format("btrfs", label=device_name, mountpoint=user_input.mountpoint)
        actions.append(blivet.deviceaction.ActionCreateDevice(new_btrfs))

        return actions
Пример #2
0
    def _create_btrfs_format(self, user_input, device):
        actions = []

        # format the device to btrfs
        btrfs_fmt = blivet.formats.get_format(fmt_type="btrfs")
        actions.append(blivet.deviceaction.ActionCreateFormat(device, btrfs_fmt))

        if getattr(user_input, "create_volume", True):
            device.format = btrfs_fmt
            new_btrfs = BTRFSVolumeDevice(parents=[device])
            new_btrfs.format = blivet.formats.get_format("btrfs", label=user_input.label, mountpoint=user_input.mountpoint)
            actions.append(blivet.deviceaction.ActionCreateDevice(new_btrfs))

        return actions
Пример #3
0
    def add_device(self, user_input):
        """ Create new device

            :param user_input: selected parameters from AddDialog
            :type user_input: class UserInput
            :returns: new device name
            :rtype: str

        """

        actions = []

        if user_input.device_type == "partition":

            if user_input.encrypt:
                dev = PartitionDevice(
                    name="req%d" % self.storage.nextID,
                    size=user_input.size,
                    parents=[i[0] for i in user_input.parents])
                actions.append(blivet.deviceaction.ActionCreateDevice(dev))

                fmt = blivet.formats.getFormat(
                    fmt_type="luks",
                    passphrase=user_input.passphrase,
                    device=dev.path)
                actions.append(blivet.deviceaction.ActionCreateFormat(
                    dev, fmt))

                luks_dev = LUKSDevice("luks-%s" % dev.name,
                                      fmt=blivet.formats.getFormat(
                                          user_input.filesystem,
                                          device=dev.path,
                                          mountpoint=user_input.mountpoint),
                                      size=dev.size,
                                      parents=[dev])

                actions.append(
                    blivet.deviceaction.ActionCreateDevice(luks_dev))

            else:
                new_part = PartitionDevice(
                    name="req%d" % self.storage.nextID,
                    size=user_input.size,
                    parents=[i[0] for i in user_input.parents],
                    partType=PARTITION_TYPE[user_input.advanced["parttype"]])

                actions.append(
                    blivet.deviceaction.ActionCreateDevice(new_part))

                if user_input.advanced["parttype"] != "extended":
                    new_fmt = blivet.formats.getFormat(
                        fmt_type=user_input.filesystem,
                        label=user_input.label,
                        mountpoint=user_input.mountpoint)

                    actions.append(
                        blivet.deviceaction.ActionCreateFormat(
                            new_part, new_fmt))

        elif user_input.device_type == "lvm" and not user_input.encrypt:

            device_name = self._pick_device_name(user_input.name)

            pvs = []

            # exact total size of newly created pvs (future parents)
            total_size = blivet.size.Size("0 MiB")

            for parent, size in user_input.parents:

                dev = PartitionDevice(name="req%d" % self.storage.nextID,
                                      size=size,
                                      parents=parent)
                ac_part = blivet.deviceaction.ActionCreateDevice(dev)

                fmt = blivet.formats.getFormat(fmt_type="lvmpv")
                ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt)

                actions.extend([ac_part, ac_fmt])

                total_size += dev.size

                # we need to try to create pvs immediately, if something
                # fails, fail now
                try:
                    for ac in (ac_part, ac_fmt):
                        self.storage.devicetree.registerAction(ac)

                except blivet.errors.PartitioningError as e:
                    return ReturnList(success=False,
                                      actions=None,
                                      message=None,
                                      exception=e,
                                      traceback=sys.exc_info()[2])

                pvs.append(dev)

            new_vg = LVMVolumeGroupDevice(size=total_size,
                                          parents=pvs,
                                          name=device_name,
                                          peSize=user_input.advanced["pesize"])

            actions.append(blivet.deviceaction.ActionCreateDevice(new_vg))

        elif user_input.device_type == "lvm" and user_input.encrypt:

            device_name = self._pick_device_name(user_input.name)

            lukses = []

            # exact total size of newly created pvs (future parents)
            total_size = blivet.size.Size("0 MiB")

            for parent, size in user_input.parents:
                dev = PartitionDevice(name="req%d" % self.storage.nextID,
                                      size=user_input.size,
                                      parents=[parent])
                ac_part = blivet.deviceaction.ActionCreateDevice(dev)

                fmt = blivet.formats.getFormat(
                    fmt_type="luks",
                    passphrase=user_input.passphrase,
                    device=dev.path)
                ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt)

                luks_dev = LUKSDevice("luks-%s" % dev.name,
                                      fmt=blivet.formats.getFormat(
                                          "lvmpv", device=dev.path),
                                      size=dev.size,
                                      parents=[dev])
                ac_luks = blivet.deviceaction.ActionCreateDevice(luks_dev)

                actions.extend([ac_part, ac_fmt, ac_luks])

                total_size += luks_dev.size

                # we need to try to create pvs immediately, if something
                # fails, fail now
                try:
                    for ac in (ac_part, ac_fmt, ac_luks):
                        self.storage.devicetree.registerAction(ac)

                except blivet.errors.PartitioningError as e:
                    return ReturnList(success=False,
                                      actions=None,
                                      message=None,
                                      exception=e,
                                      traceback=sys.exc_info()[2])

                lukses.append(luks_dev)

            new_vg = LVMVolumeGroupDevice(size=total_size,
                                          parents=lukses,
                                          name=device_name,
                                          peSize=user_input.advanced["pesize"])

            actions.append(blivet.deviceaction.ActionCreateDevice(new_vg))

        elif user_input.device_type == "lvmlv":

            device_name = self._pick_device_name(user_input.name,
                                                 user_input.parents[0][0])

            new_part = LVMLogicalVolumeDevice(
                name=device_name,
                size=user_input.size,
                parents=[i[0] for i in user_input.parents])

            actions.append(blivet.deviceaction.ActionCreateDevice(new_part))

            new_fmt = blivet.formats.getFormat(
                fmt_type=user_input.filesystem,
                mountpoint=user_input.mountpoint)

            actions.append(
                blivet.deviceaction.ActionCreateFormat(new_part, new_fmt))

        elif user_input.device_type == "lvmvg":

            device_name = self._pick_device_name(user_input.name)

            new_vg = LVMVolumeGroupDevice(
                size=user_input.size,
                name=device_name,
                parents=[i[0] for i in user_input.parents],
                peSize=user_input.advanced["pesize"])

            actions.append(blivet.deviceaction.ActionCreateDevice(new_vg))

        elif user_input.device_type == "lvmpv":

            if user_input.encrypt:

                dev = PartitionDevice(
                    name="req%d" % self.storage.nextID,
                    size=user_input.size,
                    parents=[i[0] for i in user_input.parents])
                actions.append(blivet.deviceaction.ActionCreateDevice(dev))

                fmt = blivet.formats.getFormat(
                    fmt_type="luks",
                    passphrase=user_input.passphrase,
                    device=dev.path)
                actions.append(blivet.deviceaction.ActionCreateFormat(
                    dev, fmt))

                luks_dev = LUKSDevice("luks-%s" % dev.name,
                                      fmt=blivet.formats.getFormat(
                                          "lvmpv", device=dev.path),
                                      size=dev.size,
                                      parents=[dev])
                actions.append(
                    blivet.deviceaction.ActionCreateDevice(luks_dev))

            else:
                dev = PartitionDevice(
                    name="req%d" % self.storage.nextID,
                    size=user_input.size,
                    parents=[i[0] for i in user_input.parents])
                actions.append(blivet.deviceaction.ActionCreateDevice(dev))

                fmt = blivet.formats.getFormat(fmt_type="lvmpv")
                actions.append(blivet.deviceaction.ActionCreateFormat(
                    dev, fmt))

        elif user_input.device_type == "btrfs volume":

            device_name = self._pick_device_name(user_input.name)

            # for btrfs we need to create parents first -- currently selected "parents" are
            # disks but "real parents" for subvolume are btrfs formatted partitions
            btrfs_parents = []

            # exact total size of newly created partitions (future parents)
            total_size = blivet.size.Size("0 MiB")

            for parent, size in user_input.parents:

                if user_input.btrfs_type == "disks":
                    assert parent.isDisk

                    fmt = blivet.formats.getFormat(fmt_type="btrfs")
                    ac_fmt = blivet.deviceaction.ActionCreateFormat(
                        parent, fmt)

                    actions.append(ac_fmt)

                    try:
                        self.storage.devicetree.registerAction(ac_fmt)

                    except Exception as e:  # pylint: disable=broad-except
                        return ReturnList(success=False,
                                          actions=None,
                                          message=None,
                                          exception=e,
                                          traceback=sys.exc_info()[2])

                    total_size += size
                    btrfs_parents.append(parent)

                else:

                    dev = PartitionDevice(name="req%d" % self.storage.nextID,
                                          size=size,
                                          parents=[parent])
                    ac_part = blivet.deviceaction.ActionCreateDevice(dev)

                    fmt = blivet.formats.getFormat(fmt_type="btrfs")
                    ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt)

                    actions.extend([ac_part, ac_fmt])

                    total_size += dev.size

                    # we need to try to create partitions immediately, if something
                    # fails, fail now
                    try:
                        for ac in (ac_part, ac_fmt):
                            self.storage.devicetree.registerAction(ac)

                    except blivet.errors.PartitioningError as e:
                        return ReturnList(success=False,
                                          actions=None,
                                          message=None,
                                          exception=e,
                                          traceback=sys.exc_info()[2])

                    btrfs_parents.append(dev)

            new_btrfs = BTRFSVolumeDevice(device_name,
                                          size=total_size,
                                          parents=btrfs_parents)
            new_btrfs.format = blivet.formats.getFormat(
                "btrfs", label=device_name, mountpoint=user_input.mountpoint)
            actions.append(blivet.deviceaction.ActionCreateDevice(new_btrfs))

        elif user_input.device_type == "btrfs subvolume":

            device_name = self._pick_device_name(user_input.name,
                                                 user_input.parents[0][0])

            new_btrfs = BTRFSSubVolumeDevice(
                device_name, parents=[i[0] for i in user_input.parents])
            new_btrfs.format = blivet.formats.getFormat(
                "btrfs", mountpoint=user_input.mountpoint)
            actions.append(blivet.deviceaction.ActionCreateDevice(new_btrfs))

        elif user_input.device_type == "mdraid":
            device_name = self._pick_device_name(user_input.name)

            parts = []

            # exact total size of newly created pvs (future parents)
            total_size = blivet.size.Size("0 MiB")

            for parent, size in user_input.parents:

                dev = PartitionDevice(name="req%d" % self.storage.nextID,
                                      size=size,
                                      parents=[parent])
                ac_part = blivet.deviceaction.ActionCreateDevice(dev)

                fmt = blivet.formats.getFormat(fmt_type="mdmember")
                ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt)

                actions.extend([ac_part, ac_fmt])

                total_size += dev.size

                # we need to try to create pvs immediately, if something
                # fails, fail now
                try:
                    for ac in (ac_part, ac_fmt):
                        self.storage.devicetree.registerAction(ac)

                except blivet.errors.PartitioningError as e:
                    return ReturnList(success=False,
                                      actions=None,
                                      message=None,
                                      exception=e,
                                      traceback=sys.exc_info()[2])

                parts.append(dev)

            new_md = MDRaidArrayDevice(size=total_size,
                                       parents=parts,
                                       name=device_name,
                                       level=user_input.raid_level,
                                       memberDevices=len(parts),
                                       totalDevices=len(parts))
            actions.append(blivet.deviceaction.ActionCreateDevice(new_md))

            fmt = blivet.formats.getFormat(fmt_type=user_input.filesystem)
            actions.append(blivet.deviceaction.ActionCreateFormat(new_md, fmt))

        try:
            for ac in actions:
                if not ac._applied:
                    self.storage.devicetree.registerAction(ac)

            blivet.partitioning.doPartitioning(self.storage)

        except Exception as e:  # pylint: disable=broad-except
            return ReturnList(success=False,
                              actions=None,
                              message=None,
                              exception=e,
                              traceback=sys.exc_info()[2])

        return ReturnList(success=True,
                          actions=actions,
                          message=None,
                          exception=None,
                          traceback=None)
Пример #4
0
    def add_device(self, user_input):
        """ Create new device

            :param user_input: selected parameters from AddDialog
            :type user_input: class UserInput
            :returns: new device name
            :rtype: str

        """

        actions = []

        if user_input.device_type == "partition":

            if user_input.encrypt:
                dev = PartitionDevice(name="req%d" % self.storage.nextID,
                    size=user_input.size,
                    parents=[i[0] for i in user_input.parents])
                actions.append(blivet.deviceaction.ActionCreateDevice(dev))

                fmt = blivet.formats.getFormat(fmt_type="luks", passphrase=user_input.passphrase, device=dev.path)
                actions.append(blivet.deviceaction.ActionCreateFormat(dev, fmt))

                luks_dev = LUKSDevice("luks-%s" % dev.name,
                    fmt=blivet.formats.getFormat(user_input.filesystem, device=dev.path,
                        mountpoint=user_input.mountpoint), size=dev.size, parents=[dev])

                actions.append(blivet.deviceaction.ActionCreateDevice(luks_dev))

            else:
                new_part = PartitionDevice(name="req%d" % self.storage.nextID,
                    size=user_input.size, parents=[i[0] for i in user_input.parents],
                    partType=PARTITION_TYPE[user_input.advanced["parttype"]])

                actions.append(blivet.deviceaction.ActionCreateDevice(new_part))

                if user_input.advanced["parttype"] != "extended":
                    new_fmt = blivet.formats.getFormat(fmt_type=user_input.filesystem,
                        label=user_input.label, mountpoint=user_input.mountpoint)

                    actions.append(blivet.deviceaction.ActionCreateFormat(new_part, new_fmt))

        elif user_input.device_type == "lvm" and not user_input.encrypt:

            device_name = self._pick_device_name(user_input.name)

            pvs = []

            # exact total size of newly created pvs (future parents)
            total_size = blivet.size.Size("0 MiB")

            for parent, size in user_input.parents:

                dev = PartitionDevice(name="req%d" % self.storage.nextID,
                    size=size, parents=parent)
                ac_part = blivet.deviceaction.ActionCreateDevice(dev)

                fmt = blivet.formats.getFormat(fmt_type="lvmpv")
                ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt)

                actions.extend([ac_part, ac_fmt])

                total_size += dev.size

                # we need to try to create pvs immediately, if something
                # fails, fail now
                try:
                    for ac in (ac_part, ac_fmt):
                        self.storage.devicetree.registerAction(ac)

                except blivet.errors.PartitioningError as e:
                    return ReturnList(success=False, actions=None, message=None, exception=e,
                                      traceback=sys.exc_info()[2])

                pvs.append(dev)

            new_vg = LVMVolumeGroupDevice(size=total_size, parents=pvs,
                name=device_name, peSize=user_input.advanced["pesize"])

            actions.append(blivet.deviceaction.ActionCreateDevice(new_vg))

        elif user_input.device_type == "lvm" and user_input.encrypt:

            device_name = self._pick_device_name(user_input.name)

            lukses = []

            # exact total size of newly created pvs (future parents)
            total_size = blivet.size.Size("0 MiB")

            for parent, size in user_input.parents:
                dev = PartitionDevice(name="req%d" % self.storage.nextID,
                    size=user_input.size,
                    parents=[parent])
                ac_part = blivet.deviceaction.ActionCreateDevice(dev)

                fmt = blivet.formats.getFormat(fmt_type="luks", passphrase=user_input.passphrase, device=dev.path)
                ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt)

                luks_dev = LUKSDevice("luks-%s" % dev.name,
                    fmt=blivet.formats.getFormat("lvmpv", device=dev.path),
                    size=dev.size, parents=[dev])
                ac_luks = blivet.deviceaction.ActionCreateDevice(luks_dev)

                actions.extend([ac_part, ac_fmt, ac_luks])

                total_size += luks_dev.size

                # we need to try to create pvs immediately, if something
                # fails, fail now
                try:
                    for ac in (ac_part, ac_fmt, ac_luks):
                        self.storage.devicetree.registerAction(ac)

                except blivet.errors.PartitioningError as e:
                    return ReturnList(success=False, actions=None, message=None, exception=e,
                                      traceback=sys.exc_info()[2])

                lukses.append(luks_dev)

            new_vg = LVMVolumeGroupDevice(size=total_size, parents=lukses,
                name=device_name, peSize=user_input.advanced["pesize"])

            actions.append(blivet.deviceaction.ActionCreateDevice(new_vg))

        elif user_input.device_type == "lvmlv":

            device_name = self._pick_device_name(user_input.name,
                user_input.parents[0][0])

            new_part = LVMLogicalVolumeDevice(name=device_name, size=user_input.size,
                parents=[i[0] for i in user_input.parents])

            actions.append(blivet.deviceaction.ActionCreateDevice(new_part))

            new_fmt = blivet.formats.getFormat(fmt_type=user_input.filesystem, mountpoint=user_input.mountpoint)

            actions.append(blivet.deviceaction.ActionCreateFormat(new_part, new_fmt))

        elif user_input.device_type == "lvmvg":

            device_name = self._pick_device_name(user_input.name)

            new_vg = LVMVolumeGroupDevice(size=user_input.size, name=device_name,
                parents=[i[0] for i in user_input.parents],
                peSize=user_input.advanced["pesize"])

            actions.append(blivet.deviceaction.ActionCreateDevice(new_vg))

        elif user_input.device_type == "lvmpv":

            if user_input.encrypt:

                dev = PartitionDevice(name="req%d" % self.storage.nextID,
                    size=user_input.size,
                    parents=[i[0] for i in user_input.parents])
                actions.append(blivet.deviceaction.ActionCreateDevice(dev))

                fmt = blivet.formats.getFormat(fmt_type="luks", passphrase=user_input.passphrase, device=dev.path)
                actions.append(blivet.deviceaction.ActionCreateFormat(dev, fmt))

                luks_dev = LUKSDevice("luks-%s" % dev.name,
                    fmt=blivet.formats.getFormat("lvmpv", device=dev.path),
                    size=dev.size, parents=[dev])
                actions.append(blivet.deviceaction.ActionCreateDevice(luks_dev))

            else:
                dev = PartitionDevice(name="req%d" % self.storage.nextID,
                    size=user_input.size, parents=[i[0] for i in user_input.parents])
                actions.append(blivet.deviceaction.ActionCreateDevice(dev))

                fmt = blivet.formats.getFormat(fmt_type="lvmpv")
                actions.append(blivet.deviceaction.ActionCreateFormat(dev, fmt))

        elif user_input.device_type == "btrfs volume":

            device_name = self._pick_device_name(user_input.name)

            # for btrfs we need to create parents first -- currently selected "parents" are
            # disks but "real parents" for subvolume are btrfs formatted partitions
            btrfs_parents = []

            # exact total size of newly created partitions (future parents)
            total_size = blivet.size.Size("0 MiB")

            for parent, size in user_input.parents:

                if user_input.btrfs_type == "disks":
                    assert parent.isDisk

                    fmt = blivet.formats.getFormat(fmt_type="btrfs")
                    ac_fmt = blivet.deviceaction.ActionCreateFormat(parent, fmt)

                    actions.append(ac_fmt)

                    try:
                        self.storage.devicetree.registerAction(ac_fmt)

                    except Exception as e: # pylint: disable=broad-except
                        return ReturnList(success=False, actions=None, message=None, exception=e,
                                          traceback=sys.exc_info()[2])

                    total_size += size
                    btrfs_parents.append(parent)

                else:

                    dev = PartitionDevice(name="req%d" % self.storage.nextID,
                        size=size, parents=[parent])
                    ac_part = blivet.deviceaction.ActionCreateDevice(dev)

                    fmt = blivet.formats.getFormat(fmt_type="btrfs")
                    ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt)

                    actions.extend([ac_part, ac_fmt])

                    total_size += dev.size

                    # we need to try to create partitions immediately, if something
                    # fails, fail now
                    try:
                        for ac in (ac_part, ac_fmt):
                            self.storage.devicetree.registerAction(ac)

                    except blivet.errors.PartitioningError as e:
                        return ReturnList(success=False, actions=None, message=None, exception=e,
                                          traceback=sys.exc_info()[2])

                    btrfs_parents.append(dev)

            new_btrfs = BTRFSVolumeDevice(device_name, size=total_size, parents=btrfs_parents)
            new_btrfs.format = blivet.formats.getFormat("btrfs", label=device_name, mountpoint=user_input.mountpoint)
            actions.append(blivet.deviceaction.ActionCreateDevice(new_btrfs))

        elif user_input.device_type == "btrfs subvolume":

            device_name = self._pick_device_name(user_input.name,
                user_input.parents[0][0])

            new_btrfs = BTRFSSubVolumeDevice(device_name, parents=[i[0] for i in user_input.parents])
            new_btrfs.format = blivet.formats.getFormat("btrfs", mountpoint=user_input.mountpoint)
            actions.append(blivet.deviceaction.ActionCreateDevice(new_btrfs))

        elif user_input.device_type == "mdraid":
            device_name = self._pick_device_name(user_input.name)

            parts = []

            # exact total size of newly created pvs (future parents)
            total_size = blivet.size.Size("0 MiB")

            for parent, size in user_input.parents:

                dev = PartitionDevice(name="req%d" % self.storage.nextID,
                    size=size, parents=[parent])
                ac_part = blivet.deviceaction.ActionCreateDevice(dev)

                fmt = blivet.formats.getFormat(fmt_type="mdmember")
                ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt)

                actions.extend([ac_part, ac_fmt])

                total_size += dev.size

                # we need to try to create pvs immediately, if something
                # fails, fail now
                try:
                    for ac in (ac_part, ac_fmt):
                        self.storage.devicetree.registerAction(ac)

                except blivet.errors.PartitioningError as e:
                    return ReturnList(success=False, actions=None, message=None, exception=e,
                                      traceback=sys.exc_info()[2])

                parts.append(dev)

            new_md = MDRaidArrayDevice(size=total_size, parents=parts,
                name=device_name, level=user_input.raid_level,
                memberDevices=len(parts), totalDevices=len(parts))
            actions.append(blivet.deviceaction.ActionCreateDevice(new_md))

            fmt = blivet.formats.getFormat(fmt_type=user_input.filesystem)
            actions.append(blivet.deviceaction.ActionCreateFormat(new_md, fmt))

        try:
            for ac in actions:
                if not ac._applied:
                    self.storage.devicetree.registerAction(ac)

            blivet.partitioning.doPartitioning(self.storage)

        except Exception as e: # pylint: disable=broad-except
            return ReturnList(success=False, actions=None, message=None, exception=e,
                              traceback=sys.exc_info()[2])

        return ReturnList(success=True, actions=actions, message=None, exception=None,
                          traceback=None)