X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=n2vc%2Flibjuju.py;h=8d1fdaddbfe8dd60e4825b1c06e3247caaa2449a;hp=a457309cf61de5c4235cb5760e77f237ca5478f8;hb=168bb198ea5c86aaa2cd8d0e20c634ac896e385f;hpb=5ef42a14f766aa00a5917845ba1b3e04cc3c15f7 diff --git a/n2vc/libjuju.py b/n2vc/libjuju.py index a457309..8d1fdad 100644 --- a/n2vc/libjuju.py +++ b/n2vc/libjuju.py @@ -817,6 +817,10 @@ class Libjuju: self.log.debug("Destroying model {}".format(model_name)) uuid = model.info.uuid + # Destroy machines that are manually provisioned + # and still are in pending state + await self._destroy_pending_machines(model, only_manual=True) + # Disconnect model await self.disconnect_model(model) @@ -864,6 +868,23 @@ class Libjuju: else: self.log.warning("Application not found: {}".format(application_name)) + async def _destroy_pending_machines(self, model: Model, only_manual: bool = False): + """ + Destroy pending machines in a given model + + :param: only_manual: Bool that indicates only manually provisioned + machines should be destroyed (if True), or that + all pending machines should be destroyed + """ + 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 # ):