Skip to content

Commit

Permalink
ActivationKey: implement copying of AKs (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni authored and abalakh committed Aug 2, 2018
1 parent b08a2e7 commit e0b6406
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ def path(self, which=None):
add_subscriptions
/activation_keys/<id>/add_subscriptions
copy
/activation_keys/<id>/copy
content_override
/activation_keys/<id>/content_override
product_content
Expand All @@ -272,6 +274,7 @@ def path(self, which=None):
if which in (
'add_subscriptions',
'content_override',
'copy',
'host_collections',
'product_content',
'releases',
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,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'),
Expand Down

0 comments on commit e0b6406

Please sign in to comment.