From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 9B2AD1FF164
	for <inbox@lore.proxmox.com>; Fri, 11 Apr 2025 17:45:24 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 6F3591DC6B;
	Fri, 11 Apr 2025 17:45:17 +0200 (CEST)
Mime-Version: 1.0
Date: Fri, 11 Apr 2025 17:45:14 +0200
Message-Id: <D93XC9W3SU16.27FQNEVYLV0PI@proxmox.com>
To: "Proxmox VE development discussion" <pve-devel@lists.proxmox.com>
From: "Max Carrara" <m.carrara@proxmox.com>
X-Mailer: aerc 0.18.2-0-ge037c095a049
References: <20250411150634.253684-1-d.kral@proxmox.com>
 <20250411150634.253684-2-d.kral@proxmox.com>
In-Reply-To: <20250411150634.253684-2-d.kral@proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.078 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [listvms.py, vm.name]
Subject: Re: [pve-devel] [RFC esxi-import-tools 2/2] listvms: add message
 when skipping vCLS agent VMs
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

On Fri Apr 11, 2025 at 5:06 PM CEST, Daniel Kral wrote:
> While at it, factor out the checks to make the control flow a little
> easier to read and add information why there is an extra check for the
> vm.config.

Both of these patches LGTM. Neat!

Side note: Shame that the type annotations in that regard are
incomplete, but that's something we have to deal with, unfortunately :s

Consider:

Reviewed-by: Max Carrara <m.carrara@proxmox.com>

>
> Signed-off-by: Daniel Kral <d.kral@proxmox.com>
> ---
> This is not essential, but I thought it wouldn't hurt to let people know
> of both types being skipped, but could also get quite noisy if there are
> vCLS and/or diskless VMs.
>
>  listvms.py | 30 ++++++++++++++++++------------
>  1 file changed, 18 insertions(+), 12 deletions(-)
>
> diff --git a/listvms.py b/listvms.py
> index bd0adcf..be03759 100755
> --- a/listvms.py
> +++ b/listvms.py
> @@ -251,6 +251,20 @@ def fetch_and_update_vm_data(vm: vim.VirtualMachine, data: dict[Any, Any]):
>      datastores.update({ds.name: ds.url for ds in vm.config.datastoreUrl})
>  
>  
> +def is_vcls_agent_vm(vm: vim.VirtualMachine) -> bool:
> +    # older ESXi installations seem to not expose the vm config
> +    if vm.config is not None:
> +        return False
> +
> +    return any(cfg.key == "HDCS.agent"
> +               and cfg.value.lower() == "true"
> +               for cfg in vm.config.extraConfig)
> +
> +def is_diskless_vm(vm: vim.VirtualMachine) -> bool:
> +    datastore_name, _ = parse_file_path(vm.config.files.vmPathName)
> +
> +    return not datastore_name
> +
>  def main():
>      args = parse_args()
>  
> @@ -266,20 +280,12 @@ def main():
>          data = {}
>          for vm in list_vms(connection):
>              # drop vCLS machines
> -            vCLS = vm.config is not None and any(
> -                cfg.key == "HDCS.agent"
> -                and cfg.value.lower() == "true"
> -                for cfg in vm.config.extraConfig
> -            )
> -            if vCLS:
> +            if is_vcls_agent_vm(vm):
> +                print(f"Skipping vCLS agent VM: {vm.name}", file=sys.stderr)
>                  continue
>              # drop vms with empty datastore
> -            datastore_name, relative_vmx_path = parse_file_path(
> -                vm.config.files.vmPathName
> -            )
> -            if not datastore_name:
> -                print(f"Skipping VM (no datastore value): {vm.name}",
> -                      file=sys.stderr)
> +            if is_diskless_vm(vm):
> +                print(f"Skipping diskless VM: {vm.name}", file=sys.stderr)
>                  continue
>              try:
>                  fetch_and_update_vm_data(vm, data)



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel