Skip to main content

clientapi_pve/models/
pve_net_config.rs

1/*
2 * Proxmox Virtual Environment API
3 *
4 * Generated from apidoc.js. NOT an official Proxmox specification. See https://pve.proxmox.com/pve-docs/api-viewer/ for the upstream documentation.
5 *
6 * The version of the OpenAPI document: 9.x
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11use crate::models;
12use serde::{Deserialize, Serialize};
13
14#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
15pub struct PveNetConfig {
16
17    /// Bridge to attach the network device to.
18    #[serde(rename = "bridge", skip_serializing_if = "Option::is_none")]
19    pub bridge: Option<String>,
20
21    /// Controls whether this interface's firewall rules should be used.
22    #[serde(rename = "firewall", skip_serializing_if = "Option::is_none")]
23    pub firewall: Option<models::PveBoolean>,
24
25    /// Default gateway for IPv4 traffic.
26    #[serde(rename = "gw", skip_serializing_if = "Option::is_none")]
27    pub gw: Option<String>,
28
29    /// Default gateway for IPv6 traffic.
30    #[serde(rename = "gw6", skip_serializing_if = "Option::is_none")]
31    pub gw6: Option<String>,
32
33    /// Whether this interface's IP configuration should be managed by the host. When enabled, the host (rather than the container) is responsible for the interface's IP configuration. The container should not run its own DHCP client or network manager on this interface. This is useful for containers that lack an internal network management stack, like many application containers.
34    #[serde(rename = "host-managed", skip_serializing_if = "Option::is_none")]
35    pub host_managed: Option<models::PveBoolean>,
36
37    /// A common MAC address with the I/G (Individual/Group) bit not set.
38    #[serde(rename = "hwaddr", skip_serializing_if = "Option::is_none")]
39    pub hwaddr: Option<String>,
40
41    /// IPv4 address in CIDR format.
42    #[serde(rename = "ip", skip_serializing_if = "Option::is_none")]
43    pub ip: Option<String>,
44
45    /// IPv6 address in CIDR format.
46    #[serde(rename = "ip6", skip_serializing_if = "Option::is_none")]
47    pub ip6: Option<String>,
48
49    /// Whether this interface should be disconnected (like pulling the plug).
50    #[serde(rename = "link_down", skip_serializing_if = "Option::is_none")]
51    pub link_down: Option<models::PveBoolean>,
52
53    /// Maximum transfer unit of the interface. (lxc.network.mtu)
54    #[serde(rename = "mtu", skip_serializing_if = "Option::is_none")]
55    pub mtu: Option<i32>,
56
57    /// Name of the network device as seen from inside the container. (lxc.network.name)
58    #[serde(rename = "name")]
59    pub name: String,
60
61    /// Apply rate limiting to the interface
62    #[serde(rename = "rate", skip_serializing_if = "Option::is_none")]
63    pub rate: Option<f64>,
64
65    /// VLAN tag for this interface.
66    #[serde(rename = "tag", skip_serializing_if = "Option::is_none")]
67    pub tag: Option<i32>,
68
69    /// VLAN ids to pass through the interface
70    #[serde(rename = "trunks", skip_serializing_if = "Option::is_none")]
71    pub trunks: Option<String>,
72
73    /// Network interface type.
74    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
75    pub r#type: Option<models::PveLxcTypeEnum>,
76
77
78}
79
80impl PveNetConfig {
81    pub fn new(name: String) -> PveNetConfig {
82        PveNetConfig {
83            
84            bridge: None,
85            
86            firewall: None,
87            
88            gw: None,
89            
90            gw6: None,
91            
92            host_managed: None,
93            
94            hwaddr: None,
95            
96            ip: None,
97            
98            ip6: None,
99            
100            link_down: None,
101            
102            mtu: None,
103            
104            name,
105            
106            rate: None,
107            
108            tag: None,
109            
110            trunks: None,
111            
112            r#type: None,
113            
114        }
115    }
116}
117
118
119impl PveNetConfig {
120    /// Serialise this PveNetConfig into Proxmox's CLI-style shorthand
121    /// string (`key=value,…`). The property marked `x-pve-default-key`
122    /// is emitted positionally without a `key=` prefix; aliases collapse
123    /// multiple property names to the same wire key.
124    ///
125    /// Example: `PveNetConfig `
126    /// → `"virtio,bridge=vmbr0"`
127    pub fn to_shorthand(&self) -> String {
128        let mut parts: Vec<String> = Vec::new();
129        
130        
131        
132        if let Some(ref v) = self.bridge {
133            parts.push(format!("bridge={}", v));
134        }
135        
136        
137        if let Some(ref v) = self.firewall {
138            parts.push(format!("firewall={}", v));
139        }
140        
141        
142        if let Some(ref v) = self.gw {
143            parts.push(format!("gw={}", v));
144        }
145        
146        
147        if let Some(ref v) = self.gw6 {
148            parts.push(format!("gw6={}", v));
149        }
150        
151        
152        if let Some(ref v) = self.host_managed {
153            parts.push(format!("host-managed={}", v));
154        }
155        
156        
157        if let Some(ref v) = self.hwaddr {
158            parts.push(format!("hwaddr={}", v));
159        }
160        
161        
162        if let Some(ref v) = self.ip {
163            parts.push(format!("ip={}", v));
164        }
165        
166        
167        if let Some(ref v) = self.ip6 {
168            parts.push(format!("ip6={}", v));
169        }
170        
171        
172        if let Some(ref v) = self.link_down {
173            parts.push(format!("link_down={}", v));
174        }
175        
176        
177        if let Some(ref v) = self.mtu {
178            parts.push(format!("mtu={}", v));
179        }
180        
181        
182        parts.push(format!("name={}", self.name));
183        
184        
185        
186        if let Some(ref v) = self.rate {
187            parts.push(format!("rate={}", v));
188        }
189        
190        
191        if let Some(ref v) = self.tag {
192            parts.push(format!("tag={}", v));
193        }
194        
195        
196        if let Some(ref v) = self.trunks {
197            parts.push(format!("trunks={}", v));
198        }
199        
200        
201        if let Some(ref v) = self.r#type {
202            parts.push(format!("type={}", v));
203        }
204        
205        parts.join(",")
206    }
207}
208