
    Vh`                         d dl mZmZmZ eZdZdZd dlm	Z	  e
 e
dd       e
dd            Z G d	 d
e      Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
author:
  - Laszlo Szomor (@lszomor)
module: lvg_rename
short_description: Renames LVM volume groups
description:
  - This module renames volume groups using the C(vgchange) command.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: full
version_added: 7.1.0
options:
  vg:
    description:
      - The name or UUID of the source VG.
      - See V(vgrename(8\)) for valid values.
    type: str
    required: true
  vg_new:
    description:
      - The new name of the VG.
      - See V(lvm(8\)) for valid names.
    type: str
    required: true
seealso:
  - module: community.general.lvg
notes:
  - This module does not modify VG renaming-related configurations like C(fstab) entries or boot parameters.
z
- name: Rename a VG by name
  community.general.lvg_rename:
    vg: vg_orig_name
    vg_new: vg_new_name

- name: Rename a VG by UUID
  community.general.lvg_rename:
    vg_uuid: SNgd0Q-rPYa-dPB8-U1g6-4WZI-qHID-N7y9Vj
    vg_new: vg_new_name
)AnsibleModulestrT)typerequired)vgvg_newc                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)	LvgRenamec                 R    || _         ddi| _        g | _        | j                          y)zn
        Orchestrates the lvg_rename module logic.

        :param module: An AnsibleModule instance.
        changedFN)moduleresultvg_list_load_params)selfr   s     p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/lvg_rename.py__init__zLvgRename.__init__B   s*      %(    c                 V   | j                          | j                  | j                        }| j                  | j                        }|r=|r*| j                  j                  d| j                  z         n| j                          n||rCd| j                  z  | j                  d<    | j                  j                  d
i | j                   n7| j                  j                  d| j                  d| j                  d        | j                  j                  d
i | j                   y	)zPerforms the module logic.)r
   z'The new VG name (%s) is already in use.)msgz.The new VG (%s) already exists, nothing to do.r   zBoth current (z) and new (z) VG are missing.N )	_load_vg_list_is_vg_existsr
   r   r   	fail_json
_rename_vgr   	exit_json)r   old_vg_existsnew_vg_existss      r   runzLvgRename.runM   s     	**dgg*6**dkk*:%%*SW[WbWb*c%d!%UY]YdYd%eE"%%%44%%^b^e^egkgrgr*s%t,,r   c                 |    | j                   j                  d   | _        | j                   j                  d   | _        y)z$Load the parameters from the module.r
   r   N)r   paramsr
   r   )r   s    r   r   zLvgRename._load_paramsc   s0     ++$$T*kk((2r   c                 j   | j                   j                  dd      }|dddddg}| j                   j                  |d	      \  }}}|j                         D ]Z  }|j	                         j                  d      \  }}| j                  j                  |       | j                  j                  |       \ y
)zLoad the VGs from the system.vgsTr	   z--noheadingsz--separator;z-ozvg_name,vg_uuidcheck_rcN)r   get_bin_pathrun_command
splitlinesstripsplitr   append)r   vgs_cmdvgs_cmd_with_optsdummyvg_raw_listvg_infovg_namevg_uuids           r   r   zLvgRename._load_vg_listi   s     ++**54*@$nmS$Pab$(KK$;$;<MX\$;$]!{E"--/ 	)G&}}44S9GWLL(LL(	)r   c                 n    d}d}|j                  |      r|t        |      d }n|}|| j                  v }|S )z
        Checks VG existence by name or UUID. It removes the '/dev/' prefix before checking.

        :param vg: A string with the name or UUID of the VG.
        :returns: A boolean indicates whether the VG exists or not.
        Fz/dev/N)
startswithlenr   )r   r
   vg_found
dev_prefixvg_ids        r   r   zLvgRename._is_vg_existsu   sC     
==$s:'(EEDLL(r   c                    | j                   j                  dd      }| j                   j                  r*d| j                  id| j                  id| j
                  d<   | j                   j                  r:d| j                  d| j                  d	| j
                  d
<   d| j
                  d<   y|| j                  | j                  g}| j                   j                  |d      \  }}}|| j
                  d
<   d| j
                  d<   y)zRenames the volume group.vgrenameTr'   r
   )beforeafterdiffz2Running in check mode. The module would rename VG z to .r   r   r)   N)r   r+   _diffr
   r   r   
check_moder,   )r   vgrename_cmdvgrename_cmd_with_optsr3   vg_rename_outs        r   r   zLvgRename._rename_vg   s     {{//
T/J;;.2DGG_dkkGZ"[DKK;;!!bfbibikokvkv!wDKK%)DKK	"&2DGGT[[%I"*.++*A*ABXcg*A*h'E=%!.DKK%)DKK	"r   N)	__name__
__module____qualname__r   r"   r   r   r   r   r   r   r   r   r   A   s     	-,3
)(*r   r   c                  (    t        t        d      } | S )NT)argument_specsupports_check_mode)r   rM   r   s    r   setup_module_objectrP      s    /35FMr   c                  P    t               } t        |       }|j                          y )NrO   )rP   r   r"   )r   
lvg_renames     r   mainrS      s     "F&)JNNr   __main__N)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESansible.module_utils.basicr   dictrM   objectr   rP   rS   rI   r   r   r   <module>r\      sr    A @ D
 5'UT+X* X*v zF r   