Beispiel #1
0
def partition_is(dev):
    """
    Check whether a given device path is a partition or a full disk.

    CLI Example:

    .. code-block:: bash
    salt '*' sesceph.partition_is /dev/sdc1

    """
    osdc = osd.osd_ctrl()
    return osdc.is_partition(dev)
Beispiel #2
0
def partition_is(dev):
    """
    Check whether a given device path is a partition or a full disk.

    CLI Example:

    .. code-block:: bash
    salt '*' sesceph.partition_is /dev/sdc1

    """
    mdl = model.model(**kwargs)
    osdc = osd.osd_ctrl(mdl)
    return osdc.is_partition(dev)
Beispiel #3
0
def zap(dev = None, **kwargs):
    """
    Destroy the partition table and content of a given disk.
    """
    if dev is not None:
        log.warning("Depricated use of function, use kwargs")
    dev = kwargs.get("dev", dev)
    if dev == None:
        raise Error('Cannot find', dev)
    if not os.path.exists(dev):
        raise Error('Cannot find', dev)
    dmode = os.stat(dev).st_mode
    mdl = model.model(**kwargs)
    osdc = osd.osd_ctrl(mdl)
    if not stat.S_ISBLK(dmode) or osdc.is_partition(dev):
        raise Error('not full block device; cannot zap', dev)
    try:
        log.debug('Zapping partition table on %s', dev)

        # try to wipe out any GPT partition table backups.  sgdisk
        # isn't too thorough.
        lba_size = 4096
        size = 33 * lba_size
        with file(dev, 'wb') as dev_file:
            dev_file.seek(-size, os.SEEK_END)
            dev_file.write(size*'\0')

        utils.execute_local_command(
            [
                util_which.which_sgdisk.path,
                '--zap-all',
                '--',
                dev,
            ],
        )
        utils.execute_local_command(
            [
                util_which.which_sgdisk.path,
                '--clear',
                '--mbrtogpt',
                '--',
                dev,
            ],
        )


        _update_partition('-d', dev, 'zapped')
    except subprocess.CalledProcessError as e:
        raise Error(e)
    return True
Beispiel #4
0
def zap(dev=None, **kwargs):
    """
    Destroy the partition table and content of a given disk.
    """
    if dev is not None:
        log.warning("Depricated use of function, use kwargs")
    dev = kwargs.get("dev", dev)
    if dev == None:
        raise Error('Cannot find', dev)
    if not os.path.exists(dev):
        raise Error('Cannot find', dev)
    dmode = os.stat(dev).st_mode
    mdl = model.model(**kwargs)
    osdc = osd.osd_ctrl(mdl)
    if not stat.S_ISBLK(dmode) or osdc.is_partition(dev):
        raise Error('not full block device; cannot zap', dev)
    try:
        log.debug('Zapping partition table on %s', dev)

        # try to wipe out any GPT partition table backups.  sgdisk
        # isn't too thorough.
        lba_size = 4096
        size = 33 * lba_size
        with file(dev, 'wb') as dev_file:
            dev_file.seek(-size, os.SEEK_END)
            dev_file.write(size * '\0')

        utils.execute_local_command([
            constants._path_sgdisk,
            '--zap-all',
            '--',
            dev,
        ], )
        utils.execute_local_command([
            constants._path_sgdisk,
            '--clear',
            '--mbrtogpt',
            '--',
            dev,
        ], )

        _update_partition('-d', dev, 'zapped')
    except subprocess.CalledProcessError as e:
        raise Error(e)
    return True
Beispiel #5
0
def zap(dev):
    """
    Destroy the partition table and content of a given disk.
    """
    dmode = os.stat(dev).st_mode
    osdc = osd.osd_ctrl()
    if not stat.S_ISBLK(dmode) or osdc.is_partition(dev):
        raise Error('not full block device; cannot zap', dev)
    try:
        log.debug('Zapping partition table on %s', dev)

        # try to wipe out any GPT partition table backups.  sgdisk
        # isn't too thorough.
        lba_size = 4096
        size = 33 * lba_size
        with file(dev, 'wb') as dev_file:
            dev_file.seek(-size, os.SEEK_END)
            dev_file.write(size*'\0')

        utils.execute_local_command(
            [
                constants._path_sgdisk,
                '--zap-all',
                '--',
                dev,
            ],
        )
        utils.execute_local_command(
            [
                constants._path_sgdisk,
                '--clear',
                '--mbrtogpt',
                '--',
                dev,
            ],
        )


        _update_partition('-d', dev, 'zapped')
    except subprocess.CalledProcessError as e:
        raise Error(e)
    return True