From 110e7b6be4a6a35e7c4aa2537a81d63167edba1e Mon Sep 17 00:00:00 2001 From: foroogh shahab Date: Fri, 16 Aug 2024 13:58:32 +0200 Subject: [PATCH 1/2] A new command is added. --- .../libs/csle-cli/src/csle_cli/cli.py | 95 ++++++++++++++++++- 1 file changed, 93 insertions(+), 2 deletions(-) diff --git a/simulation-system/libs/csle-cli/src/csle_cli/cli.py b/simulation-system/libs/csle-cli/src/csle_cli/cli.py index d5ee1de45..51129094d 100755 --- a/simulation-system/libs/csle-cli/src/csle_cli/cli.py +++ b/simulation-system/libs/csle-cli/src/csle_cli/cli.py @@ -3367,7 +3367,7 @@ def ls_shell_complete(ctx, param, incomplete) -> List[str]: "simulations | emulation_executions | cluster | nginx | postgresql | docker | hostmanagers | " "clientmanager | snortmanagers | elkmanager | trafficmanagers | kafkamanager | " "ossecmanagers | ryumanager | filebeats | metricbeats | heartbeats| packetbeats | logfiles | " - "logfile \n\n" + "logfile | emulation_description\n\n" "\b\n" "- \033[95mcontainers\033[0m: list all|stopped|running containers. \n" "- \033[95mnetworks\033[0m: list active networks. \n" @@ -3425,7 +3425,9 @@ def ls_shell_complete(ctx, param, incomplete) -> List[str]: "- \033[95mlogfiles\033[0m: list all CSLE log files with their path for a node with " "the specified --ip option.\n" "- \033[95mlogfile\033[0m: show the logs in a file with the path specified with " - "--logfile_name option for a node with the specified --ip option.\n\n" + "--logfile_name option for a node with the specified --ip option.\n" + "- \033[95memulation_description\033[0m: show detailed information about the containers" + " running in the emaultion with the given name and id.\n\n" "\b\n" "* \033[93mExample: csle ls filebeats --name csle-level4-060 --id 15 --ip X.X.X.X \033[0m") @click.argument('entity', default='all', type=str, shell_complete=ls_shell_complete) @@ -3525,6 +3527,8 @@ def ls(entity: str, all: bool, running: bool, stopped: bool, ip: str, name: str, list_logfiles(ip=ip) elif entity == "logfile": list_logfile(ip=ip, logfile_name=logfile_name) + elif entity == "emulation_description": + list_containers_hw_info(ip=ip, emulation=name, ip_first_octet=id) else: container = get_running_container(name=entity) if container is not None: @@ -3559,6 +3563,93 @@ def ls(entity: str, all: bool, running: bool, stopped: bool, ip: str, name: str, click.secho(f"entity: {entity} is not recognized", fg="red", bold=True) +def list_containers_hw_info(ip: str, emulation: str, ip_first_octet: int) -> None: + """ + Utility function for listing containers hardware information + + :param ip: the ip of the node to list hardware information + :param emulation: the emulation of the execution + :param ip_first_octet: the ID of the execution + + :return: None + """ + ### Still working on this + from csle_common.metastore.metastore_facade import MetastoreFacade + execution_config = MetastoreFacade.get_emulation_execution(ip_first_octet=ip_first_octet, emulation_name=emulation) + if (execution_config): + click.secho('+' + '=' * 80 + '+', fg='white', bold=True) + click.secho('|', nl=False, fg='white') + click.secho((f'Emulation {emulation} description').center(80), nl=False, fg='bright_yellow', bold=True) + click.secho('|', fg='white') + click.secho('+' + '=' * 80 + '+', fg='white', bold=True) + + click.secho('|', nl=False, fg='white') + ID_line = f"Emulation name is {click.style(execution_config.emulation_name, fg='magenta')}" + click.secho(ID_line, nl=False) + click.secho(' ' * (89 - len(ID_line)), nl=False) + click.secho('|', fg='white') + click.secho('+' + '-' * 80 + '+', fg='white') + + click.secho('|', nl=False, fg='white') + ID_line = f"Emulation ID is {click.style(execution_config.ip_first_octet, fg='magenta')}" + click.secho(ID_line, nl=False) + click.secho(' ' * (89 - len(ID_line)), nl=False) + click.secho('|', fg='white') + click.secho('+' + '-' * 80 + '+', fg='white') + + line = (f"This emulation is running on physical servers with IPs of: " + f"{click.style(execution_config.physical_servers[0], fg='magenta')}") + padding_length = 89 - len(line) + click.secho(f"|{line}{' ' * padding_length}|") + for i in range(1,len(execution_config.physical_servers)): + click.secho('|', nl=False, fg='white') + click.secho(f"{execution_config.physical_servers[i]}{' ' * padding_length}|", + fg="magenta", nl=False) + click.secho('+' + '=' * 80 + '+', fg='white', bold=True) + + click.secho("|", nl=False) + click.secho("Network information emulation containers".center(80), nl=False) + click.secho('|') + click.secho('+' + '=' * 80 + '+', fg='white', bold=True) + + agent_ip = execution_config.emulation_env_config.containers_config.agent_ip + router_ip = execution_config.emulation_env_config.containers_config.router_ip + + table_headers = ["Name", "IP", "Interface", "Subnet mask"] + for container in execution_config.emulation_env_config.containers_config.containers: + role = "" + for ip_network in container.ips_and_networks: + if agent_ip == ip_network[0]: + role = " (Agent)" + break + elif router_ip == ip_network[0]: + role = " (Router)" + break + click.secho('|', nl=False, fg='white') + click.secho(f"Container {click.style(container.name + role, fg='magenta')}".center(89), nl=False) + click.secho('|') + click.secho('+' + '-' * 80 + '+', fg='white') + for headers in table_headers: + click.secho('|', nl=False, fg='white') + click.secho(headers.center(19), nl=False) + click.secho(' |') + click.secho('+' + '-' * 80 + '+', fg='white') + for ip_network in container.ips_and_networks: + click.secho('|', nl=False, fg='white') + click.secho(ip_network[0].center(19), nl=False) + click.secho('|', nl=False, fg='white') + click.secho(ip_network[1].name.center(19), nl=False) + click.secho('|', nl=False, fg='white') + click.secho(ip_network[1].interface.center(19), nl=False) + click.secho('|', nl=False, fg='white') + click.secho(ip_network[1].subnet_mask.center(19), nl=False) + click.secho(' |') + click.secho('+' + '-' * 80 + '+', fg='white') + else: + click.secho(f"The emulation with the name \033[95m{emulation}\033[0m " + f"and ID \033[95m{ip_first_octet}\033[0m is not running.") + + def list_logfiles(ip: str) -> None: """ Utility function for listing logfiles From 8239115fe455a8143ba1df0f3d1eaa4b65d09a06 Mon Sep 17 00:00:00 2001 From: foroogh shahab Date: Fri, 16 Aug 2024 14:01:09 +0200 Subject: [PATCH 2/2] A new command is added. --- simulation-system/libs/csle-cli/src/csle_cli/cli.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/simulation-system/libs/csle-cli/src/csle_cli/cli.py b/simulation-system/libs/csle-cli/src/csle_cli/cli.py index 51129094d..86de92a40 100755 --- a/simulation-system/libs/csle-cli/src/csle_cli/cli.py +++ b/simulation-system/libs/csle-cli/src/csle_cli/cli.py @@ -3573,7 +3573,6 @@ def list_containers_hw_info(ip: str, emulation: str, ip_first_octet: int) -> Non :return: None """ - ### Still working on this from csle_common.metastore.metastore_facade import MetastoreFacade execution_config = MetastoreFacade.get_emulation_execution(ip_first_octet=ip_first_octet, emulation_name=emulation) if (execution_config): @@ -3601,7 +3600,7 @@ def list_containers_hw_info(ip: str, emulation: str, ip_first_octet: int) -> Non f"{click.style(execution_config.physical_servers[0], fg='magenta')}") padding_length = 89 - len(line) click.secho(f"|{line}{' ' * padding_length}|") - for i in range(1,len(execution_config.physical_servers)): + for i in range(1, len(execution_config.physical_servers)): click.secho('|', nl=False, fg='white') click.secho(f"{execution_config.physical_servers[i]}{' ' * padding_length}|", fg="magenta", nl=False)