Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/system/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/system/parted.pyc

�
�Udac@`sVddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
mZddlZddl
Z
ddlZd
ddddgaddddgattdddddgZdd�Zd�Zd�Zd�Zd �Zd!�Zd"�Zd#�Zdd$�Zd%�Zd&�Zd'�Zed(krRe�ndS()i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys�
---
author:
 - Fabrizio Colonna (@ColOfAbRiX)
module: parted
short_description: Configure block device partitions
version_added: "2.3"
description:
  - This module allows configuring block device partition using the C(parted)
    command line tool. For a full description of the fields and the options
    check the GNU parted manual.
requirements:
  - This module requires parted version 1.8.3 and above.
  - If the version of parted is below 3.1, it requires a Linux version running
    the sysfs file system C(/sys/).
options:
  device:
    description: The block device (disk) where to operate.
    type: str
    required: True
  align:
    description: Set alignment for newly created partitions.
    type: str
    choices: [ cylinder, minimal, none, optimal ]
    default: optimal
  number:
    description:
    - The number of the partition to work with or the number of the partition
      that will be created.
    - Required when performing any action on the disk, except fetching information.
    type: int
  unit:
    description:
    - Selects the current default unit that Parted will use to display
      locations and capacities on the disk and to interpret those given by the
      user if they are not suffixed by an unit.
    - When fetching information about a disk, it is always recommended to specify a unit.
    type: str
    choices: [ s, B, KB, KiB, MB, MiB, GB, GiB, TB, TiB, '%', cyl, chs, compact ]
    default: KiB
  label:
    description: Creates a new disk label.
    type: str
    choices: [ aix, amiga, bsd, dvh, gpt, loop, mac, msdos, pc98, sun ]
    default: msdos
  part_type:
    description:
    - May be specified only with 'msdos' or 'dvh' partition tables.
    - A C(name) must be specified for a 'gpt' partition table.
    - Neither C(part_type) nor C(name) may be used with a 'sun' partition table.
    type: str
    choices: [ extended, logical, primary ]
    default: primary
  part_start:
    description:
    - Where the partition will start as offset from the beginning of the disk,
      that is, the "distance" from the start of the disk.
    - The distance can be specified with all the units supported by parted
      (except compat) and it is case sensitive, e.g. C(10GiB), C(15%).
    type: str
    default: 0%
  part_end :
    description:
    - Where the partition will end as offset from the beginning of the disk,
      that is, the "distance" from the start of the disk.
    - The distance can be specified with all the units supported by parted
      (except compat) and it is case sensitive, e.g. C(10GiB), C(15%).
    type: str
    default: 100%
  name:
    description:
    - Sets the name for the partition number (GPT, Mac, MIPS and PC98 only).
    type: str
  flags:
    description: A list of the flags that has to be set on the partition.
    type: list
  state:
    description:
    - Whether to create or delete a partition.
    - If set to C(info) the module will only return the device information.
    type: str
    choices: [ absent, present, info ]
    default: info
notes:
  - When fetching information about a new disk and when the version of parted
    installed on the system is before version 3.1, the module queries the kernel
    through C(/sys/) to obtain disk information. In this case the units CHS and
    CYL are not supported.
sO
partition_info:
  description: Current partition information
  returned: success
  type: complex
  contains:
    device:
      description: Generic device information.
      type: dict
    partitions:
      description: List of device partitions.
      type: list
  sample: {
      "disk": {
        "dev": "/dev/sdb",
        "logical_block": 512,
        "model": "VMware Virtual disk",
        "physical_block": 512,
        "size": 5.0,
        "table": "msdos",
        "unit": "gib"
      },
      "partitions": [{
        "begin": 0.0,
        "end": 1.0,
        "flags": ["boot", "lvm"],
        "fstype": "",
        "name": "",
        "num": 1,
        "size": 1.0
      }, {
        "begin": 1.0,
        "end": 5.0,
        "flags": [],
        "fstype": "",
        "name": "",
        "num": 2,
        "size": 4.0
      }]
    }
sB
- name: Create a new primary partition
  parted:
    device: /dev/sdb
    number: 1
    state: present

- name: Remove partition number 1
  parted:
    device: /dev/sdb
    number: 1
    state: absent

- name: Create a new primary partition with a size of 1GiB
  parted:
    device: /dev/sdb
    number: 1
    state: present
    part_end: 1GiB

- name: Create a new primary partition for LVM
  parted:
    device: /dev/sdb
    number: 2
    flags: [ lvm ]
    state: present
    part_start: 1GiB

# Example on how to read info and reuse it in subsequent task
- name: Read device information (always use unit when probing)
  parted: device=/dev/sdb unit=MiB
  register: sdb_info

- name: Remove all partitions from disk
  parted:
    device: /dev/sdb
    number: '{{ item.num }}'
    state: absent
  loop: '{{ sdb_info.partitions }}'
(t
AnsibleModuleNtBtKBtMBtGBtTBtKiBtMiBtGiBtTiBtst%tcyltchstcompacttcC`s�tjd|�}|dkr�tjd|�}|dkrStjdd|�nit|jd��d6t|jd��d6t|jd	��d
6}d}n<|jd�dk	r�|jd�}nt|jd��}||fS(
s:
    Parses a string containing a size of information
    s^([\d.]+)([\w%]+)?$s^(\d+),(\d+),(\d+)$tmsgs+Error interpreting parted size output: '%s'itcylinderitheaditsectorRN(tretsearchtNonetmodulet	fail_jsontinttgrouptfloat(tsize_strtunittmatchestsize((sA/usr/lib/python2.7/site-packages/ansible/modules/system/parted.pyt
parse_unit�s		cC`s�g|jd�D]}|j�dkr|^q}|djd�jd�}t|d|�\}}i|dd6|d6|j�d	6|d
d6|dd
6t|d�d6t|d�d6}|d$krb|djd�jd�}t|d�\}}	it|d�d6t|d�d6t|d�d6|d6|	j�d6|d<|d}ng}
x.|dD]"}|jd�jd�}|dkr�t|d�d}|d}
|d
}|d}n$d}|d}
|d}|d
}|
jit|d�d6t|d�dd6t|d�dd6|d6|
d6|d6g|jd �D]}|dkr_|j�^q_d!6|j�d	6�qsWi|d"6|
d#6S(%s
    Parses the output of parted and transforms the data into
    a dictionary.

    Parted Machine Parseable Output:
    See: https://lists.alioth.debian.org/pipermail/parted-devel/2006-December/00
    0573.html
     - All lines end with a semicolon (;)
     - The first line indicates the units in which the output is expressed.
       CHS, CYL and BYT stands for CHS, Cylinder and Bytes respectively.
     - The second line is made of disk information in the following format:
       "path":"size":"transport-type":"logical-sector-size":"physical-sector-siz
       e":"partition-table-type":"model-name";
     - If the first line was either CYL or CHS, the next line will contain
       information on no. of cylinders, heads, sectors and cylinder size.
     - Partition information begins from the next line. This is of the format:
       (for BYT)
       "number":"begin":"end":"size":"filesystem-type":"partition-name":"flags-s
       et";
       (for CHS/CYL)
       "number":"begin":"end":"filesystem-type":"partition-name":"flags-set";
    s
Rit;t:itdevR'R%ittableitmodelit
logical_blockitphysical_blockRRit	cylinderstheadstsectorstcyl_sizet
cyl_size_unittchs_infotnumtbegintendtfstypetnames, tflagstgenerict
partitions(Rschs(tsplittstriptrstripR(tlowerR!tappend(t
parted_outputR%txtlinestgeneric_paramsR'R<R5R3tcyl_unittpartstlinetpart_paramsR9R:R;tf((sA/usr/lib/python2.7/site-packages/ansible/modules/system/parted.pytparse_partition_info�sV4







	5cC`sM|j�}|dkrdS|dkrvtdttj|�dd	��}d}|tt�krvt|}qvnd}|tkr�d
