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