Skip to content

Commit

Permalink
Add content related helpers for Repository entity.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Tkachenko committed Oct 20, 2016
1 parent 40ee56f commit 3b062d1
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
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/:repository_id/packages
puppet_modules
/repositories/:repository_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 list_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 list_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).list_packages, 'get'),
(entities.Repository(**generic).list_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

0 comments on commit 3b062d1

Please sign in to comment.