Skip to content

Commit 65ea2a4

Browse files
committed
feat(tools): adds an update scenario for all targets
This change adds a new function that describes the main update scenario. It handles multiple hosts and then runs an update on each of them. Basically, it is the kind of function that can be called directly from a CLI. Signed-off-by: Olivier Hoareau <olivier.hoareau@vates.tech>
1 parent fcfbb30 commit 65ea2a4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/tools/tasks/update.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,37 @@
22
33
This module is intended for performing update actions on existing remote targets.
44
"""
5+
from concurrent.futures import ThreadPoolExecutor
56

7+
from lib.common import HostAddress
68
from lib.host import Host
9+
from lib.pool import Pool
710

811
from .. import logger
912

1013
from typing import List
1114

15+
def update_all(master_hosts: List[HostAddress], enablerepos: List[str]) -> None:
16+
"""Updates all master (primary) hosts.
17+
18+
.. note:: Host must be a master
19+
20+
Throws error if hosts are not master (primary).
21+
22+
:param :py:class:`List[lib.common.HostAddress]` master_hosts:
23+
A list of hosts to update.
24+
:param List[str] enablerepos:
25+
Enable one or more repo(s) when updating.
26+
"""
27+
logger.debug(f"[{master_hosts}] enablerepos: {enablerepos}")
28+
# init related pools
29+
pools = [Pool(h) for h in master_hosts]
30+
31+
with ThreadPoolExecutor() as executor:
32+
for p in pools:
33+
executor.submit(update_host, p.master, enablerepos)
34+
35+
1236
def update_host(host: Host, enablerepos: List[str] = []):
1337
"""Updates the target host.
1438

0 commit comments

Comments
 (0)