Can define bridge name
This commit is contained in:
parent
afebe97395
commit
e969455c58
@ -71,7 +71,15 @@ pub async fn update(
|
|||||||
path: web::Path<NetworkID>,
|
path: web::Path<NetworkID>,
|
||||||
body: web::Json<NetworkInfo>,
|
body: web::Json<NetworkInfo>,
|
||||||
) -> HttpResult {
|
) -> HttpResult {
|
||||||
let mut network = body.0.to_virt_network()?;
|
let mut network = match body.0.to_virt_network() {
|
||||||
|
Ok(n) => n,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Failed to extract network info! {e}");
|
||||||
|
return Ok(
|
||||||
|
HttpResponse::BadRequest().json(format!("Failed to extract network info!\n${e}"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
network.uuid = Some(path.uid);
|
network.uuid = Some(path.uid);
|
||||||
|
|
||||||
if let Err(e) = client.update_network(network).await {
|
if let Err(e) = client.update_network(network).await {
|
||||||
|
@ -378,6 +378,14 @@ pub struct NetworkForwardXML {
|
|||||||
pub dev: String,
|
pub dev: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Network bridge information
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize, Debug)]
|
||||||
|
#[serde(rename = "bridge")]
|
||||||
|
pub struct NetworkBridgeXML {
|
||||||
|
#[serde(rename(serialize = "@name"))]
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
/// Network DNS information
|
/// Network DNS information
|
||||||
#[derive(serde::Serialize, serde::Deserialize, Debug)]
|
#[derive(serde::Serialize, serde::Deserialize, Debug)]
|
||||||
#[serde(rename = "dns")]
|
#[serde(rename = "dns")]
|
||||||
@ -500,6 +508,8 @@ pub struct NetworkXML {
|
|||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub forward: Option<NetworkForwardXML>,
|
pub forward: Option<NetworkForwardXML>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub bridge: Option<NetworkBridgeXML>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub dns: Option<NetworkDNSXML>,
|
pub dns: Option<NetworkDNSXML>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub domain: Option<NetworkDomainXML>,
|
pub domain: Option<NetworkDomainXML>,
|
||||||
|
@ -4,9 +4,10 @@ use crate::libvirt_lib_structures::{
|
|||||||
DevicesXML, DiskBootXML, DiskDriverXML, DiskReadOnlyXML, DiskSourceXML, DiskTargetXML, DiskXML,
|
DevicesXML, DiskBootXML, DiskDriverXML, DiskReadOnlyXML, DiskSourceXML, DiskTargetXML, DiskXML,
|
||||||
DomainCPUTopology, DomainCPUXML, DomainInputXML, DomainMemoryXML, DomainNetInterfaceXML,
|
DomainCPUTopology, DomainCPUXML, DomainInputXML, DomainMemoryXML, DomainNetInterfaceXML,
|
||||||
DomainVCPUXML, DomainXML, FeaturesXML, GraphicsXML, NetIntSourceXML, NetMacAddress,
|
DomainVCPUXML, DomainXML, FeaturesXML, GraphicsXML, NetIntSourceXML, NetMacAddress,
|
||||||
NetworkDHCPHostXML, NetworkDHCPRangeXML, NetworkDHCPXML, NetworkDNSForwarderXML, NetworkDNSXML,
|
NetworkBridgeXML, NetworkDHCPHostXML, NetworkDHCPRangeXML, NetworkDHCPXML,
|
||||||
NetworkDomainXML, NetworkForwardXML, NetworkIPXML, NetworkXML, OSLoaderXML, OSTypeXML,
|
NetworkDNSForwarderXML, NetworkDNSXML, NetworkDomainXML, NetworkForwardXML, NetworkIPXML,
|
||||||
TPMBackendXML, TPMDeviceXML, VideoModelXML, VideoXML, XMLUuid, ACPIXML, OSXML,
|
NetworkXML, OSLoaderXML, OSTypeXML, TPMBackendXML, TPMDeviceXML, VideoModelXML, VideoXML,
|
||||||
|
XMLUuid, ACPIXML, OSXML,
|
||||||
};
|
};
|
||||||
use crate::libvirt_rest_structures::LibVirtStructError::StructureExtraction;
|
use crate::libvirt_rest_structures::LibVirtStructError::StructureExtraction;
|
||||||
use crate::utils::disks_utils::Disk;
|
use crate::utils::disks_utils::Disk;
|
||||||
@ -492,6 +493,7 @@ pub struct NetworkInfo {
|
|||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
forward_mode: NetworkForwardMode,
|
forward_mode: NetworkForwardMode,
|
||||||
device: Option<String>,
|
device: Option<String>,
|
||||||
|
bridge_name: Option<String>,
|
||||||
dns_server: Option<Ipv4Addr>,
|
dns_server: Option<Ipv4Addr>,
|
||||||
domain: Option<String>,
|
domain: Option<String>,
|
||||||
ip_v4: Option<IPV4Config>,
|
ip_v4: Option<IPV4Config>,
|
||||||
@ -516,6 +518,12 @@ impl NetworkInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(bridge) = &self.bridge_name {
|
||||||
|
if !regex!("^[a-zA-Z0-9]+$").is_match(bridge) {
|
||||||
|
return Err(StructureExtraction("Network bridge name is invalid!").into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(domain) = &self.domain {
|
if let Some(domain) = &self.domain {
|
||||||
if !regex!("^[a-zA-Z0-9.]+$").is_match(domain) {
|
if !regex!("^[a-zA-Z0-9.]+$").is_match(domain) {
|
||||||
return Err(StructureExtraction("Domain name is invalid!").into());
|
return Err(StructureExtraction("Domain name is invalid!").into());
|
||||||
@ -594,6 +602,9 @@ impl NetworkInfo {
|
|||||||
}),
|
}),
|
||||||
NetworkForwardMode::Isolated => None,
|
NetworkForwardMode::Isolated => None,
|
||||||
},
|
},
|
||||||
|
bridge: self.bridge_name.map(|b| NetworkBridgeXML {
|
||||||
|
name: b.to_string(),
|
||||||
|
}),
|
||||||
dns: self.dns_server.map(|addr| NetworkDNSXML {
|
dns: self.dns_server.map(|addr| NetworkDNSXML {
|
||||||
forwarder: NetworkDNSForwarderXML { addr },
|
forwarder: NetworkDNSForwarderXML { addr },
|
||||||
}),
|
}),
|
||||||
@ -619,6 +630,7 @@ impl NetworkInfo {
|
|||||||
false => Some(f.dev),
|
false => Some(f.dev),
|
||||||
})
|
})
|
||||||
.unwrap_or(None),
|
.unwrap_or(None),
|
||||||
|
bridge_name: xml.bridge.map(|b| b.name),
|
||||||
dns_server: xml.dns.map(|d| d.forwarder.addr),
|
dns_server: xml.dns.map(|d| d.forwarder.addr),
|
||||||
domain: xml.domain.map(|d| d.name),
|
domain: xml.domain.map(|d| d.name),
|
||||||
ip_v4: xml
|
ip_v4: xml
|
||||||
|
@ -26,6 +26,7 @@ export interface NetworkInfo {
|
|||||||
description?: string;
|
description?: string;
|
||||||
forward_mode: "NAT" | "Isolated";
|
forward_mode: "NAT" | "Isolated";
|
||||||
device?: string;
|
device?: string;
|
||||||
|
bridge_name?: string;
|
||||||
dns_server?: string;
|
dns_server?: string;
|
||||||
domain?: string;
|
domain?: string;
|
||||||
ip_v4?: IpConfig;
|
ip_v4?: IpConfig;
|
||||||
|
@ -128,6 +128,17 @@ function NetworkDetailsInner(
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<TextInput
|
||||||
|
editable={p.editable}
|
||||||
|
label="Network bridge name"
|
||||||
|
onValueChange={(v) => {
|
||||||
|
p.net.bridge_name = v;
|
||||||
|
p.onChange?.();
|
||||||
|
}}
|
||||||
|
value={p.net.bridge_name}
|
||||||
|
checkValue={(v) => v === "" || /^[a-zA-Z0-9]+$/.test(v)}
|
||||||
|
/>
|
||||||
|
|
||||||
<IPInput
|
<IPInput
|
||||||
editable={p.editable}
|
editable={p.editable}
|
||||||
label="DNS server to use"
|
label="DNS server to use"
|
||||||
|
Loading…
Reference in New Issue
Block a user