tj|�}n"|tkr�dtj|�}n||d}|dkr�|d}n#|dkr|d}n
|d}|dkrd}n|dkr4d}nd}t	||�|fS(s
    Formats a size in bytes into a different unit, like parted does. It doesn't
    manage CYL and CHS formats, though.
    This function has been adapted from https://github.com/Distrotech/parted/blo
    b/279d9d869ff472c52b9ec2e180d568f0c99e30b0/libparted/unit.c
    igtbRRRRg�?g@g@�@g�@ig��ؗ�Ҝ<i
g{�G�zt?idg�������?g�?i(gRM(RRscylschsg�?(
RAtmaxR!tmathtlog10tlentunits_sitindext	units_iectround(t
size_bytesR%RSt
multipliertoutputtwt	precision((sA/usr/lib/python2.7/site-packages/ansible/modules/system/parted.pytformat_disk_size@s4		


		c
C`s�tjj|�}d|}t|dd�}t|dd�}tt|dd��}tt|dd��}tt|d	d��|}t||�\}	}ii|d
6dd6|	d
6|d6|d6|d6d||fd6d6gd6S(s�
    Fetches device information directly from the kernel and it is used when
    parted cannot work because of a missing label. It always returns a 'unknown'
    label.
    s
/sys/block/%ss/device/vendortUnknowns
/device/modelR-s/queue/logical_block_sizeis/queue/physical_block_sizes/sizeR+tunknownR,R'R%R.R/s%s %sR<R=(tostpathtbasenametread_recordR!R[(
tdeviceR%tdevice_nametbasetvendorR-tlogic_blockt
phys_blockRVR'((sA/usr/lib/python2.7/site-packages/ansible/modules/system/parted.pytget_unlabeled_device_infots$
c
C`s�t|�}|rt||�Sdt||f}tj|�\}}}|dkr�d|kr�tjdd|d|d|d|�nt||�S(	s^
    Fetches information about a disk and its partitions and it returns a
    dictionary.
    s%s -s -m %s -- unit '%s' printisunrecognised disk labelRs?Error while getting device information with parted script: '%s'trctoutterr(tcheck_parted_labelRhtparted_execRtrun_commandR RL(RbR%tlabel_neededtcommandRiRjRk((sA/usr/lib/python2.7/site-packages/ansible/modules/system/parted.pytget_device_info�s

	cC`s�t�\}}}|dkr*|dks6|dkr:tStjdt|f�\}}}|dkr~d|j�kr~tStS(s�
    Determines if parted needs a label to complete its duties. Versions prior
    to 3.1 don't return data when there is no label. For more information see:
    http://upstream.rosalinux.ru/changelogs/libparted/3.1/changelog.html
    iis%s -s -m %s printisunrecognised disk label(tparted_versiontFalseRRnRmRAtTrue(Rbtparted_majortparted_minort_RiRjRk((sA/usr/lib/python2.7/site-packages/ansible/modules/system/parted.pyRl�s	$"c		C`s]tjdt�\}}}|dkrMtjddd|d|d|�ng|jd�D]}|j�d	kr]|^q]}t|�dkr�tjddddd|�ntjd
