Search container by name using HTTP requests

This commit is contained in:
Yaroslava Lukoyanova 2023-11-17 16:36:24 +03:00 committed by ylukoyan
parent 8e739adea5
commit 663c144709
2 changed files with 12 additions and 8 deletions

View file

@ -1,6 +1,7 @@
import json import json
import logging import logging
import re import re
import requests
from dataclasses import dataclass from dataclasses import dataclass
from time import sleep from time import sleep
from typing import Optional, Union from typing import Optional, Union
@ -344,12 +345,13 @@ def _parse_cid(output: str) -> str:
@reporter.step("Search container by name") @reporter.step("Search container by name")
def search_container_by_name(wallet: str, name: str, shell: Shell, endpoint: str): def search_container_by_name(name: str, node: ClusterNode):
list_cids = list_containers(wallet, shell, endpoint) node_shell = node.host.get_shell()
for cid in list_cids: output = node_shell.exec(f"curl -I HEAD http://127.0.0.1:8084/{name}")
cont_info = get_container(wallet, cid, shell, endpoint, True) pattern = r"X-Container-Id: (\S+)"
if cont_info.get("attributes", {}).get("Name", None) == name: cid = re.findall(pattern, output.stdout)
return cid if cid:
return cid[0]
return None return None

View file

@ -231,6 +231,8 @@ def search_nodes_with_bucket(
shell: Shell, shell: Shell,
endpoint: str, endpoint: str,
) -> list[ClusterNode]: ) -> list[ClusterNode]:
cid = search_container_by_name(wallet=wallet, name=bucket_name, shell=shell, endpoint=endpoint) cid = search_container_by_name(name=bucket_name, cluster=cluster)
nodes_list = search_nodes_with_container(wallet=wallet, cid=cid, shell=shell, endpoint=endpoint, cluster=cluster) nodes_list = search_nodes_with_container(
wallet=wallet, cid=cid, shell=shell, endpoint=endpoint, cluster=cluster
)
return nodes_list return nodes_list