
    Vh                         d dl mZmZmZ eZdZdZd dlZd dl	m
Z
 d dlmZ d Zd Zd	 Zd
 ZddZd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: xattr
short_description: Manage user defined extended attributes
description:
  - Manages filesystem user defined extended attributes.
  - Requires that extended attributes are enabled on the target filesystem and that the C(setfattr)/C(getfattr) utilities
    are present.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  path:
    description:
      - The full path of the file/object to get the facts of.
    type: path
    required: true
    aliases: [name]
  namespace:
    description:
      - Namespace of the named name/key.
    type: str
    default: user
  key:
    description:
      - The name of a specific Extended attribute key to set/retrieve.
    type: str
  value:
    description:
      - The value to set the named name/key to, it automatically sets the O(state) to V(present).
    type: str
  state:
    description:
      - Defines which state you want to do.
      - V(read) retrieves the current value for a O(key).
      - V(present) sets O(path) to O(value), default if value is set.
      - V(all) dumps all data.
      - V(keys) retrieves all keys.
      - V(absent) deletes the key.
    type: str
    choices: [absent, all, keys, present, read]
    default: read
  follow:
    description:
      - If V(true), dereferences symlinks and sets/gets attributes on symlink target, otherwise acts on symlink itself.
    type: bool
    default: true
author:
  - Brian Coca (@bcoca)
a  
- name: Obtain the extended attributes of /etc/foo.conf
  community.general.xattr:
    path: /etc/foo.conf

- name: Set the key 'user.foo' to value 'bar'
  community.general.xattr:
    path: /etc/foo.conf
    key: foo
    value: bar

- name: Set the key 'trusted.glusterfs.volume-id' to value '0x817b94343f164f199e5b573b4ea1f914'
  community.general.xattr:
    path: /mnt/bricks/brick1
    namespace: trusted
    key: glusterfs.volume-id
    value: "0x817b94343f164f199e5b573b4ea1f914"

- name: Remove the key 'user.foo'
  community.general.xattr:
    path: /etc/foo.conf
    key: foo
    state: absent

- name: Remove the key 'trusted.glusterfs.volume-id'
  community.general.xattr:
    path: /mnt/bricks/brick1
    namespace: trusted
    key: glusterfs.volume-id
    state: absent
N)AnsibleModule)	to_nativec                     | j                  dd      dg}|s|j                  d       |j                  |       t        | |      S )NgetfattrT--absolute-names-hget_bin_pathappend
_run_xattr)modulepathfollowcmds       k/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/xattr.pyget_xattr_keysr   h   sB    z402D
EC

4JJtfc""    c                     | j                  dd      dg}|s|j                  d       ||j                  d       n"|j                  d       |j                  |       |j                  |       t        | |d      S )Nr	   Tr
   r   z-d-nFr   r   r   keyr   r   s        r   	get_xattrr   r   sl    z402D
EC

4
{

4

4

3JJtfc5))r   c                    | j                  dd      g}|s|j                  d       |j                  d       |j                  |       |j                  d       |j                  |       |j                  |       t        | |      S )NsetfattrTr   r   z-vr   )r   r   r   valuer   r   s         r   	set_xattrr      sn    z40
1C

4JJtJJsOJJtJJuJJtfc""r   c                     | j                  dd      g}|s|j                  d       |j                  d       |j                  |       |j                  |       t        | |d      S )Nr   Tr   z-xFr   r   s        r   rm_xattrr!      sX    z40
1C

4JJtJJsOJJtfc5))r   c                 `   	 | j                  ||      \  }}}i }j	                         D ]L  }|j                  d      s|dk(  rd|v r*|j                  dd      \  }	}
|
j                  d      ||	<   Hd||<   N |S # t        $ r(}| j                  dt        |      z         Y d }~d }~ww xY w)	N)check_rcz%s!msg# =   ")run_command	Exception	fail_jsonr   
splitlines
startswithsplitstrip)r   r   r#   rcouterreresultliner   vals              r   r   r      s    3++C(+CS#
 F  ??342:D[C+JS#))C.F3KF4L M  3UYq\1223s   A< <	B-B((B-c                     t        t        t        dddg      t        dd      t        dd	      t        d
      t        ddg d      t        dd            d      } | j                  j                  d      }| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }t        j
                  j                  |      s| j                  d       d}d}i }	||dv r| j                  d|z         |-|+t        |      dkD  r|dk(  r|j                  d      s|d|}|dk(  s|Ct        | |||      }
|
||
vs||
|   k7  r| j                  st        | ||||      }	d}|
}	|d|}n{|d k(  r8t        | |||      }
|
 ||
v r| j                  st        | |||      }	d}|
}	d!|z  }n>|d"k(  rt        | ||      }	d#}n)|d$k(  rt        | |d |      }	d%}nt        | |||      }	d&|z  }| j                  |||	'       y )(Nr   Tname)typerequiredaliasesstruser)r;   defaultF)r;   no_log)r;   read)absentallkeyspresentrB   )r;   r@   choicesbool)r   	namespacer   r   stater   )argument_specsupports_check_moderI   r   r   rJ   r   z!path not found or not accessible!r$   r'   )rC   rF   z%s needs a key parameterr   zuser..rF   z set to rC   z
%s removedrE   zreturning all keysrD   zdumping allzreturning %s)changedr%   xattr)r   dictparamsgetosr   existsr-   lenr/   r   
check_moder   r!   r   	exit_json)r   r   rI   r   r   rJ   r   rN   r%   rescurrents              r   mainrZ      sx   6D6(Cv6%.E"E6;ghVT2
 !
F ==V$D!!+.I
--

E
"CMMg&EMMg&E]]x(F77>>$@AG
C
C
{u 557%?@ O!	NQf$)@"C(e/FD#v6?c0EWS\4I$$c5&AG #U+	(	FD#v63'>$$vtS&9Gc"	&VT62"	%dF3c62s"
W#S9r   __main__)T)
__future__r   r   r   r;   __metaclass__DOCUMENTATIONEXAMPLESrS   ansible.module_utils.basicr   +ansible.module_utils.common.text.convertersr   r   r   r   r!   r   rZ   __name__ r   r   <module>rd      sc    A @4l@ 
 5 A#*#	*(?:D zF r   