Add logic to prevent hanging instances

os-repl
root 2022-11-28 19:38:07 +00:00
parent a012173564
commit 8535a07de1
3 changed files with 14 additions and 0 deletions

View File

@ -28,6 +28,14 @@ def destroy_instance(container_name: str):
return True
def destroy_all_instances():
for instance in lxd_client.instances.all():
instance.stop(wait=True)
instance.delete(wait=True)
return True
def execute_command(container_name: str, command: list, stdin_payload=None):
instance = lxd_client.instances.get(container_name)
result_tuple = instance.execute(command, stdin_payload=stdin_payload)

View File

@ -20,3 +20,5 @@ try:
server.run()
except KeyboardInterrupt:
server.stop()
finally:
lxd_interface.destroy_all_instances()

View File

@ -70,6 +70,10 @@ class Runner(threading.Thread):
break
self.channel.send(x)
client_channel.close()
self.channel.close()
lxd_interface.destroy_instance(self.instance_name)
Handler.check_channel_shell_request = check_channel_shell_request
Handler.check_auth_none = check_auth_none