Add logic to prevent hanging instances
parent
a012173564
commit
8535a07de1
|
@ -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)
|
||||
|
|
2
main.py
2
main.py
|
@ -20,3 +20,5 @@ try:
|
|||
server.run()
|
||||
except KeyboardInterrupt:
|
||||
server.stop()
|
||||
finally:
|
||||
lxd_interface.destroy_all_instances()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue