- machines = await model.get_machines()
- if machine_id in machines:
- machine = machines[machine_id]
- await machine.destroy(force=True)
- # max timeout
- end = time.time() + total_timeout
-
- # wait for machine removal
- machines = await model.get_machines()
- while machine_id in machines and time.time() < end:
- self.log.debug("Waiting for machine {} is destroyed".format(machine_id))
- await asyncio.sleep(0.5)
- machines = await model.get_machines()
- self.log.debug("Machine destroyed: {}".format(machine_id))
- else:
- self.log.debug("Machine not found: {}".format(machine_id))
+ status = await model.get_status()
+ for machine_id in status.machines:
+ machine_status = status.machines[machine_id]
+ if machine_status.agent_status.status == "pending":
+ if only_manual and not machine_status.instance_id.startswith("manual:"):
+ break
+ machine = model.machines[machine_id]
+ await machine.destroy(force=True)
+
+ # async def destroy_machine(
+ # self, model: Model, machine_id: str, total_timeout: float = 3600
+ # ):
+ # """
+ # Destroy machine
+
+ # :param: model: Model object
+ # :param: machine_id: Machine id
+ # :param: total_timeout: Timeout in seconds
+ # """
+ # machines = await model.get_machines()
+ # if machine_id in machines:
+ # machine = machines[machine_id]
+ # await machine.destroy(force=True)
+ # # max timeout
+ # end = time.time() + total_timeout
+
+ # # wait for machine removal
+ # machines = await model.get_machines()
+ # while machine_id in machines and time.time() < end:
+ # self.log.debug("Waiting for machine {} is destroyed".format(machine_id))
+ # await asyncio.sleep(0.5)
+ # machines = await model.get_machines()
+ # self.log.debug("Machine destroyed: {}".format(machine_id))
+ # else:
+ # self.log.debug("Machine not found: {}".format(machine_id))