Skip to content

Commit 53f5010

Browse files
committed
Add clone method to PartitionTable entity
Adds clone() method and path() override to the PartitionTable entity to support cloning partition tables via the /ptables/<id>/clone API endpoint.
1 parent b9e61df commit 53f5010

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

nailgun/entities.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6802,6 +6802,38 @@ def __init__(self, server_config=None, **kwargs):
68026802
self._meta = {'api_path': 'api/v2/ptables'}
68036803
super().__init__(server_config=server_config, **kwargs)
68046804

6805+
def path(self, which=None):
6806+
"""Extend ``nailgun.entity_mixins.Entity.path``.
6807+
6808+
The format of the returned path depends on the value of ``which``:
6809+
6810+
clone
6811+
/ptables/<id>/clone
6812+
6813+
``super`` is called otherwise.
6814+
"""
6815+
if which in ('clone',):
6816+
return f'{super().path(which="self")}/{which}'
6817+
return super().path(which)
6818+
6819+
def clone(self, synchronous=True, timeout=None, **kwargs):
6820+
"""Clone an existing partition table.
6821+
6822+
:param synchronous: What should happen if the server returns an HTTP
6823+
202 (accepted) status code? Wait for the task to complete if
6824+
``True``. Immediately return the server's response otherwise.
6825+
:param timeout: Maximum number of seconds to wait until timing out.
6826+
Defaults to ``nailgun.entity_mixins.TASK_TIMEOUT``.
6827+
:param kwargs: Arguments to pass to requests.
6828+
:returns: The server's response, with all JSON decoded.
6829+
:raises: ``requests.exceptions.HTTPError`` If the server responds with
6830+
an HTTP 4XX or 5XX message.
6831+
"""
6832+
kwargs = kwargs.copy() # shadow the passed-in kwargs
6833+
kwargs.update(self._server_config.get_client_kwargs())
6834+
response = client.post(self.path('clone'), **kwargs)
6835+
return _handle_response(response, self._server_config, synchronous, timeout)
6836+
68056837

68066838
class PuppetClass(
68076839
Entity,

0 commit comments

Comments
 (0)