JujuControllerFailedConnecting,
JujuApplicationExists,
JujuInvalidK8sConfiguration,
+ JujuError
)
from n2vc.utils import DB_DATA
from osm_common.dbbase import DbException
await self.disconnect_model(model)
await self.disconnect_controller(controller)
+ async def get_executed_actions(self, model_name: str) -> list:
+ """
+ Get executed/history of actions for a model.
+
+ :param: model_name: Model name, str.
+ :return: List of executed actions for a model.
+ """
+ model = None
+ executed_actions = []
+ controller = await self.get_controller()
+ try:
+ model = await self.get_model(controller, model_name)
+ # Get all unique action names
+ actions = {}
+ for application in model.applications:
+ application_actions = await self.get_actions(application, model_name)
+ actions.update(application_actions)
+ # Get status of all actions
+ for application_action in actions:
+ app_action_status_list = await model.get_action_status(name=application_action)
+ for action_id, action_status in app_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 self.disconnect_model(model)
+ await self.disconnect_controller(controller)
+ return executed_actions
+
+ async def get_application_configs(self, model_name: str, application_name: str) -> dict:
+ """
+ Get available configs for an application.
+
+ :param: model_name: Model name, str.
+ :param: application_name: Application name, str.
+
+ :return: A dict which has key - action name, value - action description
+ """
+ model = None
+ application_configs = {}
+ controller = await self.get_controller()
+ try:
+ model = await self.get_model(controller, model_name)
+ application = self._get_application(model, application_name=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 self.disconnect_model(model)
+ await self.disconnect_controller(controller)
+ return application_configs
+
async def get_model(
self, controller: Controller, model_name: str, id=None
) -> Model:
for m in models:
status[m] = await self.libjuju.get_model_status(m)
-
if yaml_format:
return obj_to_yaml(status)
else:
return obj_to_dict(status)
+ async def update_vca_status(self, vcastatus: dict):
+ """
+ Add all configs, actions, executed actions of all applications in a model to vcastatus dict.
+ :param vcastatus: dict containing vcaStatus
+ :return: None
+ """
+ try:
+ for model_name in vcastatus:
+ # Adding executed actions
+ vcastatus[model_name]["executedActions"] = \
+ await self.libjuju.get_executed_actions(model_name)
+ for application in vcastatus[model_name]["applications"]:
+ # Adding application actions
+ vcastatus[model_name]["applications"][application]["actions"] = \
+ await self.libjuju.get_actions(application, model_name)
+ # Adding application configs
+ vcastatus[model_name]["applications"][application]["configs"] = \
+ await self.libjuju.get_application_configs(model_name, application)
+ except Exception as e:
+ self.log.debug("Error in updating vca status: {}".format(str(e)))
+
async def create_execution_environment(
self,
namespace: str,