Skip to content

Commit 39c8ad5

Browse files
author
Gauvain Pocentek
committed
Add geo nodes API support
Fixes #524
1 parent 5a855fd commit 39c8ad5

File tree

6 files changed

+132
-0
lines changed

6 files changed

+132
-0
lines changed

docs/api-objects.rst

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ API examples
1919
gl_objects/environments
2020
gl_objects/events
2121
gl_objects/features
22+
gl_objects/geo_nodes
2223
gl_objects/groups
2324
gl_objects/issues
2425
gl_objects/boards

docs/gl_objects/geo_nodes.rst

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#########
2+
Geo nodes
3+
#########
4+
5+
Reference
6+
---------
7+
8+
* v4 API:
9+
10+
+ :class:`gitlab.v4.objects.GeoNode`
11+
+ :class:`gitlab.v4.objects.GeoNodeManager`
12+
+ :attr:`gitlab.Gitlab.geonodes`
13+
14+
* GitLab API: https://docs.gitlab.com/ee/api/geo_nodes.html
15+
16+
Examples
17+
--------
18+
19+
List the geo nodes::
20+
21+
nodes = gl.geonodes.list()
22+
23+
Get the status of all the nodes::
24+
25+
status = gl.geonodes.status()
26+
27+
Get a specific node and its status::
28+
29+
node = gl.geonodes.get(node_id)
30+
node.status()
31+
32+
Edit a node configuration::
33+
34+
node.url = 'https://secondary.mygitlab.domain'
35+
node.save()
36+
37+
Delete a node::
38+
39+
node.delete()
40+
41+
List the sync failure on the current node::
42+
43+
failures = gl.geonodes.current_failures()

gitlab/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __init__(self, url, private_token=None, oauth_token=None, email=None,
105105

106106
self.broadcastmessages = objects.BroadcastMessageManager(self)
107107
self.deploykeys = objects.DeployKeyManager(self)
108+
self.geonodes = objects.GeoNodeManager(self)
108109
self.gitlabciymls = objects.GitlabciymlManager(self)
109110
self.gitignores = objects.GitignoreManager(self)
110111
self.groups = objects.GroupManager(self)

gitlab/exceptions.py

+4
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ class GitlabRenderError(GitlabOperationError):
217217
pass
218218

219219

220+
class GitlabRepairError(GitlabOperationError):
221+
pass
222+
223+
220224
def on_http_error(error):
221225
"""Manage GitlabHttpError exceptions.
222226

gitlab/v4/objects.py

+77
Original file line numberDiff line numberDiff line change
@@ -3444,3 +3444,80 @@ def mark_all_as_done(self, **kwargs):
34443444
return int(result)
34453445
except ValueError:
34463446
return 0
3447+
3448+
3449+
class GeoNode(SaveMixin, ObjectDeleteMixin, RESTObject):
3450+
@cli.register_custom_action('GeoNode')
3451+
@exc.on_http_error(exc.GitlabRepairError)
3452+
def repair(self, **kwargs):
3453+
"""Repair the OAuth authentication of the geo node.
3454+
3455+
Args:
3456+
**kwargs: Extra options to send to the server (e.g. sudo)
3457+
3458+
Raises:
3459+
GitlabAuthenticationError: If authentication is not correct
3460+
GitlabRepairError: If the server failed to perform the request
3461+
"""
3462+
path = '/geo_nodes/%s/repair' % self.get_id()
3463+
server_data = self.manager.gitlab.http_post(path, **kwargs)
3464+
self._update_attrs(server_data)
3465+
3466+
@cli.register_custom_action('GeoNode')
3467+
@exc.on_http_error(exc.GitlabGetError)
3468+
def status(self, **kwargs):
3469+
"""Get the status of the geo node.
3470+
3471+
Args:
3472+
**kwargs: Extra options to send to the server (e.g. sudo)
3473+
3474+
Raises:
3475+
GitlabAuthenticationError: If authentication is not correct
3476+
GitlabGetError: If the server failed to perform the request
3477+
3478+
Returns:
3479+
dict: The status of the geo node
3480+
"""
3481+
path = '/geo_nodes/%s/status' % self.get_id()
3482+
return self.manager.gitlab.http_get(path, **kwargs)
3483+
3484+
3485+
class GeoNodeManager(RetrieveMixin, UpdateMixin, DeleteMixin, RESTManager):
3486+
_path = '/geo_nodes'
3487+
_obj_cls = GeoNode
3488+
_update_attrs = (tuple(), ('enabled', 'url', 'files_max_capacity',
3489+
'repos_max_capacity'))
3490+
3491+
@cli.register_custom_action('GeoNodeManager')
3492+
@exc.on_http_error(exc.GitlabGetError)
3493+
def status(self, **kwargs):
3494+
"""Get the status of all the geo nodes.
3495+
3496+
Args:
3497+
**kwargs: Extra options to send to the server (e.g. sudo)
3498+
3499+
Raises:
3500+
GitlabAuthenticationError: If authentication is not correct
3501+
GitlabGetError: If the server failed to perform the request
3502+
3503+
Returns:
3504+
list: The status of all the geo nodes
3505+
"""
3506+
return self.gitlab.http_list('/geo_nodes/status', **kwargs)
3507+
3508+
@cli.register_custom_action('GeoNodeManager')
3509+
@exc.on_http_error(exc.GitlabGetError)
3510+
def current_failures(self, **kwargs):
3511+
"""Get the list of failures on the current geo node.
3512+
3513+
Args:
3514+
**kwargs: Extra options to send to the server (e.g. sudo)
3515+
3516+
Raises:
3517+
GitlabAuthenticationError: If authentication is not correct
3518+
GitlabGetError: If the server failed to perform the request
3519+
3520+
Returns:
3521+
list: The list of failures
3522+
"""
3523+
return self.gitlab.http_list('/geo_nodes/current/failures', **kwargs)

tools/ee-test.py

+6
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@ def end_log():
2727
approval = project.approvals.get()
2828
assert(approval.approvers[0]['user']['id'] == 1)
2929
end_log()
30+
31+
start_log('geo nodes')
32+
# very basic tests because we only have 1 node...
33+
nodes = gl.geonodes.list()
34+
status = gl.geonodes.status()
35+
end_log()

0 commit comments

Comments
 (0)