Sindbad~EG File Manager
3
�f�
� @ s@ d dl Z d dlmZ d dlmZ d dlmZ G dd� de�ZdS )� N)�ContainerRuntime)�sos_get_command_output)�quotec @ s: e Zd ZdZdZdZdd� Zddd�Zd d
� Zdd� Z d
S )�CrioContainerRuntimez-Runtime class to use for systems running crioZcrioZcrictlc C s dS )NF� )�selfr r �/usr/lib/python3.6/crio.py�check_can_copy s z#CrioContainerRuntime.check_can_copyFc C sz g }d| j |rdndf }| jrvt|| jjd�}|d dkrvtj|d �}x*|d D ]}|j|d |d
d f� qTW |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 %s -o jsonz-a� )�chroot�statusr �output�
containers�idZmetadata�name)�binary�activer �policy�sysroot�json�loads�append)r Zget_allr Z_cmd�out�out_json� containerr r r �get_containers s z#CrioContainerRuntime.get_containersc C s� g }| j r�td| j | jjd�}|d dkr�tj|d �}x�|d D ]|}t|d �dkr~xf|d D ]}|j||d f� qbW qDt|d �dkr�d
}n|d d j d�d }|j|d |d f� qDW |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 images -o json)r r r r
�imagesZrepoTagsr ZrepoDigestsz<none>�@z:<none>)
r r r r r r r �lenr �split)r r r r ZimageZrepo_tagZ
image_namer r r �
get_images, s
zCrioContainerRuntime.get_imagesc C s8 |rt |�}n|}| j|�}|dk r4d| j||f S dS )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 Zget_container_by_nameZrun_cmd)r r �cmdZquotecmdZ
quoted_cmdZcontainer_idr r r �fmt_container_cmdE s
z&CrioContainerRuntime.fmt_container_cmdN)F)
�__name__�
__module__�__qualname__�__doc__r r r r r r"