|d�}|dkr�tjddddd|�nt
|jd��}t
|jd��}d}|jd
�dk	rPt
|jd
��}n|||fS(sP
    Returns the major and minor version of parted installed on the system.
    s%s --versioniRsFailed to get parted version.RiRjRks
Rs"^parted.+(\d+)\.(\d+)(?:\.(\d+))?$iiiN(RRnRmR R>R?RQRRRR!R"(	RiRjRkRDRER&tmajortminortrev((sA/usr/lib/python2.7/site-packages/ansible/modules/system/parted.pyRr�s 	4c
C`s�|r|tjr|dt|||f}tj|�\}}}|dkr|tjdd|j�d|d|d|�q|ndS(	s
    Runs a parted script.
    s%s -s -m -a %s %s -- %siRs%Error while running parted script: %sRiRjRkN(Rt
check_modeRmRnR R?(tscriptRbtalignRpRiRjRk((sA/usr/lib/python2.7/site-packages/ansible/modules/system/parted.pytparted�s	cC`sNy5t|d�}z|j�j�SWd|j�XWntk
rI|SXdS(s8
    Reads the first line of a file and returns it.
    trN(topentreadlineR?tclosetIOError(t	file_pathtdefaultRK((sA/usr/lib/python2.7/site-packages/ansible/modules/system/parted.pyRa�s
c`st��fd�|D��S(sf
    Looks if a partition that has a specific value for a specific attribute
    actually exists.
    c3`s)|]}|�o |��kVqdS(N((t.0tpart(t	attributetnumber(sA/usr/lib/python2.7/site-packages/ansible/modules/system/parted.pys	<genexpr>s(tany(R=R�R�((R�R�sA/usr/lib/python2.7/site-packages/ansible/modules/system/parted.pytpart_exists�scC`st|�\}}|tkS(s7
    Checks if the input string is an allowed size
    (R(tparted_units(R$R'R%((sA/usr/lib/python2.7/site-packages/ansible/modules/system/parted.pytcheck_size_format
sc!C`st}d}d}tdtdtdddt�dtdddd	d
ddd
d	g�dtdd�dtddddd
t�dtddddd
ddddddddddg
�dtddddd
dd dg�d!tdddd"�d#tdddd$�d%tdd�d&tdd'�d(tdddd)d
d*d)d+g��d,d(d+dggd(d*dgggd-t�aid.d/6d.d06d.d16d.d26t_tjd}tjd}tjd}tjd}tjd}tjd}tjd!}	tjd#}
tjd%}tjd(}tjd&}
tjd3t�a	|dk	rn|d4krntjd5d6�nt|	�s�tjd5d7d8t
|	��nt|
�s�tjd5d9d8t
|
��nt||�}|d:}|d+krO|d;jd<d�|kr|d=|7}n|rIt|d>|�rI|d?||	|
f7}n|rh|rhd@||f}n|r�||7}t|||�t}d}t||�d:}nt|d>|�s�tjrigd&6}tjsg|D]}|d>|kr�|^q�dA}n|dk	rF|jd%d�|krF|dB||f7}n|
rdC|
krtdD|
krt|
jdD�ntt|d&�t|
��}tt|
�t|d&��}x"|D]}|dE||f7}q�Wx%|D]}|dF||f7}q�Wqn|r#|r#d@||f}n|r�||7}t}t|||�q�np|d*kr�t|d>|�svtjr�dG|}||7}t}t|||�q�n|d)kr�dH|}nt||�}tjdI|dJ|d;d:|d:dK|j��dS(LNRt
argument_specRbttypetstrtrequiredR}R�toptimaltchoicesRtminimaltnoneR�R!R%Rtlabeltmsdostaixtamigatbsdtdvhtgpttlooptmactpc98tsunt	part_typetprimarytextendedtlogicalt
part_starts0%tpart_ends100%R:R;tlisttstatetinfotabsenttpresenttrequired_iftsupports_check_modetCtLANGtLC_ALLtLC_MESSAGEStLC_CTYPER~iRs,The partition number must be greater then 0.sZThe argument 'part_start' doesn't respect required format.The size unit is case sensitive.RksXThe argument 'part_end' doesn't respect required format.The size unit is case sensitive.R=R<R,smklabel %s R6smkpart %s %s %s s
unit %s %sisname %s '"%s"' tesptboots
set %s %s on sset %s %s off srm %s sunit '%s' print tchangedtdiskR|(RsRtdictRtR�Rtrun_command_environ_updatetparamstget_bin_pathRmRR R�R(RqtgetR�R~R{RBR�tsett	exit_jsonR?(R�t
output_scriptR|RbR}R�R%R�R�R�R�R:R�R;tcurrent_devicet
current_partst	partitiontpt	flags_offtflags_onRKtfinal_device_status((sA/usr/lib/python2.7/site-packages/ansible/modules/system/parted.pytmains�'9$'	%










		


	0$  





	

t__main__( t
__future__RRRR�t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtRETURNtEXAMPLEStansible.module_utils.basicRRORR^RRRTR�R(RLR[RhRqRlRrR~RRaR�R�R�t__name__(((sA/usr/lib/python2.7/site-packages/ansible/modules/system/parted.pyt<module>s8


[*)	X	4								�

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]