Add backend bridge support
This commit is contained in:
parent
aac05b7faf
commit
ff372800bd
@ -80,7 +80,9 @@ pub struct NetMacAddress {
|
||||
#[serde(rename = "source")]
|
||||
pub struct NetIntSourceXML {
|
||||
#[serde(rename = "@network")]
|
||||
pub network: String,
|
||||
pub network: Option<String>,
|
||||
#[serde(rename = "@bridge")]
|
||||
pub bridge: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
|
@ -53,7 +53,8 @@ pub struct Network {
|
||||
#[serde(tag = "type")]
|
||||
pub enum NetworkType {
|
||||
UserspaceSLIRPStack,
|
||||
DefinedNetwork { network: String }, // TODO : complete network types
|
||||
DefinedNetwork { network: String },
|
||||
Bridge { bridge: String },
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
@ -240,7 +241,18 @@ impl VMInfo {
|
||||
mac,
|
||||
r#type: "network".to_string(),
|
||||
source: Some(NetIntSourceXML {
|
||||
network: network.to_string(),
|
||||
network: Some(network.to_string()),
|
||||
bridge: None,
|
||||
}),
|
||||
model,
|
||||
filterref,
|
||||
},
|
||||
NetworkType::Bridge { bridge } => DomainNetInterfaceXML {
|
||||
r#type: "bridge".to_string(),
|
||||
mac,
|
||||
source: Some(NetIntSourceXML {
|
||||
network: None,
|
||||
bridge: Some(bridge.to_string()),
|
||||
}),
|
||||
model,
|
||||
filterref,
|
||||
@ -468,7 +480,34 @@ impl VMInfo {
|
||||
r#type: match d.r#type.as_str() {
|
||||
"user" => NetworkType::UserspaceSLIRPStack,
|
||||
"network" => NetworkType::DefinedNetwork {
|
||||
network: d.source.as_ref().unwrap().network.to_string(),
|
||||
network: d
|
||||
.source
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.network
|
||||
.as_deref()
|
||||
.ok_or_else(|| {
|
||||
LibVirtStructError::DomainExtraction(
|
||||
"Missing source network for defined network!"
|
||||
.to_string(),
|
||||
)
|
||||
})?
|
||||
.to_string(),
|
||||
},
|
||||
"bridge" => NetworkType::Bridge {
|
||||
bridge: d
|
||||
.source
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.bridge
|
||||
.as_deref()
|
||||
.ok_or_else(|| {
|
||||
LibVirtStructError::DomainExtraction(
|
||||
"Missing bridge name for bridge connection!"
|
||||
.to_string(),
|
||||
)
|
||||
})?
|
||||
.to_string(),
|
||||
},
|
||||
a => {
|
||||
return Err(LibVirtStructError::DomainExtraction(format!(
|
||||
|
44
virtweb_docs/BRIDGE.md
Normal file
44
virtweb_docs/BRIDGE.md
Normal file
@ -0,0 +1,44 @@
|
||||
# Bridges
|
||||
|
||||
Bridges can be used to connect virtual machines to networks.
|
||||
|
||||
## Setup Bridge on Ubuntu
|
||||
|
||||
1. Install dependencies:
|
||||
|
||||
```bash
|
||||
sudo apt install bridge-utils
|
||||
```
|
||||
|
||||
2. Adapt your netplan configuration to set the following:
|
||||
|
||||
```yaml
|
||||
network:
|
||||
version: 2
|
||||
renderer: networkd
|
||||
ethernets:
|
||||
enp2s0:
|
||||
dhcp4: no
|
||||
bridges:
|
||||
br0: # Bridge name
|
||||
dhcp4: yes
|
||||
interfaces:
|
||||
- enp2s0 # Set to your interface
|
||||
```
|
||||
|
||||
|
||||
3. Apply netplan configuration:
|
||||
|
||||
```bash
|
||||
sudo netplan apply
|
||||
```
|
||||
|
||||
|
||||
4. Get the state and the list of bridges in the system:
|
||||
|
||||
```bash
|
||||
sudo brctl show
|
||||
```
|
||||
|
||||
## Reference
|
||||
[How to Configure Network Bridge in Ubuntu](https://www.tecmint.com/create-network-bridge-in-ubuntu/)
|
Loading…
x
Reference in New Issue
Block a user