+ return application_actions
+
+ async def get_application_configs(
+ self,
+ application_name: str,
+ model_name: str,
+ cluster_uuid: str,
+ kdu_instance: str
+ ) -> dict:
+ """
+ Get available configs for an application.
+
+ :param application_name str: Application name
+ :model_name str: Model name
+ :param cluster_uuid str: The UUID of the cluster
+ :param kdu_instance str: The unique id of the KDU instance
+
+ :return: Returns a dictionary which has config list of the Application
+ """
+ model = None
+ application_configs = {}
+ controller = await self.get_controller(cluster_uuid)
+ try:
+ model = await self.get_model(kdu_instance, controller=controller)
+ application = model.applications[application_name]
+ application_configs = await application.get_config()
+ except Exception as e:
+ raise JujuError("Error in getting configs for application: {} in model: {}. Error: {}"
+ .format(application_name, model_name, str(e)))
+ finally:
+ if model:
+ await model.disconnect()
+ await controller.disconnect()
+ return application_configs
+
+ async def get_executed_actions(
+ self,
+ model_name: str,
+ cluster_uuid: str,
+ kdu_instance: str
+ ) -> list:
+ """
+ Get executed/history of actions for a model.
+ :model_name str: Model name
+ :param cluster_uuid str: The UUID of the cluster
+ :param kdu_instance str: The unique id of the KDU instance
+
+ :return: List of executed actions for a model.
+ """
+ model = None
+ executed_actions = []
+ controller = await self.get_controller(cluster_uuid)
+ try:
+ model = await self.get_model(kdu_instance, controller=controller)
+ # Get all unique action names
+ actions = {}
+ for application in model.applications:
+ application_actions = await self.get_application_actions(application, model,
+ cluster_uuid, kdu_instance)
+ actions.update(application_actions)
+ # Get status of all actions
+ for application_action in actions:
+ application_action_status_list = \
+ await model.get_action_status(name=application_action)
+ for action_id, action_status in application_action_status_list.items():
+ executed_action = {"id": action_id,
+ "action": application_action,
+ "status": action_status}
+ # Get action output by id
+ action_status = await model.get_action_output(executed_action["id"])
+ for k, v in action_status.items():
+ executed_action[k] = v
+ executed_actions.append(executed_action)
+ except Exception as e:
+ raise JujuError("Error in getting executed actions for model: {}. Error: {}"
+ .format(model_name, str(e)))
+ finally:
+ if model:
+ await model.disconnect()
+ await controller.disconnect()
+ return executed_actions
+
+ async def update_vca_status(self, vcastatus: dict, cluster_uuid: str, kdu_instance: str):
+ """
+ Add all configs, actions, executed actions of all applications in a model to vcastatus dict
+
+ :param vcastatus dict: dict containing vcastatus
+ :param cluster_uuid str: The UUID of the cluster
+ :param kdu_instance str: The unique id of the KDU instance
+ :return: None
+ """
+ try:
+ for model_name in vcastatus:
+ # Adding executed actions
+ vcastatus[model_name]["executedActions"] = \
+ await self.get_executed_actions(model_name, cluster_uuid, kdu_instance)
+
+ for application in vcastatus[model_name]["applications"]:
+ # Adding application actions
+ vcastatus[model_name]["applications"][application]["actions"] = \
+ await self.get_application_actions(application, model_name,
+ cluster_uuid, kdu_instance)
+ # Adding application configs
+ vcastatus[model_name]["applications"][application]["configs"] = \
+ await self.get_application_configs(application, model_name,
+ cluster_uuid, kdu_instance)
+ except Exception as e:
+ self.log.debug("Error in updating vca status: {}".format(str(e)))
+
+ async def get_services(
+ self, cluster_uuid: str, kdu_instance: str, namespace: str
+ ) -> list:
+ """Return a list of services of a kdu_instance"""
+
+ credentials = self.get_credentials(cluster_uuid=cluster_uuid)
+
+ config_path = "/tmp/{}".format(cluster_uuid)
+ config_file = "{}/config".format(config_path)
+
+ if not os.path.exists(config_path):
+ os.makedirs(config_path)
+ with open(config_file, "w") as f:
+ f.write(credentials)
+
+ kubectl = Kubectl(config_file=config_file)
+ return kubectl.get_services(
+ field_selector="metadata.namespace={}".format(kdu_instance)
+ )
+
+ async def get_service(
+ self, cluster_uuid: str, service_name: str, namespace: str
+ ) -> object:
+ """Return data for a specific service inside a namespace"""
+
+ credentials = self.get_credentials(cluster_uuid=cluster_uuid)
+
+ config_path = "/tmp/{}".format(cluster_uuid)
+ config_file = "{}/config".format(config_path)
+
+ if not os.path.exists(config_path):
+ os.makedirs(config_path)
+ with open(config_file, "w") as f:
+ f.write(credentials)
+
+ kubectl = Kubectl(config_file=config_file)
+
+ return kubectl.get_services(
+ field_selector="metadata.name={},metadata.namespace={}".format(
+ service_name, namespace
+ )
+ )[0]