Skip to content

Commit

Permalink
Add geo nodes API support
Browse files Browse the repository at this point in the history
Fixes #524
  • Loading branch information
Gauvain Pocentek committed Jun 9, 2018
1 parent 5a855fd commit 39c8ad5
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/api-objects.rst
Expand Up @@ -19,6 +19,7 @@ API examples
gl_objects/environments
gl_objects/events
gl_objects/features
gl_objects/geo_nodes
gl_objects/groups
gl_objects/issues
gl_objects/boards
Expand Down
43 changes: 43 additions & 0 deletions docs/gl_objects/geo_nodes.rst
@@ -0,0 +1,43 @@
#########
Geo nodes
#########

Reference
---------

* v4 API:

+ :class:`gitlab.v4.objects.GeoNode`
+ :class:`gitlab.v4.objects.GeoNodeManager`
+ :attr:`gitlab.Gitlab.geonodes`

* GitLab API: https://docs.gitlab.com/ee/api/geo_nodes.html

Examples
--------

List the geo nodes::

nodes = gl.geonodes.list()

Get the status of all the nodes::

status = gl.geonodes.status()

Get a specific node and its status::

node = gl.geonodes.get(node_id)
node.status()

Edit a node configuration::

node.url = 'https://secondary.mygitlab.domain'
node.save()

Delete a node::

node.delete()

List the sync failure on the current node::

failures = gl.geonodes.current_failures()
1 change: 1 addition & 0 deletions gitlab/__init__.py
Expand Up @@ -105,6 +105,7 @@ def __init__(self, url, private_token=None, oauth_token=None, email=None,

self.broadcastmessages = objects.BroadcastMessageManager(self)
self.deploykeys = objects.DeployKeyManager(self)
self.geonodes = objects.GeoNodeManager(self)
self.gitlabciymls = objects.GitlabciymlManager(self)
self.gitignores = objects.GitignoreManager(self)
self.groups = objects.GroupManager(self)
Expand Down
4 changes: 4 additions & 0 deletions gitlab/exceptions.py
Expand Up @@ -217,6 +217,10 @@ class GitlabRenderError(GitlabOperationError):
pass


class GitlabRepairError(GitlabOperationError):
pass


def on_http_error(error):
"""Manage GitlabHttpError exceptions.
Expand Down
77 changes: 77 additions & 0 deletions gitlab/v4/objects.py
Expand Up @@ -3444,3 +3444,80 @@ def mark_all_as_done(self, **kwargs):
return int(result)
except ValueError:
return 0


class GeoNode(SaveMixin, ObjectDeleteMixin, RESTObject):
@cli.register_custom_action('GeoNode')
@exc.on_http_error(exc.GitlabRepairError)
def repair(self, **kwargs):
"""Repair the OAuth authentication of the geo node.
Args:
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabRepairError: If the server failed to perform the request
"""
path = '/geo_nodes/%s/repair' % self.get_id()
server_data = self.manager.gitlab.http_post(path, **kwargs)
self._update_attrs(server_data)

@cli.register_custom_action('GeoNode')
@exc.on_http_error(exc.GitlabGetError)
def status(self, **kwargs):
"""Get the status of the geo node.
Args:
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabGetError: If the server failed to perform the request
Returns:
dict: The status of the geo node
"""
path = '/geo_nodes/%s/status' % self.get_id()
return self.manager.gitlab.http_get(path, **kwargs)


class GeoNodeManager(RetrieveMixin, UpdateMixin, DeleteMixin, RESTManager):
_path = '/geo_nodes'
_obj_cls = GeoNode
_update_attrs = (tuple(), ('enabled', 'url', 'files_max_capacity',
'repos_max_capacity'))

@cli.register_custom_action('GeoNodeManager')
@exc.on_http_error(exc.GitlabGetError)
def status(self, **kwargs):
"""Get the status of all the geo nodes.
Args:
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabGetError: If the server failed to perform the request
Returns:
list: The status of all the geo nodes
"""
return self.gitlab.http_list('/geo_nodes/status', **kwargs)

@cli.register_custom_action('GeoNodeManager')
@exc.on_http_error(exc.GitlabGetError)
def current_failures(self, **kwargs):
"""Get the list of failures on the current geo node.
Args:
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabGetError: If the server failed to perform the request
Returns:
list: The list of failures
"""
return self.gitlab.http_list('/geo_nodes/current/failures', **kwargs)
6 changes: 6 additions & 0 deletions tools/ee-test.py
Expand Up @@ -27,3 +27,9 @@ def end_log():
approval = project.approvals.get()
assert(approval.approvers[0]['user']['id'] == 1)
end_log()

start_log('geo nodes')
# very basic tests because we only have 1 node...
nodes = gl.geonodes.list()
status = gl.geonodes.status()
end_log()

0 comments on commit 39c8ad5

Please sign in to comment.