Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

volumes.py 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. from ..api import APIClient
  2. from .resource import Model, Collection
  3. class Volume(Model):
  4. """A volume."""
  5. id_attribute = 'Name'
  6. @property
  7. def name(self):
  8. """The name of the volume."""
  9. return self.attrs['Name']
  10. def remove(self, force=False):
  11. """
  12. Remove this volume.
  13. Args:
  14. force (bool): Force removal of volumes that were already removed
  15. out of band by the volume driver plugin.
  16. Raises:
  17. :py:class:`docker.errors.APIError`
  18. If volume failed to remove.
  19. """
  20. return self.client.api.remove_volume(self.id, force=force)
  21. class VolumeCollection(Collection):
  22. """Volumes on the Docker server."""
  23. model = Volume
  24. def create(self, name=None, **kwargs):
  25. """
  26. Create a volume.
  27. Args:
  28. name (str): Name of the volume. If not specified, the engine
  29. generates a name.
  30. driver (str): Name of the driver used to create the volume
  31. driver_opts (dict): Driver options as a key-value dictionary
  32. labels (dict): Labels to set on the volume
  33. Returns:
  34. (:py:class:`Volume`): The volume created.
  35. Raises:
  36. :py:class:`docker.errors.APIError`
  37. If the server returns an error.
  38. Example:
  39. >>> volume = client.volumes.create(name='foobar', driver='local',
  40. driver_opts={'foo': 'bar', 'baz': 'false'},
  41. labels={"key": "value"})
  42. """
  43. obj = self.client.api.create_volume(name, **kwargs)
  44. return self.prepare_model(obj)
  45. def get(self, volume_id):
  46. """
  47. Get a volume.
  48. Args:
  49. volume_id (str): Volume name.
  50. Returns:
  51. (:py:class:`Volume`): The volume.
  52. Raises:
  53. :py:class:`docker.errors.NotFound`
  54. If the volume does not exist.
  55. :py:class:`docker.errors.APIError`
  56. If the server returns an error.
  57. """
  58. return self.prepare_model(self.client.api.inspect_volume(volume_id))
  59. def list(self, **kwargs):
  60. """
  61. List volumes. Similar to the ``docker volume ls`` command.
  62. Args:
  63. filters (dict): Server-side list filtering options.
  64. Returns:
  65. (list of :py:class:`Volume`): The volumes.
  66. Raises:
  67. :py:class:`docker.errors.APIError`
  68. If the server returns an error.
  69. """
  70. resp = self.client.api.volumes(**kwargs)
  71. if not resp.get('Volumes'):
  72. return []
  73. return [self.prepare_model(obj) for obj in resp['Volumes']]
  74. def prune(self, filters=None):
  75. return self.client.api.prune_volumes(filters=filters)
  76. prune.__doc__ = APIClient.prune_volumes.__doc__