]> git.ipfire.org Git - pbs.git/commitdiff
builders: Add functions to start/stop builders on AWS
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 17 Jun 2022 15:36:59 +0000 (15:36 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 17 Jun 2022 15:36:59 +0000 (15:36 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/builders.py

index 0fb0a8d4d666fb7aedf1d35dc24d0adddcd87765..68ab11b67cd04076ec01802510593a5f5de34f32 100644 (file)
@@ -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"):