From 937dcd8d8a425c69d2a592a81b567354dc209c4b Mon Sep 17 00:00:00 2001 From: nforsg Date: Thu, 10 Aug 2023 15:23:51 +0200 Subject: [PATCH] fixed some changes --- .../csle_common/dao/docker/docker_container_metadata.py | 2 +- .../src/csle_common/dao/docker/docker_env_metadata.py | 4 ++-- .../libs/csle-common/src/csle_common/util/docker_util.py | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/simulation-system/libs/csle-common/src/csle_common/dao/docker/docker_container_metadata.py b/simulation-system/libs/csle-common/src/csle_common/dao/docker/docker_container_metadata.py index f55e8d7d1..997af552c 100644 --- a/simulation-system/libs/csle-common/src/csle_common/dao/docker/docker_container_metadata.py +++ b/simulation-system/libs/csle-common/src/csle_common/dao/docker/docker_container_metadata.py @@ -8,7 +8,7 @@ class DockerContainerMetadata(JSONSerializable): """ def __init__(self, name: str, status: str, short_id: str, image_short_id: str, image_tags: list, id: str, - created: str, ip: str, network_id: str, gateway: str, mac: str, ip_prefix_len: int, + created: str, ip: str, network_id: int, gateway: str, mac: str, ip_prefix_len: int, name2: str, level: str, hostname: str, image_name: str, net: str, dir: str, config_path: str, container_handle: str, emulation: str, kafka_container: str): """ diff --git a/simulation-system/libs/csle-common/src/csle_common/dao/docker/docker_env_metadata.py b/simulation-system/libs/csle-common/src/csle_common/dao/docker/docker_env_metadata.py index 50957a67a..0b723c9cc 100644 --- a/simulation-system/libs/csle-common/src/csle_common/dao/docker/docker_env_metadata.py +++ b/simulation-system/libs/csle-common/src/csle_common/dao/docker/docker_env_metadata.py @@ -1,4 +1,4 @@ -from typing import List, Dict, Any +from typing import List, Dict, Any, Union from csle_common.dao.docker.docker_container_metadata import DockerContainerMetadata from csle_common.dao.emulation_config.emulation_env_config import EmulationEnvConfig from csle_common.dao.emulation_config.kafka_config import KafkaConfig @@ -11,7 +11,7 @@ class DockerEnvMetadata(JSONSerializable): """ def __init__(self, containers: List[DockerContainerMetadata], name: str, subnet_prefix: str, - subnet_mask: str, level: str, config: EmulationEnvConfig, kafka_config: KafkaConfig): + subnet_mask: str, level: str, config: Union[None, EmulationEnvConfig], kafka_config: Union[None, KafkaConfig]): """ Initializes the DTO diff --git a/simulation-system/libs/csle-common/src/csle_common/util/docker_util.py b/simulation-system/libs/csle-common/src/csle_common/util/docker_util.py index 0e59bb666..8703cf201 100644 --- a/simulation-system/libs/csle-common/src/csle_common/util/docker_util.py +++ b/simulation-system/libs/csle-common/src/csle_common/util/docker_util.py @@ -23,7 +23,10 @@ def parse_runnning_emulation_infos() -> List[DockerEnvMetadata]: client_1 = docker.from_env() client_2 = docker.APIClient(base_url=constants.DOCKER.UNIX_DOCKER_SOCK_URL) parsed_containers = DockerUtil.parse_running_containers(client_1=client_1, client_2=client_2) - emulations = list(set(list(map(lambda x: x.emulation, parsed_containers)))) + for container in parsed_containers: + if container is None: + raise ValueError("contianer is None") + emulations: List[str] = list(set(list(map(lambda x: x.emulation, filter(lambda x: x is not None, parsed_containers))))) parsed_envs = DockerUtil.parse_running_emulation_envs(emulations=emulations, containers=parsed_containers) return parsed_envs @@ -148,6 +151,8 @@ def parse_containers(containers, client2) -> List[DockerContainerMetadata]: constants.DOCKER.MAC_ADDRESS_INFO] ip_prefix_len = inspect_info[constants.DOCKER.NETWORK_SETTINGS][constants.DOCKER.NETWORKS][net][ constants.DOCKER.IP_PREFIX_LEN_INFO] + if emulation is None: + raise ValueError("emulation is None, cannot be None") parsed_c = DockerContainerMetadata( name=c.name, status=c.status, short_id=c.short_id, image_short_id=c.image.short_id, image_tags=c.image.tags, id=c.id,