X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=n2vc%2Flibjuju.py;h=be16e2a8481dac8366fd6b6fa80f3dedc84c4b57;hp=b0e13588b4b5cf7bb7b0f1d23291d8a55ebc2da4;hb=891732a9f4f1381a49e506cb9d39132b328aaa1c;hpb=f8a9d46e66f1222d7aefdf5a641e4490ef1a40b8 diff --git a/n2vc/libjuju.py b/n2vc/libjuju.py index b0e1358..be16e2a 100644 --- a/n2vc/libjuju.py +++ b/n2vc/libjuju.py @@ -70,7 +70,10 @@ class Libjuju: self.log = log or logging.getLogger("Libjuju") self.db = db - self.endpoints = self._get_api_endpoints_db() or [endpoint] + db_endpoints = self._get_api_endpoints_db() + self.endpoints = db_endpoints or [endpoint] + if db_endpoints is None: + self._update_api_endpoints_db(self.endpoints) self.api_proxy = api_proxy self.username = username self.password = password @@ -737,19 +740,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 +820,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 +928,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)