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.

configs.py 1.7KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from ..api import APIClient
  2. from .resource import Model, Collection
  3. class Config(Model):
  4. """A config."""
  5. id_attribute = 'ID'
  6. def __repr__(self):
  7. return f"<{self.__class__.__name__}: '{self.name}'>"
  8. @property
  9. def name(self):
  10. return self.attrs['Spec']['Name']
  11. def remove(self):
  12. """
  13. Remove this config.
  14. Raises:
  15. :py:class:`docker.errors.APIError`
  16. If config failed to remove.
  17. """
  18. return self.client.api.remove_config(self.id)
  19. class ConfigCollection(Collection):
  20. """Configs on the Docker server."""
  21. model = Config
  22. def create(self, **kwargs):
  23. obj = self.client.api.create_config(**kwargs)
  24. return self.prepare_model(obj)
  25. create.__doc__ = APIClient.create_config.__doc__
  26. def get(self, config_id):
  27. """
  28. Get a config.
  29. Args:
  30. config_id (str): Config ID.
  31. Returns:
  32. (:py:class:`Config`): The config.
  33. Raises:
  34. :py:class:`docker.errors.NotFound`
  35. If the config does not exist.
  36. :py:class:`docker.errors.APIError`
  37. If the server returns an error.
  38. """
  39. return self.prepare_model(self.client.api.inspect_config(config_id))
  40. def list(self, **kwargs):
  41. """
  42. List configs. Similar to the ``docker config ls`` command.
  43. Args:
  44. filters (dict): Server-side list filtering options.
  45. Returns:
  46. (list of :py:class:`Config`): The configs.
  47. Raises:
  48. :py:class:`docker.errors.APIError`
  49. If the server returns an error.
  50. """
  51. resp = self.client.api.configs(**kwargs)
  52. return [self.prepare_model(obj) for obj in resp]