How to use the blivet.i18n._ function in blivet

To help you get started, we’ve selected a few blivet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github storaged-project / blivet / blivet / partitioning.py View on Github external
length = sizeToSectors(size, sectorSize)
            end = start + length - 1

        if not end_alignment.isAligned(free, end):
            end = end_alignment.alignUp(free, end)
            log.debug("adjusted length from %d to %d", length, end - start + 1)
            if start > end:
                raise PartitioningError(_("unable to allocate aligned partition"))

    new_geom = parted.Geometry(device=disklabel.partedDevice,
                               start=start,
                               end=end)

    max_length = disklabel.partedDisk.maxPartitionLength
    if max_length and new_geom.length > max_length:
        raise PartitioningError(_("requested size exceeds maximum allowed"))

    # create the partition and add it to the disk
    partition = parted.Partition(disk=disklabel.partedDisk,
                                 type=part_type,
                                 geometry=new_geom)
    constraint = parted.Constraint(exactGeom=new_geom)
    disklabel.partedDisk.addPartition(partition=partition,
                                      constraint=constraint)
    return partition
github storaged-project / blivet / blivet / iscsi.py View on Github external
:type discover_user: str or NoneType
        :param discover_pw: CHAP password for discovery
        :type discover_pw: str or NoneType
        :param discover_user_in: reverse CHAP username for discovery
        :type discover_user: str or NoneType
        :param discover_pw_in: reverse CHAP password for discovery
        :type discover_pw_in: str or NoneType
        """

        found = 0
        logged_in = 0

        found_nodes = self.discover(ipaddr, port, discover_user, discover_pw,
                                    discover_user_in, discover_pw_in)
        if found_nodes == None:
            raise IOError(_("No iSCSI nodes discovered"))

        for node in found_nodes:
            if target and target != node.name:
                log.debug("iscsi: skipping logging to iscsi node '%s'", node.name)
                continue
            if iface:
                node_net_iface = self.ifaces.get(node.iface, node.iface)
                if iface != node_net_iface:
                    log.debug("iscsi: skipping logging to iscsi node '%s' via %s",
                               node.name, node_net_iface)
                    continue

            found = found + 1

            (rc, _msg) = self.log_into_node(node, user, pw, user_in, pw_in)
            if rc:
github storaged-project / blivet / blivet / zfcp.py View on Github external
log.info("WWPN %(wwpn)s at zFCP device %(devnum)s already "
                         "there.", {'wwpn': self.wwpn,
                                    'devnum': self.devnum})

        if not os.path.exists(unitdir):
            try:
                logged_write_line_to_file(unitadd, self.fcplun)
                udev.settle()
            except IOError as e:
                raise ValueError(_("Could not add LUN %(fcplun)s to WWPN "
                                   "%(wwpn)s on zFCP device %(devnum)s "
                                   "(%(e)s).")
                                 % {'fcplun': self.fcplun, 'wwpn': self.wwpn,
                                     'devnum': self.devnum, 'e': e})
        else:
            raise ValueError(_("LUN %(fcplun)s at WWPN %(wwpn)s on zFCP "
                               "device %(devnum)s already configured.")
                             % {'fcplun': self.fcplun,
                                 'wwpn': self.wwpn,
                                 'devnum': self.devnum})

        fail = "0"
        try:
            f = open(failed, "r")
            fail = f.readline().strip()
            f.close()
        except IOError as e:
            raise ValueError(_("Could not read failed attribute of LUN "
                               "%(fcplun)s at WWPN %(wwpn)s on zFCP device "
                               "%(devnum)s (%(e)s).")
                             % {'fcplun': self.fcplun,
                                 'wwpn': self.wwpn,
github storaged-project / blivet / blivet / populator.py View on Github external
except InvalidDiskLabelError:
                log.warning("disklabel detected but not usable on %s",
                            device.name)
            else:
                device.format = fmt
            return

        try:
            fmt = formats.getFormat("disklabel",
                                    device=device.path,
                                    exists=True)
        except InvalidDiskLabelError as e:
            log.info("no usable disklabel on %s", device.name)
            if disklabel_type == "gpt":
                log.debug(e)
                device.format = formats.getFormat(_("Invalid Disk Label"))
        else:
            device.format = fmt
github storaged-project / blivet / blivet / partitioning.py View on Github external
# leave extended partitions as-is -- we'll handle them separately
            if part.isExtended:
                continue
            part.updateName()

        updateExtendedPartitions(storage, disks)

        for part in [p for p in storage.partitions if not p.exists]:
            problem = part.checkSize()
            if problem < 0:
                raise PartitioningError(_("partition is too small for %(format)s formatting "
                                        "(allowable size is %(minSize)s to %(maxSize)s)")
                                        % {"format": part.format.name, "minSize": part.format.minSize,
                                            "maxSize": part.format.maxSize})
            elif problem > 0:
                raise PartitioningError(_("partition is too large for %(format)s formatting "
                                        "(allowable size is %(minSize)s to %(maxSize)s)")
                                        % {"format": part.format.name, "minSize": part.format.minSize,
                                            "maxSize": part.format.maxSize})
github storaged-project / blivet / blivet / autopart.py View on Github external
if not storage.do_autopart:
        return

    if not any(d.format.supported for d in storage.partitioned):
        raise NoDisksError(_("No usable disks selected"))

    if min_luks_entropy is not None:
        luks_data.min_entropy = min_luks_entropy

    disks = _get_candidate_disks(storage)
    devs = _schedule_implicit_partitions(storage, disks)
    log.debug("candidate disks: %s", disks)
    log.debug("devs: %s", devs)

    if disks == []:
        raise NotEnoughFreeSpaceError(_("Not enough free space on disks for "
                                        "automatic partitioning"))
    devs = _schedule_partitions(storage, disks, devs)

    # run the autopart function to allocate and grow partitions
    do_partitioning(storage)
    _schedule_volumes(storage, devs)

    # grow LVs
    grow_lvm(storage)

    storage.set_up_bootloader()

    # only newly added swaps should appear in the fstab
    new_swaps = (dev for dev in storage.swaps if not dev.format.exists)
    storage.set_fstab_swaps(new_swaps)
github storaged-project / blivet / blivet / autopart.py View on Github external
"""Perform automatic partitioning of just required platform-specific
       partitions.  This is incompatible with do_autopart.

       :param storage: a :class:`~.Blivet` instance
       :type storage: :class:`~.Blivet`
       :param requests: list of partitioning requests to operate on,
                        or `~.storage.autopart_requests` by default
       :type requests: list of :class:`~.partspec.PartSpec` instances
    """
    if not any(d.format.supported for d in storage.partitioned):
        raise NoDisksError(_("No usable disks selected"))

    disks = _get_candidate_disks(storage)

    if disks == []:
        raise NotEnoughFreeSpaceError(_("Not enough free space on disks for "
                                        "automatic partitioning"))

    _schedule_partitions(storage, disks, [], requests=requests)
github storaged-project / blivet / blivet / deviceaction.py View on Github external
def type_desc(self):
        return _(self.type_desc_str)
github storaged-project / blivet / blivet / zfcp.py View on Github external
def __init__(self, devnum, wwpn, fcplun):
        self.devnum = blockdev.s390.sanitize_dev_input(devnum)
        self.wwpn = blockdev.s390.zfcp_sanitize_wwpn_input(wwpn)
        self.fcplun = blockdev.s390.zfcp_sanitize_lun_input(fcplun)

        if not self.devnum:
            raise ValueError(_("You have not specified a device number or the number is invalid"))
        if not self.wwpn:
            raise ValueError(_("You have not specified a worldwide port name or the name is invalid."))
        if not self.fcplun:
            raise ValueError(_("You have not specified a FCP LUN or the number is invalid."))
github storaged-project / blivet / blivet / zfcp.py View on Github external
self.devnum, port)
                    return True
        else:
            # newer zfcp sysfs interface with auto port scan
            import glob
            luns = glob.glob("%s/0x????????????????/0x????????????????"
                             % (devdir,))
            if len(luns) != 0:
                log.info("Not setting zFCP device %s offline since it still has other LUNs, e.g. %s.",
                         self.devnum, luns[0])
                return True

        try:
            logged_write_line_to_file(offline, "0")
        except IOError as e:
            raise ValueError(_("Could not set zFCP device %(devnum)s "
                               "offline (%(e)s).")
                             % {'devnum': self.devnum, 'e': e})

        return True