Exemple #1
0
    async def start(self):
        logger.info(f"Start triggered")

        print_cli(f"Starting", style="attention")

        ack, messages = self.environments.implement_env_cfgs("start")
        self._status["start"] = ack

        logger.info(f"{messages}")
        return ack, messages
Exemple #2
0
    async def install(self):
        logger.info(f"install triggered")

        print_cli(f"Installing", style="attention")

        ack, messages = self.environments.implement_env_cfgs("install")
        self._status["install"] = ack

        logger.info(f"{messages}")
        return ack, messages
Exemple #3
0
    def load(self, filename):
        logger.info(f"Load triggered - filename {filename}")
        ack = True

        print_cli(f"Loading configuration file at {filename}")

        data, error = self.load_file(filename)

        if error:
            msg = "Configuration not loaded - " + error
            print_cli(None, err=msg, style="error")
        else:
            self.experiment = Experiment("")
            ack = self.experiment.parse(data)

            if ack:
                self.topology = self.experiment.get_topology()
                self.environments.generate_env_cfgs(self.topology)
                msg = "Configuration loaded"
                print_cli(msg, style="normal")
            else:
                msg = "Configuration not loaded - Error parsing scenario data"
                print_cli(None, err=msg, style="error")

        self._status["load"] = ack

        logger.info(f"{msg}")
        return msg
Exemple #4
0
    async def end(self):
        logger.info(f"end triggered")

        print_cli(f"Ending", style="attention")

        default_env = self.topology.get_default_environment()
        default_env_components = default_env.get("components")
        broker_env = default_env_components.get("broker")

        print_cli(f"Experiment End", style="info")
        scenario = self.experiment.dump()
        reply, error = await self.broker_interface.end(broker_env, scenario)

        ack = False if error else True
        self._status["end"] = ack
        self._status["begin"] = not ack

        if ack:
            print_cli(f"Ended Umbra Experiment", style="normal")
            messages = reply
        else:
            print_cli(f"Ended Umbra Experiment Error", style="error")
            messages = error

        logger.info(f"{messages}")
        return ack, messages
Exemple #5
0
 def print_output(self, output):
     if type(output) is str:
         print_cli(output, style="normal")
     elif type(output) is list:
         for out in output:
             print_cli(out, style="normal")
     else:
         print_cli(f"Unkown command output format {type(output)}", style="attention")
Exemple #6
0
    def implement(self, actions):
        """Realizes the instantiation of the environment configuration

        Args:
            env_cfg (dict): The description of the environment configuration
            to be implemented, example:

            env_cfg = {
                "id": "X",
                "host": {
                    "user": "******",
                    "address": "192.168.122.156",
                    "port": "22",
                    "password": "******",
                }
                "settings": {
                    "source": "/tmp/umbra/...",
                    "destination": "/tmp/umbra/...",
                },
                "components": {
                    "scenario": {
                        "uuid": "y",
                        "address": "0.0.0.0:8988",
                    },
                    "broker": {},
                    "monitor": {}
                }
            }

        Returns:
            bool: If the transaction was successful (True) or not (False)
        """
        logger.info(f"Implementing actions - {actions} ")

        action_outputs = {}

        for action in actions:
            action_output = {}

            if action in ["install"]:
                logger.info(f"Implementing action - {action}")

                is_installed = self._envs_stats[self.envid].get(action, False)

                if not is_installed:
                    logger.info(
                        f"Calling action - {action} - Installing environment {self.envid}"
                    )

                    print_cli(f"Installing Umbra at environment {self.envid}")

                    action_output = self._workflow_install()
                    self._envs_stats[self.envid][action] = action_output.get(
                        "ack")

                    if action_output.get("ack"):
                        print_cli(
                            f"Install Umbra in environment {self.envid} Ok",
                            style="normal",
                        )

                    else:
                        print_cli(
                            f"Install Umbra in environment {self.envid} Error",
                            style="error",
                        )

                else:
                    logger.info(
                        f"Calling action {action} not needed - environment already installed"
                    )

                    print_cli(
                        f"Installing Umbra in environment {self.envid} not needed - environment already installed",
                        style="attention",
                    )

                    action_output = {
                        "ack": True,
                        "msg": ["install: environment already installed"],
                    }

            if action in ["uninstall"]:
                is_installed = self._envs_stats[self.envid].get(action, False)

                if is_installed:
                    logger.info(
                        f"Calling action - {action} - Uninstalling environment {self.envid}"
                    )

                    print_cli(
                        f"Uninstalling Umbra at environment {self.envid}")

                    action_output = self._workflow_uninstall()
                    self._envs_stats[self.envid][action] = action_output.get(
                        "ack")

                    if action_output.get("ack"):
                        print_cli(
                            f"Uninstall Umbra in environment {self.envid} Ok",
                            style="normal",
                        )

                    else:
                        print_cli(
                            f"Uninstall Umbra in environment {self.envid} Error",
                            style="error",
                        )

                else:
                    logger.info(
                        f"Calling action {action} not needed - environment not installed"
                    )
                    print_cli(
                        f"Uninstalling Umbra in environment {self.envid} not needed - environment not installed",
                        style="attention",
                    )

                    action_output = {
                        "ack": False,
                        "msg": ["uninstall: environment not installed"],
                    }

            if action in ["start"]:
                for name, info in self.components.items():
                    logger.info(
                        f"Calling action {action} - environment {self.envid} - component {name}"
                    )

                    print_cli(
                        f"Starting component 'umbra-{name}' in environment {self.envid}"
                    )

                    action_output = self._workflow_start(name, info)

                    self._envs_stats[self.envid]["components"].setdefault(
                        name, {})
                    self._envs_stats[
                        self.envid]["components"][name].setdefault(
                            action, False)

                    self._envs_stats[self.envid]["components"][name][
                        action] = action_output.get("ack")

                    if action_output.get("ack"):
                        print_cli(
                            f"Started component 'umbra-{name}' in environment {self.envid} Ok",
                            style="normal",
                        )

                    else:

                        print_cli(
                            f"Started component 'umbra-{name}' in environment {self.envid} Error",
                            style="error",
                        )

            if action in ["stop"]:
                for name, info in self.components.items():
                    logger.info(
                        f"Calling action {action} - environment {self.envid} - component {name}"
                    )

                    print_cli(
                        f"Stopping component 'umbra-{name}' in environment {self.envid}"
                    )

                    action_output = self._workflow_stop(name, info)

                    self._envs_stats[self.envid]["components"].setdefault(
                        name, {})
                    self._envs_stats[
                        self.envid]["components"][name].setdefault(
                            action, False)
                    self._envs_stats[self.envid]["components"][name][
                        action] = action_output.get("ack")

                    if action_output.get("ack"):
                        print_cli(
                            f"Stopped component 'umbra-{name}' in environment {self.envid} Ok",
                            style="normal",
                        )

                    else:

                        print_cli(
                            f"Stopped component 'umbra-{name}' in environment {self.envid} Error",
                            style="error",
                        )

            if action_output:
                action_outputs[action] = action_output

        all_acks = all([
            action_output.get("ack", False)
            for action_output in action_outputs.values()
        ])

        return all_acks, action_outputs