1
0
mirror of https://github.com/gryf/boxpy.git synced 2025-12-19 05:30:18 +01:00

Added new option for disabling nested virtualization.

By default, nested virtualization is enabled. It can be disabled by
passing --disable-nested.
This commit is contained in:
2021-08-13 11:12:12 +02:00
parent 635917faf2
commit 03b21369e3
2 changed files with 20 additions and 7 deletions

View File

@@ -98,8 +98,8 @@ Currently, following commands are available:
- ``ssh`` - connect to the VM using ssh
- ``completion`` - as described above
All of the commands have a range of options, and can be examined it by using
``--help``.
All of the commands have a range of options, and can be examined by using
``--help`` option.
What is more interesting though, is the fact, that you can pass your own
`cloud-init`_ yaml file, so that VM can be provisioned in easy way.

23
box.py
View File

@@ -133,8 +133,8 @@ _boxpy() {
fi
;;
create|rebuild)
items=(--cpus --disk-size --distro --forwarding --key --memory
--hostname --port --config --version)
items=(--cpus --disable-nested --disk-size --distro --forwarding
--key --memory --hostname --port --config --version)
if [[ ${prev} == ${cmd} ]]; then
if [[ ${cmd} = "rebuild" ]]; then
_vms_comp vms
@@ -332,14 +332,16 @@ class FakeLogger:
class Config:
ATTRS = ('cpus', 'config', 'creator', 'disk_size', 'distro', 'forwarding',
'hostname', 'key', 'memory', 'name', 'port', 'version')
ATTRS = ('cpus', 'config', 'creator', 'disable_nested', 'disk_size',
'distro', 'forwarding', 'hostname', 'key', 'memory', 'name',
'port', 'version')
def __init__(self, args, vbox=None):
self.advanced = None
self.distro = None
self.cpus = None
self.creator = None
self.disable_nested = 'False'
self.disk_size = None
self.forwarding = {}
self.hostname = None
@@ -686,6 +688,13 @@ class VBoxManage:
LOG.fatal(f'Cannot modify VM "{self.name_or_uuid}"')
raise BoxVBoxFailure()
if conf.disable_nested == 'False':
if Run(['vboxmanage', 'modifyvm', self.name_or_uuid,
'--nested-hw-virt', 'on']).returncode != 0:
LOG.fatal(f'Cannot set nested virtualization for VM '
f'"{self.name_or_uuid}"')
raise BoxVBoxFailure()
return self.uuid
def convertfromraw(self, src, dst):
@@ -1069,7 +1078,7 @@ def vmcreate(args, conf=None):
if not vbox.create_controller('SATA', 'sata'):
return 4
for key in ('distro', 'key', 'hostname', 'version'):
for key in ('distro', 'hostname', 'key', 'version'):
if not vbox.setextradata(key, getattr(conf, key)):
return 5
@@ -1315,6 +1324,8 @@ def main():
help="VM hostname. Default same as vm name")
create.add_argument('-p', '--port', help="set ssh port for VM, default "
"random port from range 2000-2999")
create.add_argument('-r', '--disable-nested', action='store_true',
help="disable nested virtualization")
create.add_argument('-s', '--disk-size', help="disk size to be expanded "
"to. By default to 10GB")
create.add_argument('-u', '--cpus', type=int, help="amount of CPUs to be "
@@ -1353,6 +1364,8 @@ def main():
'Megabytes')
rebuild.add_argument('-n', '--hostname', help="set VM hostname")
rebuild.add_argument('-p', '--port', help="set ssh port for VM")
rebuild.add_argument('-r', '--disable-nested', action="store_true",
help="disable nested virtualization")
rebuild.add_argument('-s', '--disk-size',
help='disk size to be expanded to')
rebuild.add_argument('-u', '--cpus', type=int,