from typing import List
from juju.controller import Controller
-from juju.errors import JujuAPIError, JujuError
+from juju.errors import JujuError
from juju.model import Model
-from n2vc.exceptions import JujuApplicationExists, JujuControllerFailedConnecting
+from n2vc.exceptions import (
+ JujuApplicationExists,
+ JujuControllerFailedConnecting,
+ JujuModelAlreadyExists,
+)
@dataclass
await model.disconnect()
async def add_model(self, model_name: str):
+ """Exception is raised if model_name already exists"""
model = None
controller = None
try:
controller = await self.get_controller()
if await self.model_exists(model_name, controller=controller):
- return
+ raise JujuModelAlreadyExists(
+ "Cannot create model {}".format(model_name)
+ )
self.logger.debug("Creating model {}".format(model_name))
model = await controller.add_model(
model_name,
- # config=self.vca_connection.data.model_config,
cloud_name=self.connection_info.cloud_name,
credential_name=self.connection_info.cloud_credentials,
)
- except JujuAPIError as e:
- if "already exists" in e.message:
- pass
- else:
- raise e
finally:
await self.disconnect_model(model)
await self.disconnect_controller(controller)