openjd_model/
capabilities.rs1use crate::error::ModelError;
13use crate::types::{Extensions, SpecificationRevision};
14
15const STANDARD_AMOUNT_CAPABILITIES_V2023_09: &[&str] = &[
17 "amount.worker.vcpu",
18 "amount.worker.memory",
19 "amount.worker.gpu",
20 "amount.worker.gpu.memory",
21 "amount.worker.disk.scratch",
22];
23
24const STANDARD_ATTRIBUTE_CAPABILITIES_V2023_09: &[(&str, &[&str])] = &[
26 ("attr.worker.os.family", &["linux", "windows", "macos"]),
27 ("attr.worker.cpu.arch", &["x86_64", "arm64"]),
28];
29
30fn unsupported_revision(revision: SpecificationRevision) -> ModelError {
31 ModelError::DecodeValidation(format!("Unsupported specification revision: {revision}"))
32}
33
34pub fn standard_amount_capability_names(
36 revision: SpecificationRevision,
37 _extensions: &Extensions,
38) -> Result<&'static [&'static str], ModelError> {
39 #[allow(unreachable_patterns)] match revision {
41 SpecificationRevision::V2023_09 => Ok(STANDARD_AMOUNT_CAPABILITIES_V2023_09),
42 _ => Err(unsupported_revision(revision)),
43 }
44}
45
46pub fn standard_attribute_capability_names(
48 revision: SpecificationRevision,
49 _extensions: &Extensions,
50) -> Result<Vec<&'static str>, ModelError> {
51 #[allow(unreachable_patterns)]
52 match revision {
53 SpecificationRevision::V2023_09 => Ok(STANDARD_ATTRIBUTE_CAPABILITIES_V2023_09
54 .iter()
55 .map(|(name, _)| *name)
56 .collect()),
57 _ => Err(unsupported_revision(revision)),
58 }
59}
60
61pub fn standard_attribute_capabilities(
64 revision: SpecificationRevision,
65 _extensions: &Extensions,
66) -> Result<&'static [(&'static str, &'static [&'static str])], ModelError> {
67 #[allow(unreachable_patterns)]
68 match revision {
69 SpecificationRevision::V2023_09 => Ok(STANDARD_ATTRIBUTE_CAPABILITIES_V2023_09),
70 _ => Err(unsupported_revision(revision)),
71 }
72}
73
74pub fn validate_amount_capability_name(name: &str) -> Result<(), String> {
76 let re = &crate::template::validate_v2023_09::helpers::AMOUNT_CAP_RE;
77 if re.is_match(name) {
78 Ok(())
79 } else {
80 Err(format!("'{name}' is not a valid amount capability name"))
81 }
82}
83
84pub fn validate_attribute_capability_name(name: &str) -> Result<(), String> {
86 let re = &crate::template::validate_v2023_09::helpers::ATTR_CAP_RE;
87 if re.is_match(name) {
88 Ok(())
89 } else {
90 Err(format!("'{name}' is not a valid attribute capability name"))
91 }
92}