Fix container filtering by name in devenv

Signed-off-by: Vladimir Domnich <v.domnich@yadro.com>
This commit is contained in:
Vladimir Domnich 2022-08-09 00:17:56 +03:00 committed by Vladimir Domnich
parent 453dcb99fa
commit b597937286

View file

@ -208,9 +208,12 @@ class RemoteDevEnvStorageServiceHelper:
def _get_container_by_name(self, node_name: str, container_name: str) -> dict:
with _create_ssh_client(node_name) as ssh_client:
output = ssh_client.exec('docker ps -a --format "{{json .}}"').stdout
containers = json.loads(output)
for container in containers:
# output contains each container as separate JSON structure, so we find each JSON structure
# by curly brackets (works because JSON is not nested), parse it and find container by name
json_blocks = re.findall(r'\{.*?\}', output, re.DOTALL)
for json_block in json_blocks:
container = json.loads(json_block)
# unlike docker.API in docker ps output Names seems to be a string, so we check by equality
if container["Names"] == container_name:
return container