
    ~ gm                     F    S SK r S SKJr  S SKJr  S SKJr   " S S\5      rg)    N)quote)ContainerRuntime)sos_get_command_outputc                   <    \ rS rSrSrSrSrS rSS jrS r	S r
S	rg
)CrioContainerRuntime   z-Runtime class to use for systems running criocriocrictlc                     g)NF )selfs    </usr/lib/python3/dist-packages/sos/policies/runtimes/crio.pycheck_can_copy#CrioContainerRuntime.check_can_copy   s        c                 0   / nU R                    SU(       a  SOS S3nU R                  (       ag  [        X0R                  R                  S9nUS   S:X  aA  [
        R                  " US   5      nUS	    H  nUR                  US
   US   S   45        M!     U$ )zGet a list of containers present on the system.

:param get_all: If set, include stopped containers as well
:type get_all: ``bool``
z ps z-a z -o jsonchrootstatusr   output
containersidmetadataname)binaryactiver   policysysrootjsonloadsappend)r   get_allr   _cmdoutout_json	containers          r   get_containers#CrioContainerRuntime.get_containers   s     
++d74";8D;;(kk6I6IJC8}!::c(m4!),!7I%%"4)J*?*GHJ "8 r   c                    / nU R                   (       a  [        U R                   S3U R                  R                  S9nUS   S:X  a  [
        R                  " US   5      nUS    H  n[        US   5      S:  a#  US    H  nUR                  XTS   45        M     M8  [        US	   5      S:X  a  S
nOUS	   S   R                  S5      S   nUR                  US-   US   45        M     U$ )z|Get a list of images present on the system

:returns: A list of 2-tuples containing (image_name, image_id)
:rtype: ``list``
z images -o jsonr   r   r   r   imagesrepoTagsr   repoDigestsz<none>@z:<none>)
r   r   r   r   r   r    r!   lenr"   split)r   r+   r%   r&   imagerepo_tag
image_names          r   
get_imagesCrioContainerRuntime.get_images,   s     ;;(DKK=)H040C0CEC8}!::c(m4%h/E5,-1(-j(9H"MM84[*AB ): u]349)1J).})=a)@)F)Fs)KA)NJzI'=uT{&KL 0 r   c                     U(       a  [        U5      nOUnU R                  U5      nUb  U R                   SU SU 3$ S$ )ax  Format a command to run inside a container using the runtime

:param container: The name or ID of the container in which to run
:type container: ``str``

:param cmd: The command to run inside `container`
:type cmd: ``str``

:param quotecmd: Whether the cmd should be quoted.
:type quotecmd: ``bool``

:returns: Formatted string to run `cmd` inside `container`
:rtype: ``str``
 r   )r   get_container_by_namerun_cmd)r   r'   cmdquotecmd
quoted_cmdcontainer_ids         r   fmt_container_cmd&CrioContainerRuntime.fmt_container_cmdE   sR     sJJ11)<+ <<.,q= 	513	5r   r   N)F)__name__
__module____qualname____firstlineno____doc__r   r   r   r(   r4   r>   __static_attributes__r   r   r   r   r      s#    7DF$25r   r   )r    shlexr   sos.policies.runtimesr   sos.utilitiesr   r   r   r   r   <module>rI      s"      2 0I5+ I5r   