X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=n2vc%2Flibjuju.py;h=5c803ed2109be0fe7e0229c73629e40c4b20e140;hb=227153dbd708538f04622a2c59722c2270b7bd5d;hp=02cc96885632b2dfeebfb5756be4685fc7a36a3e;hpb=584541c511a146bccd8b74492c1e5eab23f65c76;p=osm%2FN2VC.git diff --git a/n2vc/libjuju.py b/n2vc/libjuju.py index 02cc968..5c803ed 100644 --- a/n2vc/libjuju.py +++ b/n2vc/libjuju.py @@ -17,7 +17,7 @@ import logging import time -from juju.errors import JujuAPIError +import juju.errors from juju.model import Model from juju.machine import Machine from juju.application import Application @@ -286,7 +286,7 @@ class Libjuju: db_dict: dict = None, progress_timeout: float = None, total_timeout: float = None, - series: str = "xenial", + series: str = "bionic", wait: bool = True, ) -> (Machine, bool): """ @@ -620,7 +620,7 @@ class Libjuju: db_dict: dict = None, progress_timeout: float = None, total_timeout: float = None, - **kwargs + **kwargs, ): """Execute action @@ -793,7 +793,7 @@ class Libjuju: # Add relation try: await model.add_relation(endpoint_1, endpoint_2) - except JujuAPIError as e: + except juju.errors.JujuAPIError as e: if "not found" in e.message: self.log.warning("Relation not found: {}".format(e.message)) return @@ -952,33 +952,6 @@ class Libjuju: 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)) - async def configure_application( self, model_name: str, application_name: str, config: dict = None ): @@ -1244,6 +1217,11 @@ class Libjuju: controller = await self.get_controller() try: await controller.remove_cloud(name) + except juju.errors.JujuError as e: + if len(e.errors) == 1 and f'cloud "{name}" not found' == e.errors[0]: + self.log.warning(f"Cloud {name} not found, so it could not be deleted.") + else: + raise e finally: await self.disconnect_controller(controller)