a >hm @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.9/site-packages/sos/policies/runtimes/crio.pycheck_can_copysz#CrioContainerRuntime.check_can_copyFcCszg}|jd|rdndd}|jrvt||jjd}|ddkrvt|d}|d D]}||d |d d fqV|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 jsonchrootstatusroutput containersidmetadataname)binaryactiverpolicysysrootjsonloadsappend)rZget_allrZ_cmdoutout_json containerrrrget_containerss  z#CrioContainerRuntime.get_containerscCsg}|jrt|jd|jjd}|ddkrt|d}|dD]x}t|ddkrz|dD]}|||dfq`qDt|d dkrd }n|d d d d}||d |dfqD|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 jsonr r rrimagesZrepoTagsrZ repoDigestsz@z:) rrrrrrrlenrsplit)rrrrZimageZrepo_tagZ image_namerrr get_images,s     zCrioContainerRuntime.get_imagescCs>|rt|}n|}||}|dur:|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