
    Vhy                     `    d dl mZmZmZ eZdZdZdZd dl	m
Z
 d Zd Zd Zed	k(  r e        y
y
)    )absolute_importdivisionprint_functiona  
module: podman_prune
author:
    - 'Roberto Alfieri (@rebtoor)'
version_added: '1.10.0'
short_description: Allows to prune various podman objects
notes: []
description:
    - Allows to run C(podman container prune), C(podman image prune), C(podman network prune),
      C(podman volume prune) and C(podman system prune)
requirements:
    - 'Podman installed on host'
options:
    executable:
        description:
            - Podman binary.
        type: str
        default: podman
    container:
        description:
            - Whether to prune containers.
        type: bool
        default: false
    container_filters:
        description:
            - A dictionary of filter values used for selecting containers to delete.
            - 'For example, C(until: 24h).'
            - See L(the podman documentation,
              https://docs.podman.io/en/latest/markdown/podman-container-prune.1.html#filter-filters)
              for more information on possible filters.
        type: dict
    image:
        description:
            - Whether to prune images.
        type: bool
        default: false
    image_filters:
        description:
            - A dictionary of filter values used for selecting images to delete.
            - 'You can also use C(dangling_only: false) to delete dangling and non-dangling images or C(external: true)
              to delete images even when they are used by external containers.'
            - See L(the podman documentation,
              https://docs.podman.io/en/latest/markdown/podman-image-prune.1.html#filter-filters)
              for more information on possible filters.
        type: dict
    network:
        description:
            - Whether to prune networks.
        type: bool
        default: false
    network_filters:
        description:
            - A dictionary of filter values used for selecting networks to delete.
            - See L(the podman documentation,
              https://docs.podman.io/en/latest/markdown/podman-network-prune.1.html#filter)
              for more information on possible filters.
        type: dict
    system:
        description:
            - Whether to prune unused pods, containers, image, networks and volume data
        type: bool
        default: false
    system_all:
        description:
            - Whether to prune all unused images, not only dangling images.
        type: bool
        default: false
    system_volumes:
        description:
            - Whether to prune volumes currently unused by any container.
        type: bool
        default: false
    volume:
        description:
            - Whether to prune volumes.
        type: bool
        default: false
    volume_filters:
        description:
            - A dictionary of filter values used for selecting volumes to delete.
            - See L(the podman documentation,
              https://docs.podman.io/en/latest/markdown/podman-volume-prune.1.html#filter)
              for more information on possible filters.
        type: dict
a  
- name: Prune containers older than 24h
  containers.podman.podman_prune:
      containers: true
      containers_filters:
          # only consider containers created more than 24 hours ago
          until: 24h

- name: Prune everything
  containers.podman.podman_prune:
      system: true

- name: Prune everything (including non-dangling images)
  containers.podman.podman_prune:
      system: true
      system_all: true
      system_volumes: true
aW  
# containers
containers:
    description:
      - List of IDs of deleted containers.
    returned: I(containers) is C(true)
    type: list
    elements: str
    sample: []

# images
images:
    description:
      - List of IDs of deleted images.
    returned: I(images) is C(true)
    type: list
    elements: str
    sample: []

# networks
networks:
    description:
      - List of IDs of deleted networks.
    returned: I(networks) is C(true)
    type: list
    elements: str
    sample: []

# volumes
volumes:
    description:
      - List of IDs of deleted volumes.
    returned: I(volumes) is C(true)
    type: list
    elements: str
    sample: []

# system
system:
  description:
    - List of ID of deleted containers, volumes, images, network and total reclaimed space
  returned: I(system) is C(true)
  type: list
  elements: str
  sample: []
)AnsibleModulec           
         g }| dk(  r|D ]  }|j                  ||           |S |D ]  }t        ||   t              r3||   }|D ](  }|j                  dj                  ||||                * I| dk(  r=|dv r9|dk(  r|d   s|j                  d       |dk(  ss|d   sy|j                  d	       |j                  d
j                  |||                 |S )Nsystemz--filter={label}={key}={value})labelkeyvalueimage)dangling_onlyexternalr   z-ar   z
--externalz--filter={label}={value})r	   r   )append
isinstancedictformat)targetfilters
filter_outsystem_filtercommon_filterdict_filterssingle_filters          r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/containers/podman/plugins/modules/podman_prune.pyfiltersPreparer      s,   J$ 	6Mgm45	6& ! % 	gM'-0$7&}5%1 rM%%&F&M&MTagtT`anTo 'N 'q rr W$-;X*X$7@X"))$/$
2wz7J")),7%%&@&G&GmNUVcNd 'H 'f g	g      c                 ,   ||ddg}||j                  t        ||             | j                  |      \  }}}t        |      }|dk7  r#| j	                  dj                  ||             d||t        t        d |j                  d                  d	|iS )
Nprunez--forcer   z(Error executing prune on {target}: {err})r   err)msgchanged
errors)	extendr   run_commandbool	fail_jsonr   listfiltersplit)	moduler   r   
executablecommandrcoutr   r!   s	            r   
podmanExecr0      s    67I6G~fg67%%g.LBS3iG	Qw:AAUXAY 	 	[ 	7VD#))D/23# r   c                     t               } t        t        dd      t        d      t        dd      t        d      t        dd      t        d      t        dd      t        d      t        dd      t        dd      t        dd      t        dd            }t        |	      }|j                  |j                  d
   d      }dD ]3  \  }}|j                  |   st	        |||j                  |   |      | |<   5 |j                  d   r=d}i }|j                  d   rd|d<   |j                  d   rd|d<   t	        ||||      | |<    |j
                  di |  y )Nr&   F)typedefaultr   )r2   strpodman)	containercontainer_filtersr   image_filtersnetworknetwork_filtersvolumevolume_filtersr   
system_allsystem_volumesr,   )argument_specr,   T)required))r6   r7   )r   r8   )r9   r:   )r;   r<   r   r=   z--allr>   z	--volumes )r   r   get_bin_pathparamsr0   	exit_json)resultsmodule_argsr+   r,   r   r   system_filterss          r   mainrH      sg   fGFE2F+.'&%0&)/(/VU37UH5K !F $$l#d % 4J* ] == (w9OQ[\GFO	] }}X==&+2N<(==)*/:N+,$VV^ZPFwr   __main__N)
__future__r   r   r   r2   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   r   r0   rH   __name__rA   r   r   <module>rQ      sT    A @Tl&-
` 52$' T zF r   