a
   Ev                   @   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   9/usr/lib/python3.9/site-packages/docker/models/plugins.py__repr__	   s    zPlugin.__repr__c                 C   s   | j dS )z$
        The plugin's name.
        Name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   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   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u 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_pluginr   )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_dir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>       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/   r4   r   r   r   r   r)   }   s
   

r)   N) r   resourcer   r   r   r)   r   r   r   r   <module>   s   x