3 ܓim @s@ddlZddlmZddlmZddlmZGdddeZdS)N)quote)ContainerRuntime)sos_get_command_outputc@s:eZdZdZdZdZddZdddZd d Zd d Z d S)CrioContainerRuntimez-Runtime class to use for systems running crioZcrioZcrictlcCsdS)NF)selfrr/usr/lib/python3.6/crio.pycheck_can_copysz#CrioContainerRuntime.check_can_copyFcCs~g}|jd|rdndd}|jrzt||jjd}|ddkrztj|d}x*|d D]}|j|d |d d fqXW|S) 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-az -o json)chrootstatusroutput containersidZmetadataname)binaryactiverpolicysysrootjsonloadsappend)rZget_allrZ_cmdoutout_json containerrrrget_containerss z#CrioContainerRuntime.get_containerscCsg}|jrt|jd|jjd}|ddkrtj|d}x|dD]|}t|ddkrxf|dD]}|j||dfqdWqFt|d dkrd }n|d dj d d}|j|d |dfqFW|S) zGet a list of images present on the system :returns: A list of 2-tuples containing (image_name, image_id) :rtype: ``list`` z images -o json)r r rr imagesZrepoTagsrZ repoDigestsz@z:) rrrrrrrlenrsplit)rrrrZimageZrepo_tagZ image_namerrr get_images,s   zCrioContainerRuntime.get_imagescCs>|rt|}n|}|j|}|dk r:|jd|d|SdS)aFormat 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`` N r )rZget_container_by_nameZrun_cmd)rrcmdZquotecmdZ quoted_cmdZ container_idrrrfmt_container_cmdEs   z&CrioContainerRuntime.fmt_container_cmdN)F) __name__ __module__ __qualname____doc__rrr rr r#rrrrrs r)rZshlexrZsos.policies.runtimesrZ sos.utilitiesrrrrrr s