【问题标题】:QEMU-KVM automatically set filterref parameterQEMU-KVM 自动设置 filterref 参数
【发布时间】:2021-05-13 03:39:07
【问题描述】:

如果这是一个简单的问题,我很抱歉,但我刚开始使用 qemu,找不到简单的方法。

我正在尝试在某种程度上自动化我的 KVM 部署。我目前遇到的问题是我找不到自动为 filterref 设置参数的方法。

这就是我的 virt-install 网络选项目前的样子,并且目前运行良好。

--network type=bridge,network=default,bridge=bridge0,model=e1000e,mac=$mac,filterref=clean-traffic

但是我找不到任何东西来设置参数来定义它应该被锁定到的 IP 地址。这是我在 xml 中想要的结果:

<filterref filter='clean-traffic'>
  <parameter name='IP' value='XXX.XXX.XXX.XXX'/>
</filterref>

我正在寻找一种自动添加该参数的方法,最好是直接使用virt-install,或者在某种程度上我可以运行一个脚本,输入我想要设置的几个变量。此时,VM 已经在运行并等待设置完成,并加载了过滤器。基本上我希望在第一次启动之前加载参数,这样就没有人试图弄乱ip地址。

这可能吗?

这是我刚才复制到控制台的整个“脚本”。

name=WindowsTest
mac=00:50:56:00:05:C5
size=70
ram=6000
vcpus=6
let cores=vcpus/2

virt-install \
    --name=$name \
    --ram=$ram \
    --cpu=host \
    --vcpus=$vcpus,maxvcpus=$vcpus,sockets=1,cores=$cores,threads=2 \
    --os-type=windows \
    --os-variant=win10 \
    --disk path=/var/lib/libvirt/clutchImages/$name.qcow2,size=$size,format=qcow2,bus=virtio \
    --cdrom /var/isos/Windows_20H2_English.iso \
    --disk /var/isos/virtio-win-0.1.185.iso,device=cdrom \
    --network type=bridge,network=default,bridge=bridge0,model=e1000e,mac=$mac,filterref=clean-traffic  \
    --graphics spice,listen=157.90.2.208  \
    --graphics vnc

virsh 版本输出:

   virsh version
    Compiled against library: libvirt 6.0.0
    Using library: libvirt 6.0.0
    Using API: QEMU 6.0.0
    Running hypervisor: QEMU 4.2.0

我使用的是 CentOS Linux 版本 8.3.2011。

【问题讨论】:

    标签: qemu libvirt centos8 virsh


    【解决方案1】:

    又快又脏

    name=WindowsTest
    mac=00:50:56:00:05:C5
    IP=xxx.yyy.zzz.qqq
    size=70
    ram=6000
    vcpus=6
    let cores=vcpus/2
    
    virt-install \
        --name=$name \
        --ram=$ram \
        --cpu=host \
        --vcpus=$vcpus,maxvcpus=$vcpus,sockets=1,cores=$cores,threads=2 \
        --os-type=windows \
        --os-variant=win10 \
        --disk path=/var/lib/libvirt/clutchImages/$name.qcow2,size=$size,format=qcow2,bus=virtio \
        --cdrom /var/isos/Windows_20H2_English.iso \
        --disk /var/isos/virtio-win-0.1.185.iso,device=cdrom \
        --network type=bridge,network=default,bridge=bridge0,model=e1000e,mac=$mac,filterref=clean-traffic  \
        --graphics spice,listen=157.90.2.208  \
        --graphics vnc
        --print-xml  > /tmp/{$name}.xml  && \ 
    sed -i "s/<filterref.*/<filterref filter='clean-traffic'>\n <parameter name='IP' value='${IP}'\/>\n <\/filterref>/g" /tmp/{$name}.xml &&  \
    virsh create /tmp/{$name}.xml
    

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-24
    • 2015-12-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    相关资源
    最近更新 更多