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

View file

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