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

1// Generated from definition io.k8s.api.resource.v1beta2.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    pub ips: Option<std::vec::Vec<std::string::String>>,
18}
19
20impl crate::DeepMerge for NetworkDeviceData {
21    fn merge_from(&mut self, other: Self) {
22        crate::DeepMerge::merge_from(&mut self.hardware_address, other.hardware_address);
23        crate::DeepMerge::merge_from(&mut self.interface_name, other.interface_name);
24        crate::merge_strategies::list::atomic(&mut self.ips, other.ips);
25    }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for NetworkDeviceData {
29    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
30        #[allow(non_camel_case_types)]
31        enum Field {
32            Key_hardware_address,
33            Key_interface_name,
34            Key_ips,
35            Other,
36        }
37
38        impl<'de> crate::serde::Deserialize<'de> for Field {
39            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
40                struct Visitor;
41
42                impl crate::serde::de::Visitor<'_> for Visitor {
43                    type Value = Field;
44
45                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
46                        f.write_str("field identifier")
47                    }
48
49                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
50                        Ok(match v {
51                            "hardwareAddress" => Field::Key_hardware_address,
52                            "interfaceName" => Field::Key_interface_name,
53                            "ips" => Field::Key_ips,
54                            _ => Field::Other,
55                        })
56                    }
57                }
58
59                deserializer.deserialize_identifier(Visitor)
60            }
61        }
62
63        struct Visitor;
64
65        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
66            type Value = NetworkDeviceData;
67
68            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
69                f.write_str("NetworkDeviceData")
70            }
71
72            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
73                let mut value_hardware_address: Option<std::string::String> = None;
74                let mut value_interface_name: Option<std::string::String> = None;
75                let mut value_ips: Option<std::vec::Vec<std::string::String>> = None;
76
77                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
78                    match key {
79                        Field::Key_hardware_address => value_hardware_address = crate::serde::de::MapAccess::next_value(&mut map)?,
80                        Field::Key_interface_name => value_interface_name = crate::serde::de::MapAccess::next_value(&mut map)?,
81                        Field::Key_ips => value_ips = crate::serde::de::MapAccess::next_value(&mut map)?,
82                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
83                    }
84                }
85
86                Ok(NetworkDeviceData {
87                    hardware_address: value_hardware_address,
88                    interface_name: value_interface_name,
89                    ips: value_ips,
90                })
91            }
92        }
93
94        deserializer.deserialize_struct(
95            "NetworkDeviceData",
96            &[
97                "hardwareAddress",
98                "interfaceName",
99                "ips",
100            ],
101            Visitor,
102        )
103    }
104}
105
106impl crate::serde::Serialize for NetworkDeviceData {
107    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
108        let mut state = serializer.serialize_struct(
109            "NetworkDeviceData",
110            self.hardware_address.as_ref().map_or(0, |_| 1) +
111            self.interface_name.as_ref().map_or(0, |_| 1) +
112            self.ips.as_ref().map_or(0, |_| 1),
113        )?;
114        if let Some(value) = &self.hardware_address {
115            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "hardwareAddress", value)?;
116        }
117        if let Some(value) = &self.interface_name {
118            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "interfaceName", value)?;
119        }
120        if let Some(value) = &self.ips {
121            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "ips", value)?;
122        }
123        crate::serde::ser::SerializeStruct::end(state)
124    }
125}
126
127#[cfg(feature = "schemars")]
128impl crate::schemars::JsonSchema for NetworkDeviceData {
129    fn schema_name() -> std::string::String {
130        "io.k8s.api.resource.v1beta2.NetworkDeviceData".into()
131    }
132
133    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
134        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
135            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
136                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()),
137                ..Default::default()
138            })),
139            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
140            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
141                properties: [
142                    (
143                        "hardwareAddress".into(),
144                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
145                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
146                                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()),
147                                ..Default::default()
148                            })),
149                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
150                            ..Default::default()
151                        }),
152                    ),
153                    (
154                        "interfaceName".into(),
155                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
156                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
157                                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()),
158                                ..Default::default()
159                            })),
160                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
161                            ..Default::default()
162                        }),
163                    ),
164                    (
165                        "ips".into(),
166                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
167                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
168                                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.".into()),
169                                ..Default::default()
170                            })),
171                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
172                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
173                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(
174                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
175                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
176                                        ..Default::default()
177                                    })
178                                ))),
179                                ..Default::default()
180                            })),
181                            ..Default::default()
182                        }),
183                    ),
184                ].into(),
185                ..Default::default()
186            })),
187            ..Default::default()
188        })
189    }
190}