k8s_openapi/v1_33/api/resource/v1beta1/
network_device_data.rs

1// Generated from definition io.k8s.api.resource.v1beta1.NetworkDeviceData
2
3/// NetworkDeviceData provides network-related details for the allocated device. This information may be filled by drivers or other components to configure or identify the device within a network context.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct NetworkDeviceData {
6    /// HardwareAddress represents the hardware address (e.g. MAC Address) of the device's network interface.
7    ///
8    /// Must not be longer than 128 characters.
9    pub hardware_address: Option<std::string::String>,
10
11    /// InterfaceName specifies the name of the network interface associated with the allocated device. This might be the name of a physical or virtual network interface being configured in the pod.
12    ///
13    /// Must not be longer than 256 characters.
14    pub interface_name: Option<std::string::String>,
15
16    /// IPs lists the network addresses assigned to the device's network interface. This can include both IPv4 and IPv6 addresses. The IPs are in the CIDR notation, which includes both the address and the associated subnet mask. e.g.: "192.0.2.5/24" for IPv4 and "2001:db8::5/64" for IPv6.
17    ///
18    /// Must not contain more than 16 entries.
19    pub ips: Option<std::vec::Vec<std::string::String>>,
20}
21
22impl crate::DeepMerge for NetworkDeviceData {
23    fn merge_from(&mut self, other: Self) {
24        crate::DeepMerge::merge_from(&mut self.hardware_address, other.hardware_address);
25        crate::DeepMerge::merge_from(&mut self.interface_name, other.interface_name);
26        crate::merge_strategies::list::atomic(&mut self.ips, other.ips);
27    }
28}
29
30impl<'de> crate::serde::Deserialize<'de> for NetworkDeviceData {
31    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
32        #[allow(non_camel_case_types)]
33        enum Field {
34            Key_hardware_address,
35            Key_interface_name,
36            Key_ips,
37            Other,
38        }
39
40        impl<'de> crate::serde::Deserialize<'de> for Field {
41            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
42                struct Visitor;
43
44                impl crate::serde::de::Visitor<'_> for Visitor {
45                    type Value = Field;
46
47                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
48                        f.write_str("field identifier")
49                    }
50
51                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
52                        Ok(match v {
53                            "hardwareAddress" => Field::Key_hardware_address,
54                            "interfaceName" => Field::Key_interface_name,
55                            "ips" => Field::Key_ips,
56                            _ => Field::Other,
57                        })
58                    }
59                }
60
61                deserializer.deserialize_identifier(Visitor)
62            }
63        }
64
65        struct Visitor;
66
67        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
68            type Value = NetworkDeviceData;
69
70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71                f.write_str("NetworkDeviceData")
72            }
73
74            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
75                let mut value_hardware_address: Option<std::string::String> = None;
76                let mut value_interface_name: Option<std::string::String> = None;
77                let mut value_ips: Option<std::vec::Vec<std::string::String>> = None;
78
79                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
80                    match key {
81                        Field::Key_hardware_address => value_hardware_address = crate::serde::de::MapAccess::next_value(&mut map)?,
82                        Field::Key_interface_name => value_interface_name = crate::serde::de::MapAccess::next_value(&mut map)?,
83                        Field::Key_ips => value_ips = crate::serde::de::MapAccess::next_value(&mut map)?,
84                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
85                    }
86                }
87
88                Ok(NetworkDeviceData {
89                    hardware_address: value_hardware_address,
90                    interface_name: value_interface_name,
91                    ips: value_ips,
92                })
93            }
94        }
95
96        deserializer.deserialize_struct(
97            "NetworkDeviceData",
98            &[
99                "hardwareAddress",
100                "interfaceName",
101                "ips",
102            ],
103            Visitor,
104        )
105    }
106}
107
108impl crate::serde::Serialize for NetworkDeviceData {
109    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
110        let mut state = serializer.serialize_struct(
111            "NetworkDeviceData",
112            self.hardware_address.as_ref().map_or(0, |_| 1) +
113            self.interface_name.as_ref().map_or(0, |_| 1) +
114            self.ips.as_ref().map_or(0, |_| 1),
115        )?;
116        if let Some(value) = &self.hardware_address {
117            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "hardwareAddress", value)?;
118        }
119        if let Some(value) = &self.interface_name {
120            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "interfaceName", value)?;
121        }
122        if let Some(value) = &self.ips {
123            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "ips", value)?;
124        }
125        crate::serde::ser::SerializeStruct::end(state)
126    }
127}
128
129#[cfg(feature = "schemars")]
130impl crate::schemars::JsonSchema for NetworkDeviceData {
131    fn schema_name() -> std::string::String {
132        "io.k8s.api.resource.v1beta1.NetworkDeviceData".into()
133    }
134
135    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
136        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
137            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
138                description: Some("NetworkDeviceData provides network-related details for the allocated device. This information may be filled by drivers or other components to configure or identify the device within a network context.".into()),
139                ..Default::default()
140            })),
141            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
142            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
143                properties: [
144                    (
145                        "hardwareAddress".into(),
146                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
147                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
148                                description: Some("HardwareAddress represents the hardware address (e.g. MAC Address) of the device's network interface.\n\nMust not be longer than 128 characters.".into()),
149                                ..Default::default()
150                            })),
151                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
152                            ..Default::default()
153                        }),
154                    ),
155                    (
156                        "interfaceName".into(),
157                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
158                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
159                                description: Some("InterfaceName specifies the name of the network interface associated with the allocated device. This might be the name of a physical or virtual network interface being configured in the pod.\n\nMust not be longer than 256 characters.".into()),
160                                ..Default::default()
161                            })),
162                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
163                            ..Default::default()
164                        }),
165                    ),
166                    (
167                        "ips".into(),
168                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
169                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
170                                description: Some("IPs lists the network addresses assigned to the device's network interface. This can include both IPv4 and IPv6 addresses. The IPs are in the CIDR notation, which includes both the address and the associated subnet mask. e.g.: \"192.0.2.5/24\" for IPv4 and \"2001:db8::5/64\" for IPv6.\n\nMust not contain more than 16 entries.".into()),
171                                ..Default::default()
172                            })),
173                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
174                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
175                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(
176                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
177                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
178                                        ..Default::default()
179                                    })
180                                ))),
181                                ..Default::default()
182                            })),
183                            ..Default::default()
184                        }),
185                    ),
186                ].into(),
187                ..Default::default()
188            })),
189            ..Default::default()
190        })
191    }
192}