%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/parted_partition.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
ZddlZddl
mZddlmZe	je�ZdZidd6d	d
6Zeddd
ddddddddddg
�Zd�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�Z d �Z!d!�Z"d"�Z#d#�Z$d$�Z%d%�Z&dddd&�Z'd'�Z(d(�Z)d)�Z*d*�Z+d+�Z,d,�Z-d-�Z.d.d/�Z/d0�Z0dS(1u0
Module for managing partitions on POSIX-like systems.

:depends:   - parted, partprobe, lsblk (usually parted and util-linux packages)

Some functions may not be available, depending on your version of parted.

Check the manpage for ``parted(8)`` for more information, or the online docs
at:

http://www.gnu.org/software/parted/manual/html_chapter/parted_2.html

In light of parted not directly supporting partition IDs, some of this module
has been written to utilize sfdisk instead. For further information, please
reference the man page for ``sfdisk(8)``.
i(tabsolute_importtunicode_literalstprint_functionN(tCommandExecutionError(tsixu	partitionusetuset_ulistulist_usuBukBuMBuMiBuGBuGiBuTBuTiBu%ucyluchsucompactcC@s}tjjj�rtdfStjjjd�s;tdfStjjjd�sZtdfStjjjd�sytdfStS(u�
    Only work on POSIX-like systems, which have parted and lsblk installed.
    These are usually provided by the ``parted`` and ``util-linux`` packages.
    uMThe parted execution module failed to load Windows systems are not supported.uparteduLThe parted execution module failed to load parted binary is not in the path.ulsblkuKThe parted execution module failed to load lsblk binary is not in the path.u	partprobeuOThe parted execution module failed to load partprobe binary is not in the path.(tsalttutilstplatformt
is_windowstFalsetpathtwhicht__virtualname__(((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pyt__virtual__0s



cC@sJtjj|�r:tj|�j}tj|�r:dSntd��dS(u0
    Ensure the device name supplied is valid in a manner similar to the
    `exists` function, but raise errors on invalid input rather than return
    False.

    This function only validates a block device, it does not check if the block
    device is a drive or a partition or a filesystem, etc.
    Nu*Invalid device passed to partition module.(tosR
texistststattst_modetS_ISBLKR(tdevicetdev((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pyt_validate_deviceGs	cC@sitj|�}tjd|�}|rP|jd�}|sI|tkrPdSntdj|���dS(u9
    Ensure valid partition boundaries are supplied.
    u^([\d.]+)(\D*)$iNu(Invalid partition boundary passed: "{0}"(Rt	text_typetretsearchtgrouptVALID_UNITSRtformat(tboundarytmatchtunit((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pyt_validate_partition_boundary[scG@sMx|D]}t|�qWdjdj|��}td|�j�}|S(u�
    Ask the kernel to update its local partition data. When no args are
    specified all block devices are tried.

    Caution: Generally only works on devices with no mounted partitions and
    may take a long time to return if specified devices are in use.

    CLI Examples:

    .. code-block:: bash

        salt '*' partition.probe
        salt '*' partition.probe /dev/sda
        salt '*' partition.probe /dev/sda /dev/sdb
    upartprobe -- {0}u ucmd.run(RRtjoint__salt__t
splitlines(tdevicesRtcmdtout((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytprobejs

c	C@s.t|�|r@|tkr+td��ndj||�}ndj|�}td|�j�}iid6id6}d}x�|D]�}|d'kr�q�n|jd
�jd�}|dkrzdt|�ko�d
knrki|dd6|dd6|dd6|dd6|dd6|dd6|dd6|d<t|�d
krb|d|dd<nd}q&td��q�ddd g}|d!kr�|j	d�n|d"d#kr�|j
�n|jd$d%d&g�t|�t|�krtt
jj||��|d|d<q�td��q�W|S((u�
    Prints partition information of given <device>

    CLI Examples:

    .. code-block:: bash

        salt '*' partition.list /dev/sda
        salt '*' partition.list /dev/sda unit=s
        salt '*' partition.list /dev/sda unit=kB
    u*Invalid unit passed to partition.part_listuparted -m -s {0} unit {1} printuparted -m -s {0} printucmd.run_stdoutuinfou
partitionsuBYT;uCHS;uCYL;u;u:iiiudiskiusizeiu	interfaceiulogical sectoriuphysical sectoriupartition tableiumodelu
disk flagsu4Problem encountered while parsing output from partedunumberustartuenduchsi����ufreeufile systemunameuflags(uBYT;uCHS;uCYL;(RRRRR!R"trstriptsplittlentappendtpoptextendtdictRtmovestzip(	RRR$R%trettmodetlinetcolstfields((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytlist_�sP

"	
*
cC@s�t|�|tddg�kr1td��nyt|�Wntk
r^td��nXdj|||�}td|�j�}|S(u�
    Check if partition satisfies the alignment constraint of part_type.
    Type must be "minimal" or "optimal".

    CLI Example:

    .. code-block:: bash

        salt '*' partition.align_check /dev/sda minimal 1
    uminimaluoptimalu1Invalid part_type passed to partition.align_checku1Invalid partition passed to partition.align_checku!parted -m {0} align-check {1} {2}ucmd.run(RtsetRtintt	ExceptionRR!R"(Rt	part_typet	partitionR$R%((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytalign_check�s


cC@sdt|�yt|�Wntk
r7td��nXdj||�}td|�j�}|S(u�
    Checks if the file system on partition <minor> has any errors.

    CLI Example:

    .. code-block:: bash

        salt '*' partition.check 1
    u.Invalid minor number passed to partition.checkuparted -m -s {0} check {1}ucmd.run(RR7R8RRR!R"(RtminorR$R%((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytcheck�s



cC@sqt|�yt|�t|�Wntk
rAtd��nXdj|||�}td|�j�}|S(u�
    Copies the file system on the partition <from-minor> to partition
    <to-minor>, deleting the original contents of the destination
    partition.

    CLI Example:

    .. code-block:: bash

        salt '*' partition.cp /dev/sda 2 3
    u+Invalid minor number passed to partition.cpuparted -m -s {0} cp {1} {2}ucmd.run(RR7R8RRR!R"(Rt
from_minortto_minorR$R%((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytcps



cC@sdt|�yt|�Wntk
r7td��nXdj||�}td|�j�}|S(u0
    Prints the system ID for the partition. Some typical values are::

         b: FAT32 (vfat)
         7: HPFS/NTFS
        82: Linux Swap
        83: Linux
        8e: Linux LVM
        fd: Linux RAID Auto

    CLI Example:

    .. code-block:: bash

        salt '*' partition.get_id /dev/sda 1
    u/Invalid minor number passed to partition.get_idusfdisk --print-id {0} {1}ucmd.run(RR7R8RRR!R"(RR<R$R%((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytget_id"s


cC@s�t|�yt|�Wntk
r7td��nX|t�krVtd��ndj|||�}td|�j�}|S(u1
    Sets the system ID for the partition. Some typical values are::

         b: FAT32 (vfat)
         7: HPFS/NTFS
        82: Linux Swap
        83: Linux
        8e: Linux LVM
        fd: Linux RAID Auto

    CLI Example:

    .. code-block:: bash

        salt '*' partition.set_id /dev/sda 1 83
    u/Invalid minor number passed to partition.set_idu,Invalid system_id passed to partition.set_idusfdisk --change-id {0} {1} {2}ucmd.run(RR7R8Rtsystem_typesRR!R"(RR<t	system_idR$R%((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytset_idAs


cC@spi}xctdd�j�D]K}|s/qn|jd�rDqn|j�j�}|d||d<qW|S(u�
    List the system types that are supported by the installed version of sfdisk

    CLI Example:

    .. code-block:: bash

        salt '*' partition.system_types
    ucmd.runu	sfdisk -TuIdii(R!R"t
startswithtstripR((R0R2tcomps((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pyRBes
cC@s7|tddddddddd	d
ddd
g
�kS(u�
    Check if file system type is supported in module
    :param fs_type: file system type
    :return: True if fs_type is supported in this module, False otherwise
    uext2uext3uext4ufat32ufat16u
linux-swapureiserfsuhfsuhfs+uhfsxuNTFSuntfsuufs(R6(tfs_type((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pyt
_is_fstypezscC@s�t|�t|�s%td��n|dkr:d}n|dkrOd}ndj|�}tjjj|�s�dj|�Sdj||�}td	|�j	�}|S(
uC
    Makes a file system <fs_type> on partition <device>, destroying all data
    that resides on that partition. <fs_type> must be one of "ext2", "fat32",
    "fat16", "linux-swap" or "reiserfs" (if libreiserfs is installed)

    CLI Example:

    .. code-block:: bash

        salt '*' partition.mkfs /dev/sda2 fat32
    u(Invalid fs_type passed to partition.mkfsuNTFSuntfsu
linux-swapumkswapumkfs.{0}uError: {0} is unavailable.u{0} {1}ucmd.run(
RRIRRRRR
RR!R"(RRHtmkfs_cmdR$R%((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytmkfs�s
		
cC@sw|tddddddddd	d
g
�kr?td��ndd
d|d|f}td|dt�j�}|S(u
    Create a new disklabel (partition table) of label_type.

    Type should be one of "aix", "amiga", "bsd", "dvh", "gpt", "loop", "mac",
    "msdos", "pc98", or "sun".

    CLI Example:

    .. code-block:: bash

        salt '*' partition.mklabel /dev/sda msdos
    uaixuamigaubsdudvhugptuloopumacumsdosupc98usunu.Invalid label_type passed to partition.mklabelupartedu-mu-sumklabelucmd.runtpython_shell(R6RR!R	R"(Rt
label_typeR$R%((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytmklabel�s
*cC@s|tdddg�kr*td��nt|�sEtd��n|dk	rt|dk	rtt|�t|�n|dkr�d}n|dkr�d}n|r�ddd	d
|d||||f
}n!ddd	d
|d|||f	}td|d
t�j�}|S(u�
    Make a part_type partition for filesystem fs_type, beginning at start and
    ending at end (by default in megabytes).  part_type should be one of
    "primary", "logical", or "extended".

    CLI Examples:

    .. code-block:: bash

        salt '*' partition.mkpart /dev/sda primary fs_type=fat32 start=0 end=639
        salt '*' partition.mkpart /dev/sda primary start=0 end=639
    uprimaryulogicaluextendedu,Invalid part_type passed to partition.mkpartu*Invalid fs_type passed to partition.mkpartuupartedu-mu-su--umkpartucmd.runRLN(R6RRItNoneRR!R	R"(RR9RHtstarttendR$R%((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytmkpart�s$


		'!cC@s�t|�|tdddg�kr4td��nt|�sOtd��nt|�t|�dj|||||�}td|�j�}|S(u�
    Make a <part_type> partition with a new filesystem of <fs_type>, beginning
    at <start> and ending at <end> (by default in megabytes).

    <part_type> should be one of "primary", "logical", or "extended". <fs_type>
    must be one of "ext2", "fat32", "fat16", "linux-swap" or "reiserfs" (if
    libreiserfs is installed)

    CLI Example:

    .. code-block:: bash

        salt '*' partition.mkpartfs /dev/sda logical ext2 440 670
    uprimaryulogicaluextendedu.Invalid part_type passed to partition.mkpartfsu,Invalid fs_type passed to partition.mkpartfsu*parted -m -s -- {0} mkpart {1} {2} {3} {4}ucmd.run(RR6RRIRRR!R"(RR9RHRPRQR$R%((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytmkpartfs�s


cC@s�t|�yt|�Wntk
r7td��nXtjtjd}x)|D]!}||krStd��qSqSWdj|||�}td|�j	�}|S(u
    Set the name of partition to name. This option works only on Mac, PC98, and
    GPT disklabels. The name can be placed in quotes, if necessary.

    CLI Example:

    .. code-block:: bash

        salt '*' partition.name /dev/sda 1 'My Documents'
    u*Invalid partition passed to partition.nameu _-u+Invalid characters passed to partition.nameu!parted -m -s {0} name {1} "'{2}'"ucmd.run(
RR7R8Rtstringt
ascii_letterstdigitsRR!R"(RR:tnametvalidtletterR$R%((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pyRWs



cC@sMt|�t|�t|�dj|||�}td|�j�}|S(u!
    Rescue a lost partition that was located somewhere between start and end.
    If a partition is found, parted will ask if you want to create an
    entry for it in the partition table.

    CLI Example:

    .. code-block:: bash

        salt '*' partition.rescue /dev/sda 0 8056
    uparted -m -s {0} rescue {1} {2}ucmd.run(RRRR!R"(RRPRQR$R%((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytrescue,s


cC@sxt|�yt|�Wntk
r7td��nXt|�t|�tddj||||��}|j�S(u�
    Resizes the partition with number <minor>.

    The partition will start <start> from the beginning of the disk, and end
    <end> from the beginning of the disk. resize never changes the minor number.
    Extended partitions can be resized, so long as the new extended partition
    completely contains all logical partitions.

    CLI Example:

    .. code-block:: bash

        salt '*' partition.resize /dev/sda 3 200 850
    u/Invalid minor number passed to partition.resizeucmd.runu&parted -m -s -- {0} resize {1} {2} {3}(RR7R8RRR!RR"(RR<RPRQR%((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytresizeAs




cC@sdt|�yt|�Wntk
r7td��nXdj||�}td|�j�}|S(u�
    Removes the partition with number <minor>.

    CLI Example:

    .. code-block:: bash

        salt '*' partition.rm /dev/sda 5
    u+Invalid minor number passed to partition.rmuparted -m -s {0} rm {1}ucmd.run(RR7R8RRR!R"(RR<R$R%((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytrmds



cC@s�t|�yt|�Wntk
r7td��nX|tdddddddd	d
ddd
g�kr}td��n|tddg�kr�td��ndj||||�}td|�j�}|S(u�
    Changes a flag on the partition with number <minor>.

    A flag can be either "on" or "off" (make sure to use proper quoting, see
    :ref:`YAML Idiosyncrasies <yaml-idiosyncrasies>`). Some or all of these
    flags will be available, depending on what disk label you are using.

    Valid flags are: bios_grub, legacy_boot, boot, lba, root, swap, hidden, raid,
        LVM, PALO, PREP, DIAG

    CLI Example:

    .. code-block:: bash

        salt '*' partition.set /dev/sda 1 boot '"on"'
    u,Invalid minor number passed to partition.setu	bios_grubulegacy_bootubootulbaurootuswapuhiddenuraiduLVMuPALOuPREPuDIAGu$Invalid flag passed to partition.setuonuoffu%Invalid state passed to partition.setu parted -m -s {0} set {1} {2} {3}ucmd.run(RR7R8RR6RR!R"(RR<tflagtstateR$R%((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytset_|s


!cC@s�t|�yt|�Wntk
r7td��nX|tdddddddd	d
ddd
g�kr}td��ndj|||�}td|�j�}|S(u�
    Toggle the state of <flag> on <partition>. Valid flags are the same as
        the set command.

    CLI Example:

    .. code-block:: bash

        salt '*' partition.toggle /dev/sda 1 boot
    u3Invalid partition number passed to partition.toggleu	bios_grubulegacy_bootubootulbaurootuswapuhiddenuraiduLVMuPALOuPREPuDIAGu'Invalid flag passed to partition.toggleuparted -m -s {0} toggle {1} {2}ucmd.run(RR7R8RR6RR!R"(RR:R]R$R%((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pyttoggle�s


!ucC@s>tjj|�r:tj|�j}tj|�r:tSntS(u�
    Check to see if the partition exists

    CLI Example:

    .. code-block:: bash

        salt '*' partition.exists /dev/sdb1
    (RR
RRRRtTrueR	(RR((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pyR�s

cC@s d}td|�j�}|S(u�
    Retrieve a list of disk devices

    .. versionadded:: 2014.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' partition.get_block_device
    u"lsblk -n -io KNAME -d -e 1,7,11 -lucmd.run(R!R"(R$tdevs((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pytget_block_device�s(1t__doc__t
__future__RRRRRRRTtloggingtsalt.utils.pathRtsalt.utils.platformtsalt.exceptionsRtsalt.extRt	getLoggert__name__tlogRt__func_alias__R6RR
RRR&ROR5R;R=R@RARDRBRIRKRNRRRSRWRZR[R\R_R`RRc(((sA/usr/lib/python2.7/site-packages/salt/modules/parted_partition.pyt<module>sR
!				M	 				$		
	 	*	%	 		#		&	

Zerion Mini Shell 1.0