Add consume to libjuju.py
This function allows to consume an offered endpoint in another model
Change-Id: I320978aac654fbb8199fdfbf4e928b0e2ba5458b
Signed-off-by: David Garcia <david.garcia@canonical.com>
diff --git a/n2vc/libjuju.py b/n2vc/libjuju.py
index ceb5e02..c62b11c 100644
--- a/n2vc/libjuju.py
+++ b/n2vc/libjuju.py
@@ -740,6 +740,28 @@
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