EVOLUTION-MANAGER
Edit File: lxd.cpython-36.pyc
3 �f � @ s@ d dl Z d dlmZ d dlmZ d dlmZ G dd� de�ZdS )� N)�ContainerRuntime)�sos_get_command_output)� is_executablec @ sL e Zd ZdZdZdZdd� Zddd�Zd d � Zdd� Z d d� Z ddd�ZdS )�LxdContainerRuntimez,Runtime class to use for systems running LXD�lxd�lxcc C s8 t d| jj�r4| jjjd�s*| jjjd�r4d| _dS dS )Nr r zsnap.lxd.daemonTF)r �policy�sysrootZinit_systemZ is_running�active)�self� r �/usr/lib/python3.6/lxd.py�check_is_active s z#LxdContainerRuntime.check_is_activeFc C s| g }| j � d�}| jrxt|| jjd�}|d dkrxtj|d �}x6|D ].}|d dksZ|rF|j|d d |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 r r r �json�loads�append)r Zget_allZ containersZ_cmd�out�out_json� containerr r r �get_containers! s z"LxdContainerRuntime.get_containersc C sp g }| j rlt| j� d�| jjd�}|d dkrltj|d �}x.|D ]&}d|krB|j|d d |d f� 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)r r r r Z update_source�aliasZfingerprint)r r r r r r r r )r Zimagesr r �entr r r � get_images9 s zLxdContainerRuntime.get_imagesc C s� g }d}| j r�t| j� d�| jjd�}|d dkrxtj|d �}x6|D ].}|d dkrFd|d krF|d d d }P qFW t| j� d|� d�| jjd�}|d dkr�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)r r r r r �rootZdevicesZpoolz storage volume list z --format json)r r r r r r r r )r ZvolsZstg_poolr r Zprofiler r r r �get_volumesO s* zLxdContainerRuntime.get_volumesc C s | 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 )r r r r r �get_logs_commandp s z$LxdContainerRuntime.get_logs_commandNc C s: |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 )r r �path�destZ sizelimitr r r �get_copy_command| s z$LxdContainerRuntime.get_copy_command)F)N)�__name__� __module__�__qualname__�__doc__r r r r r r r! r% r r r r r s !r )r Zsos.policies.runtimesr Z sos.utilitiesr r r r r r r �<module> s