1// Generated from definition io.k8s.api.resource.v1alpha3.DeviceConstraint
23/// DeviceConstraint must have exactly one field set besides Requests.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceConstraint {
6/// MatchAttribute requires that all devices in question have this attribute and that its type and value are the same across those devices.
7 ///
8 /// For example, if you specified "dra.example.com/numa" (a hypothetical example!), then only devices in the same NUMA node will be chosen. A device which does not have that attribute will not be chosen. All devices should use a value of the same type for this attribute because that is part of its specification, but if one device doesn't, then it also will not be chosen.
9 ///
10 /// Must include the domain qualifier.
11pub match_attribute: Option<std::string::String>,
1213/// Requests is a list of the one or more requests in this claim which must co-satisfy this constraint. If a request is fulfilled by multiple devices, then all of the devices must satisfy the constraint. If this is not specified, this constraint applies to all requests in this claim.
14 ///
15 /// References to subrequests must include the name of the main request and may include the subrequest using the format \<main request\>\[/\<subrequest\>\]. If just the main request is given, the constraint applies to all subrequests.
16pub requests: Option<std::vec::Vec<std::string::String>>,
17}
1819impl crate::DeepMerge for DeviceConstraint {
20fn merge_from(&mut self, other: Self) {
21crate::DeepMerge::merge_from(&mut self.match_attribute, other.match_attribute);
22crate::merge_strategies::list::atomic(&mut self.requests, other.requests);
23 }
24}
2526impl<'de> crate::serde::Deserialize<'de> for DeviceConstraint {
27fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
28#[allow(non_camel_case_types)]
29enum Field {
30 Key_match_attribute,
31 Key_requests,
32 Other,
33 }
3435impl<'de> crate::serde::Deserialize<'de> for Field {
36fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
37struct Visitor;
3839impl crate::serde::de::Visitor<'_> for Visitor {
40type Value = Field;
4142fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
43 f.write_str("field identifier")
44 }
4546fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
47Ok(match v {
48"matchAttribute" => Field::Key_match_attribute,
49"requests" => Field::Key_requests,
50_ => Field::Other,
51 })
52 }
53 }
5455 deserializer.deserialize_identifier(Visitor)
56 }
57 }
5859struct Visitor;
6061impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62type Value = DeviceConstraint;
6364fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65 f.write_str("DeviceConstraint")
66 }
6768fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69let mut value_match_attribute: Option<std::string::String> = None;
70let mut value_requests: Option<std::vec::Vec<std::string::String>> = None;
7172while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
73match key {
74 Field::Key_match_attribute => value_match_attribute = crate::serde::de::MapAccess::next_value(&mut map)?,
75 Field::Key_requests => value_requests = crate::serde::de::MapAccess::next_value(&mut map)?,
76 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
77 }
78 }
7980Ok(DeviceConstraint {
81 match_attribute: value_match_attribute,
82 requests: value_requests,
83 })
84 }
85 }
8687 deserializer.deserialize_struct(
88"DeviceConstraint",
89&[
90"matchAttribute",
91"requests",
92 ],
93 Visitor,
94 )
95 }
96}
9798impl crate::serde::Serialize for DeviceConstraint {
99fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
100let mut state = serializer.serialize_struct(
101"DeviceConstraint",
102self.match_attribute.as_ref().map_or(0, |_| 1) +
103self.requests.as_ref().map_or(0, |_| 1),
104 )?;
105if let Some(value) = &self.match_attribute {
106crate::serde::ser::SerializeStruct::serialize_field(&mut state, "matchAttribute", value)?;
107 }
108if let Some(value) = &self.requests {
109crate::serde::ser::SerializeStruct::serialize_field(&mut state, "requests", value)?;
110 }
111crate::serde::ser::SerializeStruct::end(state)
112 }
113}
114115#[cfg(feature = "schemars")]
116impl crate::schemars::JsonSchema for DeviceConstraint {
117fn schema_name() -> std::string::String {
118"io.k8s.api.resource.v1alpha3.DeviceConstraint".into()
119 }
120121fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
122crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
123 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
124 description: Some("DeviceConstraint must have exactly one field set besides Requests.".into()),
125 ..Default::default()
126 })),
127 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
128 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
129 properties: [
130 (
131"matchAttribute".into(),
132crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
133 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
134 description: Some("MatchAttribute requires that all devices in question have this attribute and that its type and value are the same across those devices.\n\nFor example, if you specified \"dra.example.com/numa\" (a hypothetical example!), then only devices in the same NUMA node will be chosen. A device which does not have that attribute will not be chosen. All devices should use a value of the same type for this attribute because that is part of its specification, but if one device doesn't, then it also will not be chosen.\n\nMust include the domain qualifier.".into()),
135 ..Default::default()
136 })),
137 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
138 ..Default::default()
139 }),
140 ),
141 (
142"requests".into(),
143crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
144 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
145 description: Some("Requests is a list of the one or more requests in this claim which must co-satisfy this constraint. If a request is fulfilled by multiple devices, then all of the devices must satisfy the constraint. If this is not specified, this constraint applies to all requests in this claim.\n\nReferences to subrequests must include the name of the main request and may include the subrequest using the format <main request>[/<subrequest>]. If just the main request is given, the constraint applies to all subrequests.".into()),
146 ..Default::default()
147 })),
148 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
149 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
150 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(
151crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
152 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
153 ..Default::default()
154 })
155 ))),
156 ..Default::default()
157 })),
158 ..Default::default()
159 }),
160 ),
161 ].into(),
162 ..Default::default()
163 })),
164 ..Default::default()
165 })
166 }
167}