
    Vh*                     v    d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ d ZddZd	 Zd
 Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
author:
  - Alain Dejoux (@adejoux)
module: aix_lvol
short_description: Configure AIX LVM logical volumes
description:
  - This module creates, removes or resizes AIX logical volumes. Inspired by lvol module.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  vg:
    description:
      - The volume group this logical volume is part of.
    type: str
    required: true
  lv:
    description:
      - The name of the logical volume.
    type: str
    required: true
  lv_type:
    description:
      - The type of the logical volume.
    type: str
    default: jfs2
  size:
    description:
      - The size of the logical volume with one of the [MGT] units.
    type: str
  copies:
    description:
      - The number of copies of the logical volume.
      - Maximum copies are 3.
    type: int
    default: 1
  policy:
    description:
      - Sets the interphysical volume allocation policy.
      - V(maximum) allocates logical partitions across the maximum number of physical volumes.
      - V(minimum) allocates logical partitions across the minimum number of physical volumes.
    type: str
    choices: [maximum, minimum]
    default: maximum
  state:
    description:
      - Control if the logical volume exists. If V(present) and the volume does not already exist then the O(size) option
        is required.
    type: str
    choices: [absent, present]
    default: present
  opts:
    description:
      - Free-form options to be passed to the mklv command.
    type: str
    default: ''
  pvs:
    description:
      - A list of physical volumes, for example V(hdisk1,hdisk2).
    type: list
    elements: str
    default: []
a  
- name: Create a logical volume of 512M
  community.general.aix_lvol:
    vg: testvg
    lv: testlv
    size: 512M

- name: Create a logical volume of 512M with disks hdisk1 and hdisk2
  community.general.aix_lvol:
    vg: testvg
    lv: test2lv
    size: 512M
    pvs: [hdisk1, hdisk2]

- name: Create a logical volume of 512M mirrored
  community.general.aix_lvol:
    vg: testvg
    lv: test3lv
    size: 512M
    copies: 2

- name: Create a logical volume of 1G with a minimum placement policy
  community.general.aix_lvol:
    vg: rootvg
    lv: test4lv
    size: 1G
    policy: minimum

- name: Create a logical volume with special options like mirror pool
  community.general.aix_lvol:
    vg: testvg
    lv: testlv
    size: 512M
    opts: -p copy1=poolA -p copy2=poolB

- name: Extend the logical volume to 1200M
  community.general.aix_lvol:
    vg: testvg
    lv: test4lv
    size: 1200M

- name: Remove the logical volume
  community.general.aix_lvol:
    vg: testvg
    lv: testlv
    state: absent
z
msg:
  type: str
  description: A friendly message describing the task result.
  returned: always
  sample: Logical volume testlv created.
