o
    *bk  ã                   @   s8   d dl mZ d dlmZ d dlmZ G dd„ deƒZdS )é    )ÚContainerRuntime)Úsos_get_command_output)Úquotec                   @   s:   e Zd ZdZdZdZdd„ Zddd„Zd	d
„ Zdd„ Z	dS )ÚCrioContainerRuntimez-Runtime class to use for systems running crioZcrioZcrictlc                 C   s   dS )NF© )Úselfr   r   ú</usr/lib/python3/dist-packages/sos/policies/runtimes/crio.pyÚcheck_can_copy   s   z#CrioContainerRuntime.check_can_copyFc                 C   sx   g }d| j |r	dndf }| jr:t|| jjd}|d dkr:|d  ¡ dd	… D ]}| ¡ }| |d |d
 f¡ q(|S )zœGet a list of containers present on the system.

        :param get_all: If set, include stopped containers as well
        :type get_all: ``bool``
        z%s ps %sz-aÚ ©ÚchrootÚstatusr   Úoutputé   Néýÿÿÿ)ÚbinaryÚactiver   ÚpolicyÚsysrootÚ
splitlinesÚsplitÚappend)r   Zget_allZ
containersZ_cmdÚoutÚentr   r   r   Úget_containers   s   z#CrioContainerRuntime.get_containersc                 C   sl   g }| j r4td| j | jjd}|d dkr4|d  ¡ D ]}| ¡ }| |d d |d  |d f¡ q|S )	z”Get a list of images present on the system

        :returns: A list of 2-tuples containing (image_name, image_id)
        :rtype: ``list``
        z	%s imagesr   r   r   r   ú:r   é   )r   r   r   r   r   r   r   r   )r   Zimagesr   r   r   r   r   Ú
get_images*   s   
ÿ$zCrioContainerRuntime.get_imagesc                 C   s8   |rt |ƒ}n|}|  |¡}|durd| j||f S dS )aÀ  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``
        Nz%s %s %sr
   )r   Zget_container_by_nameZrun_cmd)r   Ú	containerÚcmdZquotecmdZ
quoted_cmdZcontainer_idr   r   r   Úfmt_container_cmd;   s   


ÿÿÿz&CrioContainerRuntime.fmt_container_cmdN)F)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Únamer   r	   r   r   r    r   r   r   r   r      s    
r   N)Zsos.policies.runtimesr   Zsos.utilitiesr   Zpipesr   r   r   r   r   r   Ú<module>   s   
