Skip to content

Commit

Permalink
fixed some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nforsg committed Aug 10, 2023
1 parent 1f10651 commit 937dcd8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 937dcd8

Please sign in to comment.