Current File : //usr/lib/python3/dist-packages/sos/policies/runtimes/__pycache__/lxd.cpython-312.pyc
�

-�_gI��F�ddlZddlmZddlmZddlmZGd�de�Zy)�N)�ContainerRuntime)�sos_get_command_output)�
is_executablec�@�eZdZdZdZdZd�Zdd�Zd�Zd�Z	d�Z
dd
�Zy	)
�LxdContainerRuntimez,Runtime class to use for systems running LXD�lxd�lxcc�2�td|jj�rw|jjj	d�rR|jj
j
d�s%|jj
j
d�rd|_yy)Nr	rzsnap.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_activez#LxdContainerRuntime.check_is_activesl���%����!4�!4�5����+�+�7�7��>����(�(�3�3�E�:����(�(�3�3�4E�F��D�K���c��g}|j�d�}|jrot||jj��}|ddk(rFtj|d�}|D])}|ddk(s|s�|j|dd|d	f��+|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�output�Running�expanded_configz
volatile.uuid�name)�binaryrrrr�json�loads�append)r�get_all�
containers�_cmd�out�out_json�	containers       r�get_containersz"LxdContainerRuntime.get_containers"s����
��+�+��1�2���;�;�(��d�k�k�6I�6I�J�C��8�}��!��:�:�c�(�m�4��!)�1�I� ��*�i�7�7�"�)�)�&�'8�9�/�J�&�v�.�0�1�1��rc��g}|jrvt|j�d�|jj��}|ddk(r@tj|d�}|D]#}d|vs�|j|dd|df��%|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 jsonrrrr�
update_source�alias�fingerprint�rrrrrrr r!)r�imagesr%r&�ents     r�
get_imageszLxdContainerRuntime.get_images:s������;�;�(��;�;�-�8�9��{�{�*�*��C��8�}��!��:�:�c�(�m�4��#�1�C�&�#�-��
�
���0��9��
�.�'0�1�1��
rc���g}d}|jr�t|j�d�|jj��}|ddk(r<tj|d�}|D]}|ddk(s�d|d	vs�|d	dd
}nt|j�d|�d�|jj��}|ddk(r3tj|d�}|D]}|j|d��|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 jsonrrrrr�root�devices�poolz storage volume list z --format jsonr-)r�vols�stg_poolr%r&�profiler/s       r�get_volumeszLxdContainerRuntime.get_volumesPs�������;�;�)��;�;�-�:�;��{�{�*�*��C��8�}��!��:�:�c�(�m�4��'��G����9�4�"�g�i�&8�8�#*�9�#5�f�#=�f�#E���	�)��;�;�-�4�X�J�n�M��{�{�*�*��C��8�}��!��:�:�c�(�m�4��#�-�C��K�K��F��,�-��rc�&�|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)rr's  r�get_logs_commandz$LxdContainerRuntime.get_logs_commandqs���+�+��f�Y�K�{�;�;rNc�`�|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 )�run_cmdr)rr'�path�dest�	sizelimits     r�get_copy_commandz$LxdContainerRuntime.get_copy_command}sG��,��l�l�^�1�Y�K�y���1�T�F�K�K��+�+��k�)��T�F�!�D�6�B�Br)F)N)�__name__�
__module__�__qualname__�__doc__rrrr(r0r9r;rB�rrrrs/��6��D�
�F���0�,�B
<�Crr)r�sos.policies.runtimesr�
sos.utilitiesrrrrGrr�<module>rJs$���2�0�'�CC�*�CCr