forked from TrueCloudLab/frostfs-testcases
Change SberCloud api call (get id by ip)
Signed-off-by: Vladimir Avdeev <v.avdeev@yadro.com>
This commit is contained in:
parent
f1d3aa6098
commit
2ebe3192e2
1 changed files with 9 additions and 15 deletions
|
@ -209,23 +209,17 @@ class SberCloud:
|
||||||
access_key_id=config.access_key_id,
|
access_key_id=config.access_key_id,
|
||||||
secret_key=config.secret_key,
|
secret_key=config.secret_key,
|
||||||
)
|
)
|
||||||
self.ecs_nodes = [] # Cached list of ecs servers
|
self.ecs_node_by_ip = {} # Cached list of ecs servers
|
||||||
|
|
||||||
def find_ecs_node_by_ip(self, ip: str, no_cache: bool = False) -> str:
|
def find_ecs_node_by_ip(self, ip: str) -> str:
|
||||||
if not self.ecs_nodes or no_cache:
|
if ip not in self.ecs_node_by_ip:
|
||||||
self.ecs_nodes = self.get_ecs_nodes()
|
self.ecs_node_by_ip[ip] = self.get_ecs_node_id(ip)
|
||||||
nodes_by_ip = [
|
assert ip in self.ecs_node_by_ip
|
||||||
node
|
return self.ecs_node_by_ip[ip]
|
||||||
for node in self.ecs_nodes
|
|
||||||
if ip
|
|
||||||
in [node_ip["addr"] for node_ips in node["addresses"].values() for node_ip in node_ips]
|
|
||||||
]
|
|
||||||
assert len(nodes_by_ip) == 1
|
|
||||||
return nodes_by_ip[0]["id"]
|
|
||||||
|
|
||||||
def get_ecs_nodes(self) -> list[dict]:
|
def get_ecs_node_id(self, ip: str) -> str:
|
||||||
response = self.ecs_requests.get("/detail", {"limit": "1000"}).json()
|
response = self.ecs_requests.get("/detail", {"ip": ip}).json()
|
||||||
return response["servers"]
|
return response["servers"][0]["id"]
|
||||||
|
|
||||||
def start_node(self, node_id: Optional[str] = None, node_ip: Optional[str] = None) -> None:
|
def start_node(self, node_id: Optional[str] = None, node_ip: Optional[str] = None) -> None:
|
||||||
data = {"os-start": {"servers": [{"id": node_id or self.find_ecs_node_by_ip(node_ip)}]}}
|
data = {"os-start": {"servers": [{"id": node_id or self.find_ecs_node_by_ip(node_ip)}]}}
|
||||||
|
|
Loading…
Reference in a new issue