U
    ™K7\Ú  ã                   @   s@   d dl mZ ddlmZmZ G dd„ deƒZG dd„ deƒZdS )	é   )Úerrorsé   )Ú
CollectionÚModelc                   @   sr   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZedd	„ ƒZd
d„ Z	dd„ Z
ddd„Zdd„ Zddd„Zddd„ZdS )ÚPluginz!
    A plugin on the server.
    c                 C   s   d| j j| jf S )Nz
<%s: '%s'>)Ú	__class__Ú__name__Úname©Úself© r   ú7/usr/lib/python3/dist-packages/docker/models/plugins.pyÚ__repr__	   s    zPlugin.__repr__c                 C   s   | j  d¡S )z$
        The plugin's name.
        ÚName©ZattrsÚgetr
   r   r   r   r	      s    zPlugin.namec                 C   s   | j  d¡S )z0
        Whether the plugin is enabled.
        ZEnabledr   r
   r   r   r   Úenabled   s    zPlugin.enabledc                 C   s   | j  d¡S )zG
        A dictionary representing the plugin's configuration.
        ZSettingsr   r
   r   r   r   Úsettings   s    zPlugin.settingsc                 C   s   | j j | j|¡ |  ¡  dS )a  
            Update the plugin's settings.

            Args:
                options (dict): A key-value mapping of options.

            Raises:
                :py:class:`docker.errors.APIError`
                    If the server returns an error.
        N)ÚclientÚapiZconfigure_pluginr	   Úreload)r   Zoptionsr   r   r   Ú	configure!   s    zPlugin.configurec                 C   s   | j j | j¡ |  ¡  dS )z¥
            Disable the plugin.

            Raises:
                :py:class:`docker.errors.APIError`
                    If the server returns an error.
        N)r   r   Zdisable_pluginr	   r   r
   r   r   r   Údisable/   s    	zPlugin.disableé    c                 C   s   | j j | j|¡ |  ¡  dS )zõ
            Enable the plugin.

            Args:
                timeout (int): Timeout in seconds. Default: 0

            Raises:
                :py:class:`docker.errors.APIError`
                    If the server returns an error.
        N)r   r   Zenable_pluginr	   r   )r   Ztimeoutr   r   r   Úenable;   s    zPlugin.enablec                 C   s   | j j | j¡S )a  
            Push the plugin to a remote registry.

            Returns:
                A dict iterator streaming the status of the upload.

            Raises:
                :py:class:`docker.errors.APIError`
                    If the server returns an error.
        )r   r   Zpush_pluginr	   r
   r   r   r   ÚpushI   s    zPlugin.pushFc                 C   s   | j jj| j|dS )a.  
            Remove the plugin from the server.

            Args:
                force (bool): Remove even if the plugin is enabled.
                    Default: False

            Raises:
                :py:class:`docker.errors.APIError`
                    If the server returns an error.
        )Úforce)r   r   Zremove_pluginr	   )r   r   r   r   r   ÚremoveV   s    zPlugin.removeNc                 c   sX   | j rt d¡‚|dkr| j}| jj |¡}| jj | j||¡D ]
}|V  q@|  ¡  dS )aR  
            Upgrade the plugin.

            Args:
                remote (string): Remote reference to upgrade to. The
                    ``:latest`` tag is optional and is the default if omitted.
                    Default: this plugin's name.

            Returns:
                A generator streaming the decoded API logs
        z)Plugin must be disabled before upgrading.N)	r   r   ZDockerErrorr	   r   r   Úplugin_privilegesZupgrade_pluginZ_reload)r   ZremoteÚ
privilegesÚdr   r   r   Úupgraded   s    ÿzPlugin.upgrade)r   )F)N)r   Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr	   r   r   r   r   r   r   r   r!   r   r   r   r   r      s   




r   c                   @   s4   e Zd ZeZddd„Zdd„ Zddd„Zd	d
„ ZdS )ÚPluginCollectionFc                 C   s   | j j |||¡ |  |¡S )aC  
            Create a new plugin.

            Args:
                name (string): The name of the plugin. The ``:latest`` tag is
                    optional, and is the default if omitted.
                plugin_data_dir (string): Path to the plugin data directory.
                    Plugin data directory must contain the ``config.json``
                    manifest file and the ``rootfs`` directory.
                gzip (bool): Compress the context using gzip. Default: False

            Returns:
                (:py:class:`Plugin`): The newly created plugin.
        )r   r   Zcreate_pluginr   )r   r	   Zplugin_data_dirZgzipr   r   r   Úcreate€   s    zPluginCollection.createc                 C   s   |   | jj |¡¡S )ah  
        Gets a plugin.

        Args:
            name (str): The name of the plugin.

        Returns:
            (:py:class:`Plugin`): The plugin.

        Raises:
            :py:class:`docker.errors.NotFound` If the plugin does not
            exist.
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        )Úprepare_modelr   r   Zinspect_plugin)r   r	   r   r   r   r   ’   s    zPluginCollection.getNc                 C   s8   | j j |¡}| j j |||¡}|D ]}q$|  |p4|¡S )a‚  
            Pull and install a plugin.

            Args:
                remote_name (string): Remote reference for the plugin to
                    install. The ``:latest`` tag is optional, and is the
                    default if omitted.
                local_name (string): Local name for the pulled plugin.
                    The ``:latest`` tag is optional, and is the default if
                    omitted. Optional.

            Returns:
                (:py:class:`Plugin`): The installed plugin
            Raises:
                :py:class:`docker.errors.APIError`
                    If the server returns an error.
        )r   r   r   Zpull_pluginr   )r   Zremote_nameZ
local_namer   ÚitÚdatar   r   r   Úinstall¤   s
    zPluginCollection.installc                    s   ˆ j j ¡ }‡ fdd„|D ƒS )zð
        List plugins installed on the server.

        Returns:
            (list of :py:class:`Plugin`): The plugins.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        c                    s   g | ]}ˆ   |¡‘qS r   )r(   )Ú.0Úrr
   r   r   Ú
<listcomp>È   s     z)PluginCollection.list.<locals>.<listcomp>)r   r   Zplugins)r   Zrespr   r
   r   Úlist¼   s    zPluginCollection.list)F)N)	r   r"   r#   r   Zmodelr'   r   r+   r/   r   r   r   r   r&   }   s
   

r&   N)Ú r   Úresourcer   r   r   r&   r   r   r   r   Ú<module>   s   x