Skip to content

Commit 3bd4cc8

Browse files
committed
tools/update: use inventory instead of flat args
Flat args in `update_all` have been replaced with a new inventory object. Signed-off-by: Olivier Hoareau <olivier.hoareau@vates.tech>
1 parent 4a99c33 commit 3bd4cc8

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

lib/tools/cli.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88

99
from lib.common import HostAddress
1010
from lib.tools import logger
11+
from lib.tools.inventory import into_inventory, load_inventory
1112
from lib.tools.tasks.update import update_all
1213

1314
def _command_update(args):
14-
update_all(args.hosts, args.repos)
15+
if args.inventory:
16+
inventory = load_inventory(args.inventory)
17+
else:
18+
inventory = into_inventory(args.hosts, args.repos)
19+
20+
update_all(inventory)
1521

1622

1723
def cli():

lib/tools/tasks/update.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,28 @@
44
"""
55
from concurrent.futures import ThreadPoolExecutor
66

7-
from lib.common import HostAddress
87
from lib.host import Host
98
from lib.pool import Pool
109

1110
from .. import logger
1211

13-
def update_all(master_hosts: list[HostAddress], enablerepos: list[str]) -> None:
12+
def update_all(inventory: dict) -> None:
1413
"""Updates all master (primary) hosts.
1514
1615
.. note:: Host must be a master
1716
1817
Throws error if hosts are not master (primary).
1918
20-
:param :py:class:`list[lib.common.HostAddress]` master_hosts:
21-
A list of hosts to update.
22-
:param list[str] enablerepos:
23-
Repositories to enable when updating.
19+
:param dict inventory:
20+
Each host (key) holds its own config data (values).
2421
"""
25-
logger.debug(f"[{master_hosts}] enablerepos: {enablerepos}")
22+
logger.debug(f"Inventory: {inventory}")
2623
# init related pools
27-
pools = [Pool(h) for h in master_hosts]
24+
pools = [Pool(h) for h in inventory]
2825

2926
with ThreadPoolExecutor() as executor:
3027
for p in pools:
31-
executor.submit(update_host, p.master, enablerepos)
28+
executor.submit(update_host, p.master, inventory[p.master.hostname_or_ip]["enablerepos"])
3229

3330

3431
def update_host(host: Host, enablerepos: list[str] = []):

0 commit comments

Comments
 (0)