On Fri, Mar 19, 2021 at 09:13:50AM +0800, Liu Shaofei wrote:
On Thu, Mar 18, 2021 at 04:01:37PM +0800, Wang Chenglong wrote:
[How] Use the 'nr_nic' to set the number of network cards in yaml.
nr_nic: 2
root@vm-2p8g ~# ifconfig enp0s1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.18.42.60 netmask 255.255.0.0 broadcast 172.18.255.255 inet6 fe80::843:24ff:fef2:ec17 prefixlen 64 scopeid 0x20<link> ether 0a:43:24:f2:ec:17 txqueuelen 1000 (Ethernet) RX packets 155492 bytes 1172898602 (1.0 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 75 bytes 11207 (10.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.18.88.228 netmask 255.255.0.0 broadcast 172.18.255.255 inet6 fe80::820:70ff:fe34:d27b prefixlen 64 scopeid 0x20<link> ether 0a:20:70:34:d2:7b txqueuelen 1000 (Ethernet) RX packets 168 bytes 9079 (8.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 199208 bytes 32959935 (31.4 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Signed-off-by: Wang Chenglong 18509160991@163.com
providers/qemu/kvm.sh | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-)
diff --git a/providers/qemu/kvm.sh b/providers/qemu/kvm.sh index dcab81a..bbd5cd5 100755 --- a/providers/qemu/kvm.sh +++ b/providers/qemu/kvm.sh @@ -119,9 +119,35 @@ add_disk() done }
+set_mac() +{
- job_id=$(cat ipxe_script|awk -F'/' '/job_initrd_tmpfs/{print $(NF-1)}')
- if [ $(command -v es-find) ]; then
nr_nic=$(es-find id=$job_id | awk '/nr_nic/{print $2}' | tr -d ,)
- else
echo "command not found: es-find. set nr_nic=1"
sleep 1
- fi
- mac_arr[1]=$mac
- nr_nic=${nr_nic:-1}
- if [ "$nr_nic" -ge "2" ]; then
for i in $(seq 2 $nr_nic)
do
mac=$(echo $hostname$i | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/0a-\1-\2-\3-\4-\5/')
mac_arr[$i]=$mac
done
- fi
don't nested 'for' inside 'if': [ "$nr_nic" -ge "2" ] || return for i in $(..) ....
Ok. i got it.
Thanks, Chenglong
Thanks, Liushaofei
+}
set_nic() {
nic="tap,model=virtio-net-pci,helper=$helper,br=br0,mac=${mac}"
for i in $(seq 1 $nr_nic)
do
nic[$i]="-nic tap,model=virtio-net-pci,helper=$helper,br=br0,mac=${mac_arr[$i]}"
done
}
set_device() @@ -190,7 +216,7 @@ individual_option() -machine virt-4.0,accel=kvm,gic-version=3 -cpu Kunpeng-920 -bios $bios
-nic $nic
qemu-kvm)${nic[@]} ) ;;
@@ -198,17 +224,17 @@ individual_option() -machine virt-4.0,accel=kvm,gic-version=3 -cpu Kunpeng-920 -bios $bios
-nic $nic
${nic[@]} ) [ "$(arch)" == "x86_64" ] && arch_option=( -bios $bios
-nic $nic
qemu-system-x86_64) arch_option=( -bios $bios${nic[@]} ) ;;
-nic $nic
qemu-system-riscv64)${nic[@]} ) ;;
@@ -234,6 +260,7 @@ set_options() { set_bios set_helper
- set_mac set_nic set_device set_netdev
-- 2.23.0