+ async def add_relation(
+ self, provider: RelationEndpoint, requirer: RelationEndpoint
+ ):
+ """
+ Add relation between two charmed endpoints
+
+ :param: provider: Provider relation endpoint
+ :param: requirer: Requirer relation endpoint
+ """
+ self.log.debug(f"adding new relation between {provider} and {requirer}")
+ cross_model_relation = (
+ provider.model_name != requirer.model_name
+ or provider.vca_id != requirer.vca_id
+ )
+ try:
+ if cross_model_relation:
+ # Cross-model relation
+ provider_libjuju = await self._get_libjuju(provider.vca_id)
+ requirer_libjuju = await self._get_libjuju(requirer.vca_id)
+ offer = await provider_libjuju.offer(provider)
+ if offer:
+ saas_name = await requirer_libjuju.consume(
+ requirer.model_name, offer, provider_libjuju
+ )
+ await requirer_libjuju.add_relation(
+ requirer.model_name, requirer.endpoint, saas_name
+ )
+ else:
+ # Standard relation
+ vca_id = provider.vca_id
+ model = provider.model_name
+ libjuju = await self._get_libjuju(vca_id)
+ # add juju relations between two applications
+ await libjuju.add_relation(
+ model_name=model,
+ endpoint_1=provider.endpoint,
+ endpoint_2=requirer.endpoint,
+ )
+ except Exception as e:
+ message = f"Error adding relation between {provider} and {requirer}: {e}"
+ self.log.error(message)
+ raise Exception(message=message)
+
+ async def update_vca_status(
+ self, vcastatus: dict, kdu_instance: str, namespace: str = None, **kwargs
+ ):
+ """
+ Add all configs, actions, executed actions of all applications in a model to vcastatus dict
+
+ :param vcastatus dict: dict containing vcastatus
+ :param kdu_instance str: The unique id of the KDU instance
+ :param namespace str: The namespace (model) where the Bundle was deployed
+ :param: kwargs: Additional parameters
+ vca_id (str): VCA ID
+
+ :return: None
+ """
+
+ model_name = self._obtain_namespace(
+ kdu_instance=kdu_instance, namespace=namespace
+ )
+
+ libjuju = await self._get_libjuju(kwargs.get("vca_id"))
+ try:
+ for vca_model_name in vcastatus:
+ # Adding executed actions
+ vcastatus[vca_model_name][
+ "executedActions"
+ ] = await libjuju.get_executed_actions(model_name=model_name)
+
+ for application in vcastatus[vca_model_name]["applications"]:
+ # Adding application actions
+ vcastatus[vca_model_name]["applications"][application][
+ "actions"
+ ] = {}
+ # Adding application configs
+ vcastatus[vca_model_name]["applications"][application][
+ "configs"
+ ] = await libjuju.get_application_configs(
+ model_name=model_name, application_name=application
+ )
+
+ except Exception as e:
+ self.log.debug("Error in updating vca status: {}".format(str(e)))
+