Commit d7dd6132 authored by Michael Pöhn's avatar Michael Pöhn

make --dry-run work without root

parent 6fe4010d
......@@ -136,7 +136,7 @@ def exec_vmdebootstrap(params, provider):
params['username'],
provider)
cmd = [shutil.which('vmdebootstrap'),
cmd = [shutil.which('vmdebootstrap') or 'vmdebootstrap',
'--grub',
'--image={}'.format(params['img_path_raw']),
'--size={}'.format(params['size']),
......@@ -155,16 +155,18 @@ def exec_vmdebootstrap(params, provider):
cmd += ['--verbose']
if provider == 'virtualbox':
cmd += ['--debootstrapopts=components=main,contrib']
if params['dry_run']:
cmd += ['--dry-run']
logging.debug('> {}'.format(' '.join(cmd)))
logging.info('running vmdebootstrap (please be patient, '
'this may take several minutes) ...')
subprocess.call(cmd)
if not params['dry_run']:
logging.info('running vmdebootstrap (please be patient, '
'this may take several minutes) ...')
subprocess.call(cmd)
else:
logging.info("(dry run) Skip bootstraping to Debian "
"to raw disk image.")
def libvirt_convert_raw_to_qcow2(params):
cmd = (shutil.which('qemu-img'),
cmd = (shutil.which('qemu-img') or 'qemu-img',
'convert',
'-f', 'raw',
'-O', 'qcow2',
......@@ -234,7 +236,7 @@ def get_resource_as_string(resource_name):
def vbox_convert_raw_to_vmdk(params):
cmd = (shutil.which('VBoxManage'),
cmd = (shutil.which('VBoxManage') or 'VBoxManage',
'convertfromraw',
params['img_path_raw'],
params['img_path_vmdk'],
......@@ -300,7 +302,7 @@ def vbox_package_box(params):
def main(provider='virtualbox', debver='jessie64',
verbose=False, dry_run=False):
if not os.geteuid() == 0:
if not os.geteuid() == 0 and not dry_run:
raise BaseboxException('This script requires super user privileges. '
'(Please use sudo or run as root.)')
......@@ -319,14 +321,14 @@ def main(provider='virtualbox', debver='jessie64',
"{supvers}".format(debver=debver,
supvers=supvers))
if not shutil.which('vmdebootstrap'):
if not shutil.which('vmdebootstrap') and not dry_run:
raise BaseboxException("Can not find 'vmdebootstrap' executable. "
"(Please install vmdebootstrap.)")
if provider == 'virtualbox':
if provider == 'virtualbox' and not dry_run:
if not shutil.which('VBoxManage'):
raise BaseboxException("Can not find 'VBoxManage' executable. "
"(Please install virtualbox.)")
elif provider == 'libvirt':
elif provider == 'libvirt' and not dry_run:
if not shutil.which('qemu-img'):
raise BaseboxException("Can not find 'qemu-img' executable. "
"(Please install qemu-utils.)")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment