Skip to content

Commit

Permalink
Add support for reading a Provisioning Template
Browse files Browse the repository at this point in the history
Signed-off-by: Shubham Ganar <shubhamsg123m@gmail.com>
  • Loading branch information
shubhamsg199 committed Feb 23, 2023
1 parent 1f2bca5 commit 33f8b7e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -4344,6 +4344,7 @@ def path(self, which=None):
'disassociate',
'traces',
'traces/resolve',
'template',
):
return f'{super().path(which="self")}/{which}'
elif which in (
Expand Down Expand Up @@ -4409,6 +4410,33 @@ def delete_puppetclass(self, synchronous=True, timeout=None, **kwargs):
client.delete(path, **kwargs), self._server_config, synchronous, timeout
)

def read_template(self, synchronous=True, timeout=None, **kwargs):
"""Fetches and reads the provisioning template for given host
Here is an example of how to use this method::
host.preview_template(data={'template_kind': 'iPXE'})
Constructs path:
api/hosts/:id/template/:kind
: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 content 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())
kind = f'{kwargs["data"].pop("template_kind")}'
path = f'{self.path("template")}/{kind}'
response = client.get(path, **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def list_scparams(self, synchronous=True, timeout=None, **kwargs):
"""List all smart class parameters
Expand Down

0 comments on commit 33f8b7e

Please sign in to comment.