Sindbad~EG File Manager

Current Path : /lib/python3.6/site-packages/sos/policies/runtimes/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/sos/policies/runtimes/__pycache__/lxd.cpython-36.pyc

3

�f�@s@ddlZddlmZddlmZddlmZGdd�de�ZdS)�N)�ContainerRuntime)�sos_get_command_output)�
is_executablec@sLeZdZdZdZdZdd�Zddd�Zd	d
�Zdd�Z	d
d�Z
ddd�ZdS)�LxdContainerRuntimez,Runtime class to use for systems running LXD�lxd�lxccCs8td|jj�r4|jjjd�s*|jjjd�r4d|_dSdS)Nrrzsnap.lxd.daemonTF)r�policy�sysrootZinit_systemZ
is_running�active)�self�r�/usr/lib/python3.6/lxd.py�check_is_activesz#LxdContainerRuntime.check_is_activeFcCs|g}|j�d�}|jrxt||jjd�}|ddkrxtj|d�}x6|D].}|ddksZ|rF|j|dd|d	f�qFW|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 list --format json)�chroot�statusr�outputZRunningZexpanded_configz
volatile.uuid�name)�binaryr
rrr	�json�loads�append)rZget_allZ
containersZ_cmd�out�out_json�	containerrrr
�get_containers!s

z"LxdContainerRuntime.get_containerscCspg}|jrlt|j�d�|jjd�}|ddkrltj|d�}x.|D]&}d|krB|j|dd|df�qBW|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 image list --format json)rrrrZ
update_source�aliasZfingerprint)r
rrrr	rrr)rZimagesrr�entrrr
�
get_images9s


zLxdContainerRuntime.get_imagescCs�g}d}|jr�t|j�d�|jjd�}|ddkrxtj|d�}x6|D].}|ddkrFd|d	krF|d	dd
}PqFWt|j�d|�d�|jjd�}|ddkr�tj|d�}x|D]}|j|d�q�W|S)
z�Get a list of container volumes present on the system

        :returns: A list of volume IDs on the system
        :rtype: ``list``
        �defaultz profile list --format json)rrrrr�rootZdevicesZpoolz storage volume list z --format json)r
rrrr	rrr)rZvolsZstg_poolrrZprofilerrrr
�get_volumesOs*


zLxdContainerRuntime.get_volumescCs|j�d|�d�S)a!Get 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)rrrrr
�get_logs_commandps
z$LxdContainerRuntime.get_logs_commandNcCs:|r |j�d|�d|�d|��S|j�d|�|�d|��S)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 )Zrun_cmdr)rr�path�destZ	sizelimitrrr
�get_copy_command|sz$LxdContainerRuntime.get_copy_command)F)N)�__name__�
__module__�__qualname__�__doc__rrrrrr r!r%rrrr
rs	
!r)rZsos.policies.runtimesrZ
sos.utilitiesrrrrrrr
�<module>s

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists