public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Lukas Wagner" <l.wagner@proxmox.com>
To: "Michael Köppl" <m.koeppl@proxmox.com>, pve-devel@lists.proxmox.com
Subject: Re: [PATCH test-tools 1/6] runner: add vmid-range option for test guest VMIDs
Date: Tue, 06 Oct 2026 12:45:59 +0200	[thread overview]
Message-ID: <DLXP0YRLIFH1.1VF238AER9OP3@proxmox.com> (raw)
In-Reply-To: <20260917162324.1926056-2-m.koeppl@proxmox.com>

On Thu Sep 17, 2026 at 6:23 PM CEST, Michael Köppl wrote:
> +impl FromStr for VmIdRange {
> +    type Err = Error;
> +
> +    fn from_str(s: &str) -> Result<Self, Self::Err> {
> +        let (start, end) = s
> +            .split_once(':')
> +            .ok_or_else(|| format_err!("expected '<start>:<end>', got '{s}'"))?;
> +
> +        let start: u32 = start
> +            .parse()
> +            .with_context(|| format!("invalid range start '{start}'"))?;
> +
> +        let end: u32 = end
> +            .parse()
> +            .with_context(|| format!("invalid range end '{end}'"))?;
> +
> +        if start >= end {
> +            bail!("range start {start} must be lower than its end {end}");
> +        }
> +
> +        if start < VMID_MIN || end > VMID_MAX {
> +            bail!("range must be within {VMID_MIN}..={VMID_MAX}");
> +        }
> +
> +        Ok(Self { start, end })
> +    }
> +}
> +
> +impl std::fmt::Display for VmIdRange {
> +    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
> +        write!(f, "{}:{}", self.start, self.end)
> +    }
> +}
> +
> +impl Serialize for VmIdRange {
> +    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
> +    where
> +        S: serde::Serializer,
> +    {
> +        serializer.collect_str(self)
> +    }
> +}
> +
> +impl<'d> Deserialize<'d> for VmIdRange {
> +    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
> +    where
> +        D: serde::Deserializer<'d>,
> +    {
> +        let s = String::deserialize(deserializer)?;
> +        s.parse().map_err(serde::de::Error::custom)
> +    }
> +}

Btw, you could use:

proxmox_serde::forward_deserialize_to_from_str!(VmIdRange);
proxmox_serde::forward_serialize_to_display!(VmIdRange);

we use these helpers quite often in our code bases already.




  reply	other threads:[~2026-10-06 10:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 16:23 [PATCH test-tools,e2e-tests 0/6] randomly select VMIDs for test Michael Köppl
2026-09-17 16:23 ` [PATCH test-tools 1/6] runner: add vmid-range option for test guest VMIDs Michael Köppl
2026-10-06 10:45   ` Lukas Wagner [this message]
2026-09-17 16:23 ` [PATCH e2e-tests 2/6] lib: add function for drawing a random unused VMID Michael Köppl
2026-09-17 16:23 ` [PATCH e2e-tests 3/6] storage-plugin: use random_vmid function for getting VMIDs Michael Köppl
2026-09-17 16:23 ` [PATCH e2e-tests 4/6] hw-validation: " Michael Köppl
2026-09-17 16:23 ` [PATCH e2e-tests 5/6] tests: " Michael Köppl
2026-09-17 16:23 ` [PATCH e2e-tests 6/6] storage-plugin: README: document the vmid-range option Michael Köppl
2026-10-06 10:50 ` [PATCH test-tools,e2e-tests 0/6] randomly select VMIDs for test Lukas Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DLXP0YRLIFH1.1VF238AER9OP3@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=m.koeppl@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal