From 1b736a8d726fdb45d261b25b4f74bee1f319e4b2 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Wed, 1 Aug 2018 15:20:38 +0200 Subject: [PATCH] ActivationKey: implement copying of AKs --- nailgun/entities.py | 22 ++++++++++++++++++++++ tests/test_entities.py | 1 + 2 files changed, 23 insertions(+) diff --git a/nailgun/entities.py b/nailgun/entities.py index 8e5a0d5f..aa1457e7 100644 --- a/nailgun/entities.py +++ b/nailgun/entities.py @@ -255,6 +255,8 @@ def path(self, which=None): add_subscriptions /activation_keys//add_subscriptions + copy + /activation_keys//copy content_override /activation_keys//content_override product_content @@ -272,6 +274,7 @@ def path(self, which=None): if which in ( 'add_subscriptions', 'content_override', + 'copy', 'host_collections', 'product_content', 'releases', @@ -317,6 +320,25 @@ def add_subscriptions(self, synchronous=True, **kwargs): response = client.put(self.path('add_subscriptions'), **kwargs) return _handle_response(response, self._server_config, synchronous) + def copy(self, synchronous=True, **kwargs): + """Copy provided activation key. + + :param synchronous: What should happen if the server returns an HTTP + 202 (accepted) status code? Wait for the task to complete if + ``True``. Immediately return the server's response otherwise. + :param kwargs: Arguments to pass to requests. + :returns: The server's response, with all JSON decoded. + :raises: ``requests.exceptions.HTTPError`` If the server responds with + an HTTP 4XX or 5XX message. + + """ + kwargs = kwargs.copy() # shadow the passed-in kwargs + if 'data' in kwargs and 'id' not in kwargs['data']: + kwargs['data']['id'] = self.id # pylint:disable=no-member + kwargs.update(self._server_config.get_client_kwargs()) + response = client.post(self.path('copy'), **kwargs) + return _handle_response(response, self._server_config, synchronous) + def remove_subscriptions(self, synchronous=True, **kwargs): """Helper for removing subscriptions from an activation key. diff --git a/tests/test_entities.py b/tests/test_entities.py index 91a8817d..db2175d2 100644 --- a/tests/test_entities.py +++ b/tests/test_entities.py @@ -302,6 +302,7 @@ def test_id_and_which(self): (entities.AbstractDockerContainer, 'power'), (entities.ActivationKey, 'add_subscriptions'), (entities.ActivationKey, 'content_override'), + (entities.ActivationKey, 'copy'), (entities.ActivationKey, 'host_collections'), (entities.ActivationKey, 'releases'), (entities.ActivationKey, 'remove_subscriptions'),