66
77from concurrent .futures import ThreadPoolExecutor
88
9+ from lib .host import Host
910from lib .pool import NotAMasterHostError , Pool
1011from lib .tools .inventory import Inventory
12+ from lib .tools .tasks .snapshot import create_snapshots
1113
1214from .. import logger
1315
@@ -27,10 +29,18 @@ def update_pools(inventory: Inventory) -> None:
2729 inventory_hosts = inventory ["hosts" ]
2830 # init related pools
2931 pools : list [Pool ] = []
32+ nested_hosts : dict [str , list [Host ]] = {}
3033 for host in inventory_hosts :
3134 try :
3235 p = Pool (host )
3336 pools .append (p )
37+ hosting_pool = inventory_hosts [host ]["hosting_pool" ]
38+ if hosting_pool is not None :
39+ # we assume all hosts are nested, not only master
40+ if nested_hosts .get (hosting_pool ) is not None :
41+ nested_hosts [hosting_pool ].extend (p .hosts )
42+ else :
43+ nested_hosts [hosting_pool ] = p .hosts
3444 except NotAMasterHostError :
3545 logger .warning (f"[{ host } ] Skipping: not a master host" )
3646
@@ -47,3 +57,9 @@ def update_pools(inventory: Inventory) -> None:
4757 # repos are the same as for the master host
4858 repos = inventory_hosts [p .master .hostname_or_ip ]["repositories" ]
4959 executor .submit (other_host .update , repos )
60+
61+ # Snapshot creation
62+ for hosting_pool , nested in nested_hosts .items ():
63+ pool = Pool (hosting_pool ) # mandatory for getting an host instance
64+ vm_uuids = [h .get_system_uuid () for h in nested ]
65+ create_snapshots (pool .master , vm_uuids )
0 commit comments