X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=n2vc%2Flibjuju.py;h=daedc3b2abab47fa7a0479f8fbec864883f4db0a;hp=b0e13588b4b5cf7bb7b0f1d23291d8a55ebc2da4;hb=d745e229c23053e565c89231c4e239186ba3e332;hpb=f8a9d46e66f1222d7aefdf5a641e4490ef1a40b8 diff --git a/n2vc/libjuju.py b/n2vc/libjuju.py index b0e1358..daedc3b 100644 --- a/n2vc/libjuju.py +++ b/n2vc/libjuju.py @@ -737,19 +737,6 @@ class Libjuju: self.log.debug("Destroying model {}".format(model_name)) uuid = model.info.uuid - # Destroy applications - for application_name in model.applications: - try: - await self.destroy_application( - model, application_name=application_name, - ) - except Exception as e: - self.log.error( - "Error destroying application {} in model {}: {}".format( - application_name, model_name, e - ) - ) - # Destroy machines machines = await model.get_machines() for machine_id in machines: @@ -830,25 +817,19 @@ class Libjuju: machines = await model.get_machines() if machine_id in machines: machine = model.machines[machine_id] - # TODO: change this by machine.is_manual when this is upstreamed: - # https://github.com/juju/python-libjuju/pull/396 - if "instance-id" in machine.safe_data and machine.safe_data[ - "instance-id" - ].startswith("manual:"): - await machine.destroy(force=True) - - # max timeout - end = time.time() + total_timeout + await machine.destroy(force=True) + # max timeout + end = time.time() + total_timeout - # wait for machine removal + # 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() - 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)) + self.log.debug("Machine destroyed: {}".format(machine_id)) else: self.log.debug("Machine not found: {}".format(machine_id)) @@ -944,3 +925,20 @@ class Libjuju: finally: await self.disconnect_controller(controller) await asyncio.sleep(interval) + + async def list_models(self, contains: str = None) -> [str]: + """List models with certain names + + :param: contains: String that is contained in model name + + :retur: [models] Returns list of model names + """ + + controller = await self.get_controller() + try: + models = await controller.list_models() + if contains: + models = [model for model in models if contains in model] + return models + finally: + await self.disconnect_controller(controller)