Skip to content

Commit 2b5ef3d

Browse files
committed
tools/tasks: add a function to create snapshot
Signed-off-by: Olivier Hoareau <olivier.hoareau@vates.tech>
1 parent adadeaa commit 2b5ef3d

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

lib/tools/tasks/snapshot.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Snapshot tasks.
2+
"""
3+
from concurrent.futures import ThreadPoolExecutor
4+
from datetime import date
5+
6+
from lib.host import Host
7+
from lib.vm import VM
8+
9+
from .. import logger
10+
11+
def create_snapshot(host: Host, vm_uuids: list[str]):
12+
"""Create a snapshot for a list of VMs in host.
13+
14+
:param `lib.Host` host:
15+
The target parent which hosts the VMs.
16+
:param list[str] vm_uuids:
17+
uuids of target VMs.
18+
"""
19+
# init VMs list
20+
vms = [VM(uuid, host) for uuid in vm_uuids]
21+
22+
snapshot_name = f"utd-{date.today().strftime('%Y%m%d')}"
23+
24+
logger.debug(f"[{host}] Create snapshot '{snapshot_name}' for VMs: {vm_uuids}")
25+
26+
with ThreadPoolExecutor() as executor:
27+
for vm in vms:
28+
executor.submit(vm.snapshot, None, snapshot_name)

0 commit comments

Comments
 (0)