From 2e24a542e785f42c68ffac147c6aaaafa4dcc42b Mon Sep 17 00:00:00 2001 From: "Stark, Jens (Landesbaudirektion)" Date: Fri, 7 Nov 2025 20:25:37 +0100 Subject: [PATCH] added optional vihost filter to snapshot command --- checkvsphere/vcmd/snapshots.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/checkvsphere/vcmd/snapshots.py b/checkvsphere/vcmd/snapshots.py index c7e7414..b8fdc7d 100644 --- a/checkvsphere/vcmd/snapshots.py +++ b/checkvsphere/vcmd/snapshots.py @@ -107,6 +107,8 @@ def run(): global check global args parser = get_argparser() + parser.add_optional_arguments(cli.Argument.VIHOST) + args = parser.get_args() if not (args.warning or args.critical): @@ -117,10 +119,20 @@ def run(): args._si = service_instance.connect(args) + if args.vihost: + host_view = args._si.content.viewManager.CreateContainerView( + args._si.content.rootFolder, [vim.HostSystem], True) + try: + parentView = next(x for x in host_view.view if x.name.lower() == args.vihost.lower()) + except: + raise CheckVsphereException(f"host {args.vihost} not found") + else: + parentView = args._si.content.rootFolder + vms = find_entity_views( args._si, vim.VirtualMachine, - begin_entity=args._si.content.rootFolder, + begin_entity=parentView, properties=['name', 'snapshot', 'resourcePool', 'config.template'] )