Skip to content

Commit

Permalink
implementing auto_provision[_all] and reboot_all methods for Discover…
Browse files Browse the repository at this point in the history
…edHost entity
  • Loading branch information
rplevka committed Oct 30, 2020
1 parent 3f63d0e commit a617602
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,8 +1094,9 @@ def path(self, which=None):
``super`` is called otherwise.
"""
if which in ('facts', 'refresh_facts', 'reboot'):
prefix = 'base' if which == 'facts' else 'self'
if which in ('auto_provision', 'auto_provision_all', 'facts', 'refresh_facts', 'reboot',
'reboot_all'):
prefix = 'base' if which in ['auto_provision_all', 'facts', 'reboot_all'] else 'self'
return '{0}/{1}'.format(
super(DiscoveredHost, self).path(which=prefix),
which
Expand Down Expand Up @@ -1183,6 +1184,54 @@ def reboot(self, synchronous=True, **kwargs):
response = client.put(self.path('reboot'), **kwargs)
return _handle_response(response, self._server_config, synchronous)

def reboot_all(self, synchronous=True, **kwargs):
"""Helper for rebooting all discovered hosts
: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() # shadow the passed-in kwargs
kwargs.update(self._server_config.get_client_kwargs())
response = client.put(self.path('reboot_all'), **kwargs)
return _handle_response(response, self._server_config, synchronous)

def auto_provision(self, synchronous=True, **kwargs):
"""Helper for auto-provisioning of the discovered 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 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() # shadow the passed-in kwargs
kwargs.update(self._server_config.get_client_kwargs())
response = client.post(self.path('auto_provision'), **kwargs)
return _handle_response(response, self._server_config, synchronous)

def auto_provision_all(self, synchronous=True, **kwargs):
"""Helper for auto-provisioning of all discovered hosts
: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() # shadow the passed-in kwargs
kwargs.update(self._server_config.get_client_kwargs())
response = client.post(self.path('auto_provision_all'), **kwargs)
return _handle_response(response, self._server_config, synchronous)


class DiscoveryRule(
Entity,
Expand Down

0 comments on commit a617602

Please sign in to comment.