MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / ovmf_variant_for_version

Function ovmf_variant_for_version

dstack-mr/src/lib.rs:29–47  ·  view source on GitHub ↗

Pick the OVMF variant for a given dstack OS version string ("MAJOR.MINOR.PATCH"). Treats `0.5.10 <= v < 0.6.0` and `v >= 0.6.1` as `Stable202505`, everything else as `Pre202505`. Used as a fallback when `VmConfig::ovmf_variant` is absent.

(version: &str)

Source from the content-addressed store, hash-verified

27/// Treats `0.5.10 <= v < 0.6.0` and `v >= 0.6.1` as `Stable202505`, everything else as
28/// `Pre202505`. Used as a fallback when `VmConfig::ovmf_variant` is absent.
29pub fn ovmf_variant_for_version(version: &str) -> Result<OvmfVariant> {
30 let parts: Vec<u32> = version
31 .split('.')
32 .map(|p| {
33 p.parse::<u32>()
34 .with_context(|| format!("invalid version component: {p}"))
35 })
36 .collect::<Result<Vec<_>, _>>()?;
37 if parts.len() != 3 {
38 bail!("expected MAJOR.MINOR.PATCH, got {version}");
39 }
40 let v = (parts[0], parts[1], parts[2]);
41 let stable = ((0, 5, 10)..(0, 6, 0)).contains(&v) || v >= (0, 6, 1);
42 Ok(if stable {
43 OvmfVariant::Stable202505
44 } else {
45 OvmfVariant::Pre202505
46 })
47}
48
49/// Extract the `MAJOR.MINOR.PATCH` version suffix from a dstack image name.
50///

Callers 2

mainFunction · 0.85
ovmf_variant_for_imageFunction · 0.85

Calls 2

containsMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected