"""
if not model_names:
raise Exception(
- "model_names must be a non-empty array. Given value: {}".format(model_names)
+ "model_names must be a non-empty array. Given value: {}".format(
+ model_names
+ )
)
non_existing_models = []
models = await self.list_models()
if await u.is_leader_from_status():
unit = u
if unit is None:
- raise JujuLeaderUnitNotFound("Cannot execute action: leader unit not found")
+ raise JujuLeaderUnitNotFound(
+ "Cannot execute action: leader unit not found"
+ )
actions = await application.get_actions()
await self.disconnect_controller(controller)
async def add_relation(
- self,
- model_name: str,
- endpoint_1: str,
- endpoint_2: str,
+ self, model_name: str, endpoint_1: str, endpoint_2: str,
):
"""Add relation
await self.disconnect_model(model)
await self.disconnect_controller(controller)
+ async def consume(
+ self, offer_url: str, model_name: str,
+ ):
+ """
+ Adds a remote offer to the model. Relations can be created later using "juju relate".
+
+ :param: offer_url: Offer Url
+ :param: model_name: Model name
+
+ :raises ParseError if there's a problem parsing the offer_url
+ :raises JujuError if remote offer includes and endpoint
+ :raises JujuAPIError if the operation is not successful
+ """
+ controller = await self.get_controller()
+ model = await controller.get_model(model_name)
+
+ try:
+ await model.consume(offer_url)
+ finally:
+ await self.disconnect_model(model)
+ await self.disconnect_controller(controller)
+
async def destroy_model(self, model_name: str, total_timeout: float):
"""
Destroy model
# 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)
- )
+ 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))