datadog_api_client/datadogV2/model/
model_interface_attributes.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// The interface attributes
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct InterfaceAttributes {
14    /// The interface alias
15    #[serde(rename = "alias")]
16    pub alias: Option<String>,
17    /// The interface description
18    #[serde(rename = "description")]
19    pub description: Option<String>,
20    /// The interface index
21    #[serde(rename = "index")]
22    pub index: Option<i64>,
23    /// The interface IP addresses
24    #[serde(rename = "ip_addresses")]
25    pub ip_addresses: Option<Vec<String>>,
26    /// The interface MAC address
27    #[serde(rename = "mac_address")]
28    pub mac_address: Option<String>,
29    /// The interface name
30    #[serde(rename = "name")]
31    pub name: Option<String>,
32    /// The interface status
33    #[serde(rename = "status")]
34    pub status: Option<crate::datadogV2::model::InterfaceAttributesStatus>,
35    #[serde(flatten)]
36    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
37    #[serde(skip)]
38    #[serde(default)]
39    pub(crate) _unparsed: bool,
40}
41
42impl InterfaceAttributes {
43    pub fn new() -> InterfaceAttributes {
44        InterfaceAttributes {
45            alias: None,
46            description: None,
47            index: None,
48            ip_addresses: None,
49            mac_address: None,
50            name: None,
51            status: None,
52            additional_properties: std::collections::BTreeMap::new(),
53            _unparsed: false,
54        }
55    }
56
57    pub fn alias(mut self, value: String) -> Self {
58        self.alias = Some(value);
59        self
60    }
61
62    pub fn description(mut self, value: String) -> Self {
63        self.description = Some(value);
64        self
65    }
66
67    pub fn index(mut self, value: i64) -> Self {
68        self.index = Some(value);
69        self
70    }
71
72    pub fn ip_addresses(mut self, value: Vec<String>) -> Self {
73        self.ip_addresses = Some(value);
74        self
75    }
76
77    pub fn mac_address(mut self, value: String) -> Self {
78        self.mac_address = Some(value);
79        self
80    }
81
82    pub fn name(mut self, value: String) -> Self {
83        self.name = Some(value);
84        self
85    }
86
87    pub fn status(mut self, value: crate::datadogV2::model::InterfaceAttributesStatus) -> Self {
88        self.status = Some(value);
89        self
90    }
91
92    pub fn additional_properties(
93        mut self,
94        value: std::collections::BTreeMap<String, serde_json::Value>,
95    ) -> Self {
96        self.additional_properties = value;
97        self
98    }
99}
100
101impl Default for InterfaceAttributes {
102    fn default() -> Self {
103        Self::new()
104    }
105}
106
107impl<'de> Deserialize<'de> for InterfaceAttributes {
108    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
109    where
110        D: Deserializer<'de>,
111    {
112        struct InterfaceAttributesVisitor;
113        impl<'a> Visitor<'a> for InterfaceAttributesVisitor {
114            type Value = InterfaceAttributes;
115
116            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
117                f.write_str("a mapping")
118            }
119
120            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
121            where
122                M: MapAccess<'a>,
123            {
124                let mut alias: Option<String> = None;
125                let mut description: Option<String> = None;
126                let mut index: Option<i64> = None;
127                let mut ip_addresses: Option<Vec<String>> = None;
128                let mut mac_address: Option<String> = None;
129                let mut name: Option<String> = None;
130                let mut status: Option<crate::datadogV2::model::InterfaceAttributesStatus> = None;
131                let mut additional_properties: std::collections::BTreeMap<
132                    String,
133                    serde_json::Value,
134                > = std::collections::BTreeMap::new();
135                let mut _unparsed = false;
136
137                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
138                    match k.as_str() {
139                        "alias" => {
140                            if v.is_null() {
141                                continue;
142                            }
143                            alias = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
144                        }
145                        "description" => {
146                            if v.is_null() {
147                                continue;
148                            }
149                            description =
150                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
151                        }
152                        "index" => {
153                            if v.is_null() {
154                                continue;
155                            }
156                            index = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
157                        }
158                        "ip_addresses" => {
159                            if v.is_null() {
160                                continue;
161                            }
162                            ip_addresses =
163                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
164                        }
165                        "mac_address" => {
166                            if v.is_null() {
167                                continue;
168                            }
169                            mac_address =
170                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
171                        }
172                        "name" => {
173                            if v.is_null() {
174                                continue;
175                            }
176                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
177                        }
178                        "status" => {
179                            if v.is_null() {
180                                continue;
181                            }
182                            status = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
183                            if let Some(ref _status) = status {
184                                match _status {
185                                    crate::datadogV2::model::InterfaceAttributesStatus::UnparsedObject(_status) => {
186                                        _unparsed = true;
187                                    },
188                                    _ => {}
189                                }
190                            }
191                        }
192                        &_ => {
193                            if let Ok(value) = serde_json::from_value(v.clone()) {
194                                additional_properties.insert(k, value);
195                            }
196                        }
197                    }
198                }
199
200                let content = InterfaceAttributes {
201                    alias,
202                    description,
203                    index,
204                    ip_addresses,
205                    mac_address,
206                    name,
207                    status,
208                    additional_properties,
209                    _unparsed,
210                };
211
212                Ok(content)
213            }
214        }
215
216        deserializer.deserialize_any(InterfaceAttributesVisitor)
217    }
218}