mirror of
https://github.com/gryf/boxpy.git
synced 2025-12-19 21:47:59 +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:
@@ -98,8 +98,8 @@ Currently, following commands are available:
|
|||||||
- ``ssh`` - connect to the VM using ssh
|
- ``ssh`` - connect to the VM using ssh
|
||||||
- ``completion`` - as described above
|
- ``completion`` - as described above
|
||||||
|
|
||||||
All of the commands have a range of options, and can be examined it by using
|
All of the commands have a range of options, and can be examined by using
|
||||||
``--help``.
|
``--help`` option.
|
||||||
|
|
||||||
What is more interesting though, is the fact, that you can pass your own
|
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.
|
`cloud-init`_ yaml file, so that VM can be provisioned in easy way.
|
||||||
|
|||||||
23
box.py
23
box.py
@@ -133,8 +133,8 @@ _boxpy() {
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
create|rebuild)
|
create|rebuild)
|
||||||
items=(--cpus --disk-size --distro --forwarding --key --memory
|
items=(--cpus --disable-nested --disk-size --distro --forwarding
|
||||||
--hostname --port --config --version)
|
--key --memory --hostname --port --config --version)
|
||||||
if [[ ${prev} == ${cmd} ]]; then
|
if [[ ${prev} == ${cmd} ]]; then
|
||||||
if [[ ${cmd} = "rebuild" ]]; then
|
if [[ ${cmd} = "rebuild" ]]; then
|
||||||
_vms_comp vms
|
_vms_comp vms
|
||||||
@@ -332,14 +332,16 @@ class FakeLogger:
|
|||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
ATTRS = ('cpus', 'config', 'creator', 'disk_size', 'distro', 'forwarding',
|
ATTRS = ('cpus', 'config', 'creator', 'disable_nested', 'disk_size',
|
||||||
'hostname', 'key', 'memory', 'name', 'port', 'version')
|
'distro', 'forwarding', 'hostname', 'key', 'memory', 'name',
|
||||||
|
'port', 'version')
|
||||||
|
|
||||||
def __init__(self, args, vbox=None):
|
def __init__(self, args, vbox=None):
|
||||||
self.advanced = None
|
self.advanced = None
|
||||||
self.distro = None
|
self.distro = None
|
||||||
self.cpus = None
|
self.cpus = None
|
||||||
self.creator = None
|
self.creator = None
|
||||||
|
self.disable_nested = 'False'
|
||||||
self.disk_size = None
|
self.disk_size = None
|
||||||
self.forwarding = {}
|
self.forwarding = {}
|
||||||
self.hostname = None
|
self.hostname = None
|
||||||
@@ -686,6 +688,13 @@ class VBoxManage:
|
|||||||
LOG.fatal(f'Cannot modify VM "{self.name_or_uuid}"')
|
LOG.fatal(f'Cannot modify VM "{self.name_or_uuid}"')
|
||||||
raise BoxVBoxFailure()
|
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
|
return self.uuid
|
||||||
|
|
||||||
def convertfromraw(self, src, dst):
|
def convertfromraw(self, src, dst):
|
||||||
@@ -1069,7 +1078,7 @@ def vmcreate(args, conf=None):
|
|||||||
if not vbox.create_controller('SATA', 'sata'):
|
if not vbox.create_controller('SATA', 'sata'):
|
||||||
return 4
|
return 4
|
||||||
|
|
||||||
for key in ('distro', 'key', 'hostname', 'version'):
|
for key in ('distro', 'hostname', 'key', 'version'):
|
||||||
if not vbox.setextradata(key, getattr(conf, key)):
|
if not vbox.setextradata(key, getattr(conf, key)):
|
||||||
return 5
|
return 5
|
||||||
|
|
||||||
@@ -1315,6 +1324,8 @@ def main():
|
|||||||
help="VM hostname. Default same as vm name")
|
help="VM hostname. Default same as vm name")
|
||||||
create.add_argument('-p', '--port', help="set ssh port for VM, default "
|
create.add_argument('-p', '--port', help="set ssh port for VM, default "
|
||||||
"random port from range 2000-2999")
|
"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 "
|
create.add_argument('-s', '--disk-size', help="disk size to be expanded "
|
||||||
"to. By default to 10GB")
|
"to. By default to 10GB")
|
||||||
create.add_argument('-u', '--cpus', type=int, help="amount of CPUs to be "
|
create.add_argument('-u', '--cpus', type=int, help="amount of CPUs to be "
|
||||||
@@ -1353,6 +1364,8 @@ def main():
|
|||||||
'Megabytes')
|
'Megabytes')
|
||||||
rebuild.add_argument('-n', '--hostname', help="set VM hostname")
|
rebuild.add_argument('-n', '--hostname', help="set VM hostname")
|
||||||
rebuild.add_argument('-p', '--port', help="set ssh port for VM")
|
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',
|
rebuild.add_argument('-s', '--disk-size',
|
||||||
help='disk size to be expanded to')
|
help='disk size to be expanded to')
|
||||||
rebuild.add_argument('-u', '--cpus', type=int,
|
rebuild.add_argument('-u', '--cpus', type=int,
|
||||||
|
|||||||
Reference in New Issue
Block a user