- self._params.add('daemonize', '')
- self._params.add('nodefaults', '')
- self._params.add('name', 'vnf{qemu},debug-threads=on'.
- format(qemu=self._opt.get('qemu_id')))
- self._params.add('no-user-config', '')
- self._params.add('monitor', 'none')
- self._params.add('display', 'none')
- self._params.add('vga', 'none')
- self._params.add('enable-kvm', '')
- self._params.add('pidfile', '{pidfile}'.
- format(pidfile=self._temp.get('pidfile')))
- self._params.add('cpu', 'host')
- self._params.add('machine', 'pc,accel=kvm,usb=off,mem-merge=off')
- self._params.add('smp', '{smp},sockets=1,cores={smp},threads=1'.
- format(smp=self._opt.get('smp')))
- self._params.add('object',
- 'memory-backend-file,id=mem,size={mem}M,'
- 'mem-path=/dev/hugepages,share=on'.
- format(mem=self._opt.get('mem')))
- self._params.add('m', '{mem}M'.
- format(mem=self._opt.get('mem')))
- self._params.add('numa', 'node,memdev=mem')
- self._params.add('balloon', 'none')
-
- def add_nestedvm_params(self):
- """Set NestedVM QEMU parameters."""
- self._params.add('net', 'nic,macaddr=52:54:00:00:{qemu:02x}:ff'.
- format(qemu=self._opt.get('qemu_id')))
- self._params.add('net', 'user,hostfwd=tcp::{info[port]}-:22'.
- format(info=self._vm_info))
- # TODO: Remove try except after fully migrated to Bionic or
- # qemu_set_node is removed.
- try:
- locking = ',file.locking=off'\
- if self.qemu_version(version='2.10') else ''
- except AttributeError:
- locking = ''
- self._params.add('drive',
- 'file={img},format=raw,cache=none,if=virtio{locking}'.
- format(img=self._opt.get('img'), locking=locking))
- self._params.add('qmp', 'unix:{qmp},server,nowait'.
- format(qmp=self._temp.get('qmp')))
- self._params.add('chardev', 'socket,host=127.0.0.1,port={info[serial]},'
- 'id=gnc0,server,nowait'.format(info=self._vm_info))
- self._params.add('device', 'isa-serial,chardev=gnc0')
- self._params.add('chardev',
- 'socket,path={qga},server,nowait,id=qga0'.
- format(qga=self._temp.get('qga')))
- self._params.add('device', 'isa-serial,chardev=qga0')
+ mem_path = f"/dev/hugepages1G" \
+ if self._opt[u"page_size"] == u"1G" else u"/dev/hugepages"
+
+ 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,"
+ f"mem-path={mem_path},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
+ """
+ index = f"index={index}," if index else u""
+ self._params.add_with_value(
+ u"drive", f"file={drive_file},{index}media=cdrom"
+ )
+
+ def add_drive(self, drive_file, drive_format):
+ """Set drive with custom format.
+
+ :param drive_file: Path to drive image.
+ :param drive_format: Drive image format.
+ :type drive_file: str
+ :type drive_format: str
+ """
+ self._params.add_with_value(
+ u"drive", f"file={drive_file},format={drive_format},"
+ u"cache=none,if=virtio,file.locking=off"
+ )