+ self._nic_id = 0
+ self._node = node
+ self._arch = Topology.get_node_arch(self._node)
+ self._opt = dict()
+
+ # Architecture specific options
+ if self._arch == u"aarch64":
+ self._opt[u"machine_args"] = \
+ u"virt,accel=kvm,usb=off,mem-merge=off,gic-version=3"
+ self._opt[u"console"] = u"ttyAMA0"
+ else:
+ self._opt[u"machine_args"] = u"pc,accel=kvm,usb=off,mem-merge=off"
+ self._opt[u"console"] = u"ttyS0"
+ self._testpmd_path = f"{Constants.QEMU_VM_DPDK}/build/app"
+ self._vm_info = {
+ u"host": node[u"host"],
+ u"type": NodeType.VM,
+ u"port": 10021 + qemu_id,
+ u"serial": 4555 + qemu_id,
+ u"username": 'testuser',
+ u"password": 'Csit1234',
+ u"interfaces": {},
+ }
+ if node[u"port"] != 22:
+ self._vm_info[u"host_port"] = node[u"port"]
+ self._vm_info[u"host_username"] = node[u"username"]
+ self._vm_info[u"host_password"] = node[u"password"]
+ # Input Options.
+ self._opt[u"qemu_id"] = qemu_id
+ self._opt[u"mem"] = int(mem)
+ self._opt[u"smp"] = int(smp)
+ self._opt[u"img"] = img
+ self._opt[u"vnf"] = vnf
+ # Temporary files.
+ self._temp = dict()
+ self._temp[u"log"] = f"/tmp/serial_{qemu_id}.log"
+ self._temp[u"pidfile"] = f"/run/qemu_{qemu_id}.pid"
+ if img == Constants.QEMU_VM_IMAGE:
+ self._temp[u"qmp"] = f"/run/qmp_{qemu_id}.sock"
+ self._temp[u"qga"] = f"/run/qga_{qemu_id}.sock"
+ elif img == Constants.QEMU_VM_KERNEL:
+ self._opt[u"img"], _ = exec_cmd_no_error(
+ node, f"ls -1 {Constants.QEMU_VM_KERNEL}* | tail -1",
+ message=u"Qemu Kernel VM image not found!"
+ )
+ self._temp[u"ini"] = f"/etc/vm_init_{qemu_id}.conf"
+ self._opt[u"initrd"], _ = exec_cmd_no_error(
+ node, f"ls -1 {Constants.QEMU_VM_KERNEL_INITRD}* | tail -1",
+ message=u"Qemu Kernel initrd image not found!"
+ )
+ else:
+ raise RuntimeError(f"QEMU: Unknown VM image option: {img}")
+ # Computed parameters for QEMU command line.
+ self._params = OptionString(prefix=u"-")
+
+ def add_default_params(self):
+ """Set default QEMU command line parameters."""
+ self._params.add(u"daemonize")
+ self._params.add(u"nodefaults")
+ self._params.add_with_value(
+ u"name", f"vnf{self._opt.get(u'qemu_id')},debug-threads=on"
+ )
+ self._params.add(u"no-user-config")
+ self._params.add(u"nographic")
+ self._params.add(u"enable-kvm")
+ self._params.add_with_value(u"pidfile", self._temp.get(u"pidfile"))
+ self._params.add_with_value(u"cpu", u"host")
+
+ self._params.add_with_value(u"machine", self._opt.get(u"machine_args"))
+ self._params.add_with_value(
+ u"smp", f"{self._opt.get(u'smp')},sockets=1,"
+ f"cores={self._opt.get(u'smp')},threads=1"
+ )
+ self._params.add_with_value(
+ u"object", f"memory-backend-file,id=mem,"
+ f"size={self._opt.get(u'mem')}M,mem-path=/dev/hugepages,share=on"
+ )
+ self._params.add_with_value(u"m", f"{self._opt.get(u'mem')}M")
+ self._params.add_with_value(u"numa", u"node,memdev=mem")
+
+ def add_net_user(self, net="10.0.2.0/24"):
+ """Set managment port forwarding."""
+ self._params.add_with_value(
+ u"netdev", f"user,id=mgmt,net={net},"
+ f"hostfwd=tcp::{self._vm_info[u'port']}-:22"
+ )
+ self._params.add_with_value(
+ u"device", f"virtio-net,netdev=mgmt"
+ )
+
+ def add_qmp_qga(self):
+ """Set QMP, QGA management."""
+ self._params.add_with_value(
+ u"chardev", f"socket,path={self._temp.get(u'qga')},"
+ f"server,nowait,id=qga0"
+ )
+ self._params.add_with_value(
+ u"device", u"isa-serial,chardev=qga0"
+ )
+ self._params.add_with_value(
+ u"qmp", f"unix:{self._temp.get(u'qmp')},server,nowait"
+ )
+
+ def add_serial(self):
+ """Set serial to file redirect."""
+ self._params.add_with_value(
+ u"chardev", f"socket,host=127.0.0.1,"
+ f"port={self._vm_info[u'serial']},id=gnc0,server,nowait"
+ )
+ self._params.add_with_value(
+ u"device", u"isa-serial,chardev=gnc0"
+ )
+ self._params.add_with_value(
+ u"serial", f"file:{self._temp.get(u'log')}"
+ )
+
+ def add_drive_cdrom(self, drive_file, index=None):
+ """Set CD-ROM drive.
+
+ :param drive_file: Path to drive image.
+ :param index: Drive index.
+ :type drive_file: str
+ :type index: int