Skip to content

Commit

Permalink
Merge branch 'master' into rhcloud_enable_connector
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrlc authored Jun 21, 2023
2 parents a8dd2cb + 162e767 commit 4e069e8
Show file tree
Hide file tree
Showing 3 changed files with 265 additions and 29 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/auto_cherry_pick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: auto_cherry_pick_commits

on:
pull_request_target:
types:
- [closed, labeled]
types: [closed, labeled]

# Github & Parent PR Env vars
env:
Expand Down
165 changes: 164 additions & 1 deletion nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,34 @@ def content_add_lifecycle_environment(self, synchronous=True, timeout=None, **kw
response = client.post(self.path('content_lifecycle_environments'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def content_delete_lifecycle_environment(self, synchronous=True, timeout=None, **kwargs):
"""Helper to disassociate lifecycle environment from capsule
Here is an example of how to use this method::
capsule.content_delete_lifecycle_environment(data={'environment_id': lce.id})
Constructs path:
/katello/api/capsules/:capsule_id/content/lifecycle_environments/: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 timeout: Maximum number of seconds to wait until timing out.
Defaults to ``nailgun.entity_mixins.TASK_TIMEOUT``.
: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())
path = (
f'{self.path("content_lifecycle_environments")}/{kwargs["data"].pop("environment_id")}'
)
response = client.delete(path, **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def content_lifecycle_environments(self, synchronous=True, timeout=None, **kwargs):
"""Helper to get all the lifecycle environments, associated with
capsule
Expand Down Expand Up @@ -3585,11 +3613,17 @@ def path(self, which=None):
/api/hostgroups/:hostgroup_id/rebuild_config
smart_class_parameters
/api/hostgroups/:hostgroup_id/smart_class_parameters
assign_ansible_roles
/api/hostgroups/:hostgroup_id/assign_ansible_roles
ansible_roles
/api/hostgroups/:hostgroup_id/ansible_roles
Otherwise, call ``super``.
"""
if which in (
'assign_ansible_roles',
'ansible_roles',
'clone',
'puppetclass_ids',
'rebuild_config',
Expand Down Expand Up @@ -3702,6 +3736,88 @@ def rebuild_config(self, synchronous=True, timeout=None, **kwargs):
response = client.put(self.path('rebuild_config'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def assign_ansible_roles(self, synchronous=True, timeout=None, **kwargs):
"""Add an Ansible Role to a hostgroup
Here is an example of how to use this method::
hostgroup.assign_ansible_roles(data={'ansible_role_ids':
[ansible_role_id1, ansible_role_id2]})
: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 timeout: Maximum number of seconds to wait until timing out.
Defaults to ``nailgun.entity_mixins.TASK_TIMEOUT``.
: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.post(self.path('assign_ansible_roles'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def list_ansible_roles(self, synchronous=True, timeout=None, **kwargs):
"""List all Ansible Roles assigned to a hostgroup
: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 timeout: Maximum number of seconds to wait until timing out.
Defaults to ``nailgun.entity_mixins.TASK_TIMEOUT``.
: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('ansible_roles'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def add_ansible_role(self, synchronous=True, timeout=None, **kwargs):
"""Add single Ansible Role to a hostgroup
: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 timeout: Maximum number of seconds to wait until timing out.
Defaults to ``nailgun.entity_mixins.TASK_TIMEOUT``.
: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())
path = f'{self.path("ansible_roles")}/{kwargs["data"].pop("ansible_role_id")}'
return _handle_response(
client.put(path, **kwargs), self._server_config, synchronous, timeout
)

def remove_ansible_role(self, synchronous=True, timeout=None, **kwargs):
"""Remove single Ansible Role assigned to a hostgroup
: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 timeout: Maximum number of seconds to wait until timing out.
Defaults to ``nailgun.entity_mixins.TASK_TIMEOUT``.
: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())
path = f'{self.path("ansible_roles")}/{kwargs["data"].pop("ansible_role_id")}'
return _handle_response(
client.delete(path, **kwargs), self._server_config, synchronous, timeout
)


class HostPackage(Entity):
"""A representation of a Host Package entity."""
Expand Down Expand Up @@ -4727,6 +4843,46 @@ def list_ansible_roles(self, synchronous=True, timeout=None, **kwargs):
response = client.get(self.path('ansible_roles'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def add_ansible_role(self, synchronous=True, timeout=None, **kwargs):
"""Add single Ansible Role to a host
: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 timeout: Maximum number of seconds to wait until timing out.
Defaults to ``nailgun.entity_mixins.TASK_TIMEOUT``.
: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())
path = f'{self.path("ansible_roles")}/{kwargs["data"].pop("ansible_role_id")}'
return _handle_response(
client.put(path, **kwargs), self._server_config, synchronous, timeout
)

def remove_ansible_role(self, synchronous=True, timeout=None, **kwargs):
"""Remove single Ansible Role assigned to a host
: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 timeout: Maximum number of seconds to wait until timing out.
Defaults to ``nailgun.entity_mixins.TASK_TIMEOUT``.
: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())
path = f'{self.path("ansible_roles")}/{kwargs["data"].pop("ansible_role_id")}'
return _handle_response(
client.delete(path, **kwargs), self._server_config, synchronous, timeout
)

def list_provisioning_templates(self, synchronous=True, timeout=None, **kwargs):
"""List all Provisioning templates assigned to a Host
Expand Down Expand Up @@ -8548,7 +8704,14 @@ def sync(self, synchronous=True, timeout=None, **kwargs):
return _handle_response(response, self._server_config, synchronous, timeout)


class AnsibleRoles(Entity):
class AnsibleRoles(
Entity,
EntityCreateMixin,
EntityDeleteMixin,
EntityReadMixin,
EntitySearchMixin,
EntityUpdateMixin,
):
"""A representation of Ansible Roles entity."""

def __init__(self, server_config=None, **kwargs):
Expand Down
Loading

0 comments on commit 4e069e8

Please sign in to comment.