N)AnsibleModulec                     |d   j                         }g d}	 d|j                  |      z  }t	        |d d       z  S # t        $ r | j                  d       Y .w xY w)N)MGTi   zNo valid size unit specified.msg)upperindex
ValueError	fail_jsonint)modulesizeunitunits
multipliers        n/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/aix_lvol.pyconvert_sizer      si    8>>DE>U[[..
 tCRy>J&&  ><=>s   > AAc                 `    t        |t        t        |       |z        z        }|| k  r||z  }|S )N)r   roundfloat)xbasenew_sizes      r   round_ppsizer       s4    4%a4001H!|DO    c                    d }| j                         D ]  }t        j                  d|      }|#|j                  d      }|j                  d      }>t        j                  d|      }|t	        |j                  d            }qt        j                  d|      }|t	        |j                  d            }t        j                  d|      }||j                  d      } |sy z  }||dS )Nz/LOGICAL VOLUME:\s+(\w+)\s+VOLUME GROUP:\s+(\w+)      zLPs:\s+(\d+).*PPsPP SIZE:\s+(\d+)zINTER-POLICY:\s+(\w+))namevgr   policy
splitlinesresearchgroupr   )	datar&   linematchr'   lpspp_sizer(   r   s	            r   parse_lvr3      s    D! 		LdS;;q>DQB		.5ekk!n%C		-t4%++a.)G		2D9[[^F#& =DDFCCr!   c                    | j                         D ]  }t        j                  d|      }||j                  d      }-t        j                  d|      }|t	        |j                  d            }`t        j                  d|      }|t	        |j                  d            }t        j                  d|      }|t	        |j                  d            } dS )NzVOLUME GROUP:\s+(\w+)r#   zTOTAL PP.*\((\d+)r%   zFREE PP.*\((\d+))r&   r   freer2   r)   )r.   r/   r0   r&   r   r2   r5   s          r   parse_vgr6      s    ! 		2D9;;q>D		.5u{{1~&D		-t4%++a.)G		-t4u{{1~&D), $IIr!   c                  	   t        t        t        dd      t        dd      t        dd      t        d      t        dd      t        dd	      t        dd
dd
g      t        ddddg      t        ddt                     	      d      } | j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }	|dk(  rd}
nd}
| j                  r| j                  dd      g}ng }| j                  d d      }| j                  d!d      }| j                  ||g      \  }}}|d"k7  r4|dk(  r| j                  d#d$|z  %       n| j                  d$|z  |||&       t        |      }|t        t        | |      |d'   (      }| j                  ||g      \  }}}|d"k7  r|dk(  r| j                  d#d)|z  %       d#}t        |      }|d
k(  r|s|| j                  d*+       ||d
k(  r|d,   kD  r| j                  d-|d.   d/|d,   d0+       | j                  d1d      }||d2|d3|d4|d5|
|||d6gz   |	z   }| j                  |      \  }}}|d"k(  r| j                  dd7|z  %       y | j                  d8|z  |||&       y y |dk(  rf| j                  d9d      }| j                  ||d:|d.   gz         \  }}}|d"k(  r| j                  dd;|z  %       y | j                  d<|z  |||&       y |d   |k7  rj| j                  d=d      }| j                  ||d5|
|d.   gz         \  }}}|d"k(  r| j                  dd>|d?|d@%       n| j                  dA|z  |||&       ||d   k7  r| j                  d>|dB|d   +       |s| j                  d#dC|z  %       t              |d   kD  rv| j                  dDd      }|||||d   z
  d6gz   }| j                  |      \  }}}|d"k(  r| j                  dd>|dE|dF%       y | j                  dG|dH|dF|||&       y ||d   k  r| j                  dI|dJ|d   dK+       y | j                  d#d>|dL|dF%       y )MNstrT)typerequiredjfs2)r9   default)r9    r   r#   presentabsent)r9   r<   choicesmaximumminimumlist)r9   elementsr<   )	r'   lvlv_typer   optscopiesstater(   pvs)argument_specsupports_check_moder'   rE   rF   r   rG   rH   r(   rI   rJ   r   mecho)r:   lsvglslvr   FzVolume group %s does not exist.)changedr   )r   rcouterrr2   )r   z!Logical Volume %s does not exist.zNo size given.r   r5   z&Not enough free space in volume group r&   z: z	 MB free.mklvz-tz-yz-cz-er	   zLogical volume %s created.z"Creating logical volume %s failed.rmlvz-fzLogical volume %s deleted.z#Failed to remove logical volume %s.chlvzLogical volume z policy changed: .z*Failed to change logical volume %s policy.z already exist in volume group z Logical volume %s already exist.extendlvz size extended to zMB.zUnable to resize z to zNo shrinking of Logical Volume z permitted. Current size: z MBz size is already )r   dictrC   params
check_modeget_bin_pathrun_command	exit_jsonr   r6   r    r   r3   r   )r   r'   rE   rF   r   rG   rH   r(   rI   rJ   	lv_policytest_optlsvg_cmdlslv_cmdrR   vg_inforT   this_vglv_sizelv_inforQ   this_lvmklv_cmdcmdrS   rmlv_cmdchlv_cmdextendlv_cmds                               r   mainrn      s   ..eV45!5"-UA.E9x>STUI	9?UV&5$&A

 !F 
t	B	t	BmmI&G== D== D]]8$F]]8$FMM'"E
--
C		 '''>? ""6D"9H""6D"9H ))8R.9B	QwHU0QTV0VW!BR!GBT[adewG|FD9	@RS ))8R.9B	QwHU0SVX0XYGwG	$?!12I(  `ghn`oqxy  rA  &B   C **6D*AHhgtRvtU^`dfhszj}~~  BE  EC!--c2LBSQw  3ORT3T U  %IB%NSU[^dg h  H**6D*AH!--h(D'RX/9Z.Z[LBSQw  3ORT3T U  %JR%OTV\_eh ix F*!..v.E%11(hiY`agYh=i2ijC7$$Tbdfl7m$n$$)UXZ)Z_agjps$tWT]"  ]_ahiman%o p   4VZ\4] ^ 7|gfo-%22:2M,Wwv=V4Y!ZZ%11#6C7$$Tegip7q$r$$2w)W\^dgmp$q76?*  kmovw}o~%   A  acel4m nr!   __main__)   )
__future__r   r   r   r9   __metaclass__DOCUMENTATIONEXAMPLESRETURNr+   ansible.module_utils.basicr   r   r    r3   r6   rn   __name__ r!   r   <module>ry      se    A @BH.`
 
 4'D<J6{o| zF r!   