-
Notifications
You must be signed in to change notification settings - Fork 1
/
transport_model.py
79 lines (66 loc) · 2.23 KB
/
transport_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
from functools import lru_cache
_ip2port = {
"10.19.90.95": [8501, 8502],
"10.19.160.33": [8501, 8502],
"10.19.117.187": [8503, 8504],
"10.19.128.25": [8503, 8504]
}
_port2ip = {}
for key, value in _ip2port.items():
for port in value:
target = _port2ip.get(port, set())
target.add(key)
_port2ip[port] = target.copy()
# better to move to config to void leak
_ip2pwd = {
"10.19.90.95": "Knowbox.cn",
"10.19.160.33": "Knowbox.cn",
"10.19.117.187": "root!@#.com",
"10.19.128.25": "root!@#.com",
}
_address = [
"[email protected]:/data/midas-model",
"[email protected]:/data/midas-model",
"[email protected]:/data/midas-model",
"[email protected]:/data/midas-model",
]
_source = "/data/lishuang/ad_kafka/update-model-1/serving"
_port = [8501, 8502, 8503, 8504]
_state = """sshpass -p {pwd} scp -r {source} {target}"""
def trans_model(version: int, source: str = None, target: str = None, port: int = None) -> None:
"""
deploy source/version's model to target/port/version ,port decides ips
:param version: model version
:param source: model's path
:param target: deploy the model to where, add port is the abs_path
:param port: model category
:return: None
"""
@lru_cache(maxsize=20)
def parse_ip(address):
ip = address.split(":")[0].split("@")[1]
return ip
def parse2list(item):
if not isinstance(item, (list, tuple)):
item = [item]
return item
port = parse2list(port or _port)
source = source or _source
addresses = parse2list(target or _address.copy())
# print(addresses)
for pp in port:
ips = _port2ip.get(pp, set())
if len(ips) == 0:
continue
for address in addresses:
if parse_ip(address) not in _port2ip[pp]:
continue
real_source = os.path.join(source, str(version))
real_target = os.path.join(address, str(pp))
# TODO: use thread???
os.system(_state.format(pwd=_ip2pwd[parse_ip(address)],
source=real_source,
target=real_target))
if __name__ == "__main__":
trans_model(74)