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

Add content related helpers for Repository entity. #327

Merged
merged 1 commit into from
Oct 25, 2016
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
70 changes: 69 additions & 1 deletion nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -4051,6 +4051,12 @@ def path(self, which=None):

errata
/repositories/<id>/errata
packages
/repositories/<id>/packages
puppet_modules
/repositories/<id>/puppet_modules
remove_content
/repositories/<id>/remove_content
sync
/repositories/<id>/sync
upload_content
Expand All @@ -4059,7 +4065,13 @@ def path(self, which=None):
``super`` is called otherwise.

"""
if which in ('errata', 'sync', 'upload_content'):
if which in (
'errata',
'packages',
'puppet_modules',
'remove_content',
'sync',
'upload_content'):
return '{0}/{1}'.format(
super(Repository, self).path(which='self'),
which
Expand Down Expand Up @@ -4153,6 +4165,62 @@ def upload_content(self, synchronous=True, **kwargs):
)
return json

def remove_content(self, synchronous=True, **kwargs):
"""Remove content from a repository

It expects packages/puppet modules/docker manifests ids sent as data.
Here is an example of how to use this method::

repository.remove_content(data={'ids': [package.id]})

: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()
kwargs.update(self._server_config.get_client_kwargs())
response = client.put(self.path('remove_content'), **kwargs)
return _handle_response(response, self._server_config, synchronous)

def puppet_modules(self, synchronous=True, **kwargs):
""""List puppet modules associated with repository

: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()
kwargs.update(self._server_config.get_client_kwargs())
response = client.get(self.path('puppet_modules'), **kwargs)
return _handle_response(response, self._server_config, synchronous)

def packages(self, synchronous=True, **kwargs):
"""List packages associated with repository

: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()
kwargs.update(self._server_config.get_client_kwargs())
response = client.get(self.path('packages'), **kwargs)
return _handle_response(response, self._server_config, synchronous)


class RepositorySet(
Entity,
Expand Down
6 changes: 6 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ def test_id_and_which(self):
(entities.Product, 'sync'),
(entities.PuppetClass, 'smart_class_parameters'),
(entities.Repository, 'errata'),
(entities.Repository, 'packages'),
(entities.Repository, 'puppet_modules'),
(entities.Repository, 'remove_content'),
(entities.Repository, 'sync'),
(entities.Repository, 'upload_content'),
(entities.RHCIDeployment, 'deploy'),
Expand Down Expand Up @@ -1335,6 +1338,9 @@ def setUpClass(cls):
(entities.PuppetClass(**generic).list_smart_variables, 'get'),
(entities.RHCIDeployment(**generic).deploy, 'put'),
(entities.Repository(**generic).errata, 'get'),
(entities.Repository(**generic).packages, 'get'),
(entities.Repository(**generic).puppet_modules, 'get'),
(entities.Repository(**generic).remove_content, 'put'),
(entities.Repository(**generic).sync, 'post'),
(entities.RepositorySet(**repo_set).available_repositories, 'get'),
(entities.RepositorySet(**repo_set).disable, 'put'),
Expand Down