
    ~ gI                     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)ContainerRuntime)sos_get_command_output)is_executablec                   L    \ rS rSrSrSrSrS rSS jrS r	S r
S	 rSS jrSrg
)LxdContainerRuntime   z,Runtime class to use for systems running LXDlxdlxcc                 Z   [        SU R                  R                  5      (       a  U R                  R                  R	                  S5      (       a\  U R                  R
                  R                  S5      (       d*  U R                  R
                  R                  S5      (       a  SU l        gg)Nr
   r	   zsnap.lxd.daemonTF)r   policysysrootpackage_managerpkg_by_nameinit_system
is_runningactive)selfs    ;/usr/lib/python3/dist-packages/sos/policies/runtimes/lxd.pycheck_is_active#LxdContainerRuntime.check_is_active   sx    %!4!455++77>>((33E::((334EFFDK    c                 6   / nU R                    S3nU R                  (       av  [        X0R                  R                  S9nUS   S:X  aP  [
        R                  " US   5      nU H1  nUS   S:X  d	  U(       d  M  UR                  US   S   US	   45        M3     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 list --format jsonchrootstatusr   outputRunningexpanded_configzvolatile.uuidname)binaryr   r   r   r   jsonloadsappend)r   get_all
containers_cmdoutout_json	containers          r   get_containers"LxdContainerRuntime.get_containers"   s     
++12;;(kk6I6IJC8}!::c(m4!)I *i777"))&'89/J&v.01 "* r   c                     / nU R                   (       az  [        U R                   S3U R                  R                  S9nUS   S:X  aF  [
        R                  " US   5      nU H'  nSU;   d  M  UR                  US   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 image list --format jsonr   r   r   r   update_sourcealiasfingerprintr   r   r    r   r   r!   r"   r#   )r   imagesr'   r(   ents        r   
get_imagesLxdContainerRuntime.get_images:   s     ;;(;;-89{{**C 8}!::c(m4#C&#-09.'0 1 $ r   c                    / nSnU R                   (       a  [        U R                   S3U R                  R                  S9nUS   S:X  aC  [
        R                  " US   5      nU H$  nUS   S:X  d  M  SUS	   ;   d  M  US	   S   S
   n  O   [        U R                   SU S3U R                  R                  S9nUS   S:X  a6  [
        R                  " US   5      nU H  nUR                  US   5        M     U$ )zuGet a list of container volumes present on the system

:returns: A list of volume IDs on the system
:rtype: ``list``
defaultz profile list --format jsonr   r   r   r   r   rootdevicespoolz storage volume list z --format jsonr0   )r   volsstg_poolr'   r(   profiler2   s          r   get_volumesLxdContainerRuntime.get_volumesP   s    ;; );;-:;{{**C 8}!::c(m4'G94"gi&88#*9#5f#=f#E	  ( );;-4XJnM{{**C 8}!::c(m4#CKKF, $r   c                 &    U R                    SU S3$ )zGet the command string used to dump container logs from the
runtime

:param container: The name or ID of the container to get logs for
:type container: ``str``

:returns: Formatted runtime command to get logs from `container`
:type: ``str``
z info z --show-log)r    )r   r)   s     r   get_logs_command$LxdContainerRuntime.get_logs_commandq   s     ++fYK{;;r   Nc                 j    U(       a  U R                    SU SU SU 3$ U R                   SU U SU 3$ )a  Generate the command string used to copy a file out of a container
by way of the runtime.

:param container:   The name or ID of the container
:type container:    ``str``

:param path:        The path to copy from the container. Note that at
                    this time, no supported runtime supports globbing
:type path:         ``str``

:param dest:        The destination on the *host* filesystem to write
                    the file to
:type dest:         ``str``

:param sizelimit:   Limit the collection to the last X bytes of the
                    file at PATH
:type sizelimit:    ``int``

:returns:   Formatted runtime command to copy a file from a container
:rtype:     ``str``
 z	 tail -c z file pull )run_cmdr    )r   r)   pathdest	sizelimits        r   get_copy_command$LxdContainerRuntime.get_copy_command}   sG    , ll^1YKy1TFKK++k)TF!D6BBr   )r   )F)N)__name__
__module____qualname____firstlineno____doc__r   r    r   r*   r3   r=   r@   rH   __static_attributes__ r   r   r   r      s/    6DF0,B
<Cr   r   )r!   sos.policies.runtimesr   sos.utilitiesr   r   r   rP   r   r   <module>rS      s$     2 0 'CC* CCr   