
    q_a                     0    d dl mZ d dl mZ  G d d      Zy)   )errors)utilsc                   `    e Zd ZddZ	 	 d	dZd Z ej                  d      dd       Zd
dZ	y)VolumeApiMixinNc                     d|rt        j                  |      ndi}| j                  d      }| j                  | j	                  ||      d      S )a  
        List volumes currently registered by the docker daemon. Similar to the
        ``docker volume ls`` command.

        Args:
            filters (dict): Server-side list filtering options.

        Returns:
            (dict): Dictionary with list of volume objects as value of the
            ``Volumes`` key.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.

        Example:

            >>> client.api.volumes()
            {u'Volumes': [{u'Driver': u'local',
               u'Mountpoint': u'/var/lib/docker/volumes/foobar/_data',
               u'Name': u'foobar'},
              {u'Driver': u'local',
               u'Mountpoint': u'/var/lib/docker/volumes/baz/_data',
               u'Name': u'baz'}]}
        filtersNz/volumesparamsT)r   convert_filters_url_result_getselfr   r
   urls       3/usr/lib/python3/dist-packages/docker/api/volume.pyvolumeszVolumeApiMixin.volumes   sM    8 u,,W5d
 ii
#||DIIc&I94@@    c                 d   | j                  d      }|t        |t              st        d      |||d}|Xt	        j
                  d| j                        dk  rt        j                  d      t        |t              st        d      ||d<   | j                  | j                  ||	      d
      S )a  
        Create and register a named volume

        Args:
            name (str): Name of the volume
            driver (str): Name of the driver used to create the volume
            driver_opts (dict): Driver options as a key-value dictionary
            labels (dict): Labels to set on the volume

        Returns:
            (dict): The created volume reference object

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.

        Example:

            >>> volume = client.api.create_volume(name='foobar', driver='local',
                    driver_opts={'foo': 'bar', 'baz': 'false'},
                    labels={"key": "value"})
            >>> print(volume)
            {u'Driver': u'local',
             u'Labels': {u'key': u'value'},
             u'Mountpoint': u'/var/lib/docker/volumes/foobar/_data',
             u'Name': u'foobar',
             u'Scope': u'local'}

        z/volumes/createz driver_opts must be a dictionary)NameDriver
DriverOptsz1.23    z)volume labels were introduced in API 1.23zlabels must be a dictionaryLabels)dataT)r   
isinstancedict	TypeErrorr   compare_version_versionr   InvalidVersionr   
_post_json)r   namedriverdriver_optslabelsr   r   s          r   create_volumezVolumeApiMixin.create_volume'   s    > ii)*":k4+H>?? %
 $$VT]];a?++?  fd+ =>>#DN||DOOCdO;TBBr   c                 h    | j                  d|      }| j                  | j                  |      d      S )a  
        Retrieve volume info by name.

        Args:
            name (str): volume name

        Returns:
            (dict): Volume information dictionary

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.

        Example:

            >>> client.api.inspect_volume('foobar')
            {u'Driver': u'local',
             u'Mountpoint': u'/var/lib/docker/volumes/foobar/_data',
             u'Name': u'foobar'}

        /volumes/{0}T)r   r   r   )r   r#   r   s      r   inspect_volumezVolumeApiMixin.inspect_volume[   s-    , ii-||DIIcND11r   1.25c                     i }|rt        j                  |      |d<   | j                  d      }| j                  | j	                  ||      d      S )a  
        Delete unused volumes

        Args:
            filters (dict): Filters to process on the prune list.

        Returns:
            (dict): A dict containing a list of deleted volume names and
                the amount of disk space reclaimed in bytes.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        r   z/volumes/pruner	   T)r   r   r   r   _postr   s       r   prune_volumeszVolumeApiMixin.prune_volumest   sN       % 5 5g >F9ii()||DJJs6J:DAAr   c                     i }|r9t        j                  | j                  d      rt        j                  d      d|i}| j                  d||      }| j                  |      }| j                  |       y)az  
        Remove a volume. Similar to the ``docker volume rm`` command.

        Args:
            name (str): The volume's name
            force (bool): Force removal of volumes that were already removed
                out of band by the volume driver plugin.

        Raises:
            :py:class:`docker.errors.APIError`
                If volume failed to remove.
        r+   z(force removal was introduced in API 1.25forcer)   r	   N)r   
version_ltr    r   r!   r   _delete_raise_for_status)r   r#   r0   r
   r   resps         r   remove_volumezVolumeApiMixin.remove_volume   sr     v6++>  u%FiiVi<||C t$r   )N)NNNN)F)
__name__
__module____qualname__r   r'   r*   r   minimum_versionr.   r5    r   r   r   r      sG    AB AE!2Ch22 U6"B #B*%r   r   N) r   r   r   r:   r   r   <module>r<      s     \% \%r   