Can change network interface type
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2025-05-30 20:30:30 +02:00
parent ef0d77f1d6
commit 22416badcf
3 changed files with 47 additions and 1 deletions

View File

@@ -29,6 +29,12 @@ pub enum VMArchitecture {
X86_64, X86_64,
} }
#[derive(serde::Serialize, serde::Deserialize)]
pub enum NetworkInterfaceModelType {
Virtio,
E1000,
}
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
pub struct NWFilterParam { pub struct NWFilterParam {
name: String, name: String,
@@ -46,6 +52,7 @@ pub struct Network {
#[serde(flatten)] #[serde(flatten)]
r#type: NetworkType, r#type: NetworkType,
mac: String, mac: String,
model: NetworkInterfaceModelType,
nwfilterref: Option<NWFilterRef>, nwfilterref: Option<NWFilterRef>,
} }
@@ -196,7 +203,11 @@ impl VMInfo {
}; };
let model = Some(NetIntModelXML { let model = Some(NetIntModelXML {
r#type: "virtio".to_string(), r#type: match n.model {
NetworkInterfaceModelType::Virtio => "virtio",
NetworkInterfaceModelType::E1000 => "e1000",
}
.to_string(),
}); });
let filterref = if let Some(n) = &n.nwfilterref { let filterref = if let Some(n) = &n.nwfilterref {
@@ -518,6 +529,18 @@ impl VMInfo {
))); )));
} }
}, },
model: match d.model.as_ref() {
None => NetworkInterfaceModelType::Virtio,
Some(model) => match model.r#type.as_str() {
"virtio" => NetworkInterfaceModelType::Virtio,
"e1000" => NetworkInterfaceModelType::E1000,
model => {
return Err(LibVirtStructError::DomainExtraction(format!(
"Unknown network interface model type: {model}! "
)));
}
},
},
nwfilterref: d.filterref.as_ref().map(|f| NWFilterRef { nwfilterref: d.filterref.as_ref().map(|f| NWFilterRef {
name: f.filter.to_string(), name: f.filter.to_string(),
parameters: f parameters: f

View File

@@ -60,6 +60,7 @@ export type VMNetInterface = (
export interface VMNetInterfaceBase { export interface VMNetInterfaceBase {
mac: string; mac: string;
model: "Virtio" | "E1000";
nwfilterref?: VMNetInterfaceFilter; nwfilterref?: VMNetInterfaceFilter;
} }

View File

@@ -35,6 +35,7 @@ export function VMNetworksList(p: {
const addNew = () => { const addNew = () => {
p.vm.networks.push({ p.vm.networks.push({
type: "UserspaceSLIRPStack", type: "UserspaceSLIRPStack",
model: "Virtio",
mac: randomMacAddress(ServerApi.Config.net_mac_prefix), mac: randomMacAddress(ServerApi.Config.net_mac_prefix),
}); });
p.onChange?.(); p.onChange?.();
@@ -146,6 +147,7 @@ function NetworkInfoWidget(p: {
/> />
</ListItem> </ListItem>
<div style={{ marginLeft: "70px" }}> <div style={{ marginLeft: "70px" }}>
{/* MAC address input */}
<MACInput <MACInput
editable={p.editable} editable={p.editable}
label="MAC Address" label="MAC Address"
@@ -156,6 +158,26 @@ function NetworkInfoWidget(p: {
}} }}
/> />
{/* NIC model */}
<SelectInput
editable={p.editable}
label="NIC Model"
value={p.network.model}
onValueChange={(v) => {
p.network.model = v as any;
p.onChange?.();
}}
options={[
{ label: "e1000", value: "E1000" },
{
label: "virtio",
value: "Virtio",
description:
"Recommended model, but will require specific drivers on OS that do not support it.",
},
]}
/>
{/* Defined network selection */} {/* Defined network selection */}
{p.network.type === "DefinedNetwork" && ( {p.network.type === "DefinedNetwork" && (
<SelectInput <SelectInput