Skip to content

Commit 9c19e06

Browse files
author
Gauvain Pocentek
committed
Add support for environment stop()
1 parent 6779616 commit 9c19e06

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

docs/gl_objects/environments.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ Delete an environment for a project::
3434
environment = project.environments.delete(environment_id)
3535
# or
3636
environment.delete()
37+
38+
Stop an environments::
39+
40+
environment.stop()

gitlab/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ class GitlabSearchError(GitlabOperationError):
201201
pass
202202

203203

204+
class GitlabStopError(GitlabOperationError):
205+
pass
206+
207+
204208
def on_http_error(error):
205209
"""Manage GitlabHttpError exceptions.
206210

gitlab/v4/objects.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,20 @@ class ProjectCommitManager(RetrieveMixin, CreateMixin, RESTManager):
12781278

12791279

12801280
class ProjectEnvironment(SaveMixin, ObjectDeleteMixin, RESTObject):
1281-
pass
1281+
@cli.register_custom_action('ProjectEnvironment')
1282+
@exc.on_http_error(exc.GitlabStopError)
1283+
def stop(self, **kwargs):
1284+
"""Stop the environment.
1285+
1286+
Args:
1287+
**kwargs: Extra options to send to the server (e.g. sudo)
1288+
1289+
Raises:
1290+
GitlabAuthenticationError: If authentication is not correct
1291+
GitlabStopError: If the operation failed
1292+
"""
1293+
path = '%s/%s/stop' % (self.manager.path, self.get_id())
1294+
self.manager.gitlab.http_post(path, **kwargs)
12821295

12831296

12841297
class ProjectEnvironmentManager(ListMixin, CreateMixin, UpdateMixin,

tools/python_test_v4.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@
432432
env.save()
433433
env = admin_project.environments.list()[0]
434434
assert(env.external_url == 'http://new.env/whatever')
435+
env.stop()
435436
env.delete()
436437
assert(len(admin_project.environments.list()) == 0)
437438

0 commit comments

Comments
 (0)