diff --git a/nailgun/entities.py b/nailgun/entities.py index bbff0370..f2f22049 100644 --- a/nailgun/entities.py +++ b/nailgun/entities.py @@ -6993,6 +6993,34 @@ def deploy(self, synchronous=True, timeout=None, **kwargs): return _handle_response(response, self._server_config, synchronous, timeout) +class RHCloud(Entity): + """A representation of a RHCloud entity.""" + + def __init__(self, server_config=None, **kwargs): + self._fields = { + 'organization': entity_fields.OneToOneField(Organization), + 'location': entity_fields.OneToOneField(Location), + } + super().__init__(server_config, **kwargs) + self._meta = {'api_path': 'api/v2/rh_cloud'} + + def path(self, which=None): + """Extend ``nailgun.entity_mixins.Entity.path``.""" + if which in ("enable_connector",): + return f'{super().path(which="base")}/{which}' + return super().path(which) + + def enable_connector(self, synchronous=True, timeout=None, **kwargs): + """Function to enable RH Cloud connector""" + kwargs = kwargs.copy() + kwargs.update(self._server_config.get_client_kwargs()) + kwargs['data'] = {} + if data := _payload(self.get_fields(), self.get_values()): + kwargs['data'] = data + response = client.post(self.path('enable_connector'), **kwargs) + return _handle_response(response, self._server_config, synchronous, timeout) + + class RoleLDAPGroups(Entity): """A representation of a Role LDAP Groups entity.""" @@ -8566,7 +8594,7 @@ def path(self, which=None): ``super`` is called otherwise. """ - if which in ("sync"): + if which in ("sync",): return f'{super().path(which="base")}/{which}' return super().path(which) diff --git a/tests/test_entities.py b/tests/test_entities.py index f5a6f358..f4630a49 100644 --- a/tests/test_entities.py +++ b/tests/test_entities.py @@ -164,6 +164,7 @@ def test_init_succeeds(self): entities.Report, entities.Repository, entities.RepositorySet, + entities.RHCloud, entities.Role, entities.RoleLDAPGroups, entities.ScapContents, @@ -382,6 +383,7 @@ def test_noid_and_which(self): (entities.ForemanTask, 'bulk_resume'), (entities.ForemanTask, 'bulk_search'), (entities.ForemanTask, 'summary'), + (entities.RHCloud, 'enable_connector'), (entities.Host, 'bulk/install_content'), (entities.Template, 'imports'), (entities.Template, 'exports'), @@ -2201,6 +2203,7 @@ def setUpClass(cls): (entities.Template(**generic).exports, 'post'), (entities.VirtWhoConfig(**generic).deploy_script, 'get'), ) + plain_taxonomy = {'server_config': cfg, 'organization': 1, 'location': 2} capsule = {'server_config': cfg, 'id': 1} repo_set = {'server_config': cfg, 'id': 1, 'product': 2} snapshot = {'server_config': cfg, 'id': 'snapshot-1', 'host': 1} @@ -2213,6 +2216,11 @@ def setUpClass(cls): (entities.RepositorySet(**repo_set).available_repositories, 'get', {'product_id': 2}), (entities.RepositorySet(**repo_set).disable, 'put', {'product_id': 2}), (entities.RepositorySet(**repo_set).enable, 'put', {'product_id': 2}), + ( + entities.RHCloud(**plain_taxonomy).enable_connector, + 'post', + {'organization_id': 1, 'location_id': 2}, + ), (entities.Snapshot(**snapshot).revert, 'put', {}), )