New vhost network for both containers and VMs

User can enable / disable bridging to change network behavior.
Containers and VMs are automatically updated to the new network settings
This commit is contained in:
bergware
2023-08-09 19:36:00 +02:00
parent a734929342
commit f8d6560b79
7 changed files with 146 additions and 74 deletions
@@ -661,23 +661,36 @@
$netmodel = $nic['model'] ?: 'virtio-net';
$net_res =$this->libvirt_get_net_res($this->conn, $nic['network']);
exec("brctl show | cut -f1| awk NF | sed -n '1!p'", $br);
$vhost = file_exists("/boot/config/network.cfg") && exec("grep -Po '^BRNICS\[0\]=\"\K[^\"]+' /boot/config/network.cfg")=='';
if ($vhost) {
exec("ip -br a|grep -Po '^vhost[0-9][^@]*'",$br);
} else {
exec("brctl show | cut -f1| awk NF | sed -n '1!p'", $br);
}
if ($nic["boot"] != NULL) $nicboot = "<boot order='".$nic["boot"]."'/>" ; else $nicboot = "" ;
if($net_res) {
$netstr .= "<interface type='network'>
$netstr .= "<interface type='network'>
<mac address='{$nic['mac']}'/>
<source network='" . htmlspecialchars($nic['network'], ENT_QUOTES | ENT_XML1) . "'/>
<model type='$netmodel'/>
$nicboot
</interface>" ;
</interface>";
} elseif(in_array($nic['network'], $br)) {
$netstr .= "<interface type='bridge'>
if ($vhost) {
$netstr .= "<interface type='direct'>
<mac address='{$nic['mac']}'/>
<source dev='" . htmlspecialchars($nic['network'], ENT_QUOTES | ENT_XML1) . "' mode='bridge'/>
<model type='$netmodel'/>
$nicboot
</interface>";
} else {
$netstr .= "<interface type='bridge'>
<mac address='{$nic['mac']}'/>
<source bridge='" . htmlspecialchars($nic['network'], ENT_QUOTES | ENT_XML1) . "'/>
<model type='$netmodel'/>
$nicboot
</interface>";
}
} else {
continue;
}