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.

nodes.py 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. from .resource import Model, Collection
  2. class Node(Model):
  3. """A node in a swarm."""
  4. id_attribute = 'ID'
  5. @property
  6. def version(self):
  7. """
  8. The version number of the service. If this is not the same as the
  9. server, the :py:meth:`update` function will not work and you will
  10. need to call :py:meth:`reload` before calling it again.
  11. """
  12. return self.attrs.get('Version').get('Index')
  13. def update(self, node_spec):
  14. """
  15. Update the node's configuration.
  16. Args:
  17. node_spec (dict): Configuration settings to update. Any values
  18. not provided will be removed. Default: ``None``
  19. Returns:
  20. `True` if the request went through.
  21. Raises:
  22. :py:class:`docker.errors.APIError`
  23. If the server returns an error.
  24. Example:
  25. >>> node_spec = {'Availability': 'active',
  26. 'Name': 'node-name',
  27. 'Role': 'manager',
  28. 'Labels': {'foo': 'bar'}
  29. }
  30. >>> node.update(node_spec)
  31. """
  32. return self.client.api.update_node(self.id, self.version, node_spec)
  33. def remove(self, force=False):
  34. """
  35. Remove this node from the swarm.
  36. Args:
  37. force (bool): Force remove an active node. Default: `False`
  38. Returns:
  39. `True` if the request was successful.
  40. Raises:
  41. :py:class:`docker.errors.NotFound`
  42. If the node doesn't exist in the swarm.
  43. :py:class:`docker.errors.APIError`
  44. If the server returns an error.
  45. """
  46. return self.client.api.remove_node(self.id, force=force)
  47. class NodeCollection(Collection):
  48. """Nodes on the Docker server."""
  49. model = Node
  50. def get(self, node_id):
  51. """
  52. Get a node.
  53. Args:
  54. node_id (string): ID of the node to be inspected.
  55. Returns:
  56. A :py:class:`Node` object.
  57. Raises:
  58. :py:class:`docker.errors.APIError`
  59. If the server returns an error.
  60. """
  61. return self.prepare_model(self.client.api.inspect_node(node_id))
  62. def list(self, *args, **kwargs):
  63. """
  64. List swarm nodes.
  65. Args:
  66. filters (dict): Filters to process on the nodes list. Valid
  67. filters: ``id``, ``name``, ``membership`` and ``role``.
  68. Default: ``None``
  69. Returns:
  70. A list of :py:class:`Node` objects.
  71. Raises:
  72. :py:class:`docker.errors.APIError`
  73. If the server returns an error.
  74. Example:
  75. >>> client.nodes.list(filters={'role': 'manager'})
  76. """
  77. return [
  78. self.prepare_model(n)
  79. for n in self.client.api.nodes(*args, **kwargs)
  80. ]