From: Michael Tremer Date: Fri, 17 Jun 2022 15:36:59 +0000 (+0000) Subject: builders: Add functions to start/stop builders on AWS X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00d1ebb6590af61cf0b39685368442171ffb0797;p=pbs.git builders: Add functions to start/stop builders on AWS Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builders.py b/src/buildservice/builders.py index 0fb0a8d4..68ab11b6 100644 --- a/src/buildservice/builders.py +++ b/src/buildservice/builders.py @@ -462,7 +462,45 @@ class Builder(base.DataObject): log.debug("%s is currently in state: %s" % (self, self.instance.state)) # Launch in a separate thread - return await asyncio.to_thread(callback) + await asyncio.to_thread(callback) + + async def start(self): + """ + Starts the instance on AWS + """ + await asyncio.to_thread(self._start) + + def _start(self): + log.info("Starting %s" % self) + + # Send the start signal + self.instance.start() + + log.debug("Waiting until %s has started" % self) + + # And wait until the instance is running + self.instance.wait_until_running() + + log.debug("%s has been started" % self) + + async def stop(self): + """ + Stops this instance on AWS + """ + await asyncio.to_thread(self._stop) + + def _stop(self): + log.info("Stopping %s" % self) + + # Send the stop signal + self.instance.stop() + + log.debug("Waiting until %s has stopped" % self) + + # And wait until the instance has been stopped + self.instance.wait_until_stopped() + + log.debug("%s has been stopped" % self) def generate_password_hash(password, salt=None, algo="sha512"):