Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActivationKey: implement copying of AKs #517

Merged
merged 1 commit into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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'),
Expand Down