Commit 87b92d55 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

SlapBuilder can modify .vmdk Files

The binary "vmware-mount" has to be installed on the computer
option --virtual must be use with slapbuilder
parent bcf3c298
...@@ -102,7 +102,9 @@ class Parser(OptionParser): ...@@ -102,7 +102,9 @@ class Parser(OptionParser):
Option(None, "--no_usb", default=False, action="store_true", Option(None, "--no_usb", default=False, action="store_true",
help="Do not write on USB."), help="Do not write on USB."),
Option(None, "--one_disk",default=False, action="store_true", Option(None, "--one_disk",default=False, action="store_true",
help="Prepare image for one disk usage") help="Prepare image for one disk usage"),
Option(None, "--virtual",default=False, action="store_true",
help="Work with .vmdk files")
]) ])
def check_args(self): def check_args(self):
...@@ -145,19 +147,26 @@ def run(config): ...@@ -145,19 +147,26 @@ def run(config):
mount_dir_path = "/tmp/a_generated_directory" mount_dir_path = "/tmp/a_generated_directory"
fdisk_output_path = "/tmp/a_generated_file" fdisk_output_path = "/tmp/a_generated_file"
try: try:
offset = 0 if not config.virtual:
fdisk_output_file = open(fdisk_output_path, 'w') offset = 0
_call(['sfdisk', '-d', '-uS', config.system_path], stdout=fdisk_output_file) fdisk_output_file = open(fdisk_output_path, 'w')
fdisk_output_file.close() _call(['sfdisk', '-d', '-uS', config.system_path], stdout=fdisk_output_file)
fdisk_output_file = open(fdisk_output_path, 'r') fdisk_output_file.close()
for line in fdisk_output_file: fdisk_output_file = open(fdisk_output_path, 'r')
line = line.rstrip().replace(' ', '') for line in fdisk_output_file:
if line.endswith("bootable"): line = line.rstrip().replace(' ', '')
offset = int(line.split(':')[1].split(',')[0].split('=')[1]) if line.endswith("bootable"):
fdisk_output_file.close() offset = int(line.split(':')[1].split(',')[0].split('=')[1])
offset = offset * 512 fdisk_output_file.close()
_call(['mount', '-o', 'loop,offset=%i' % offset, config.system_path, offset = offset * 512
mount_dir_path], dry_run=dry_run) _call(['mount', '-o', 'loop,offset=%i' % offset, config.system_path,
mount_dir_path], dry_run=dry_run)
# Call vmware-mount to mount Virtual disk image
else:
print "Mount Virtual Image"
fdisk_output_file = open(fdisk_output_path, 'w')
_call(['vmware-mount', config.system_path, mount_dir_path], dry_run=dry_run )
try: try:
# Create slapos configuration directory if needed # Create slapos configuration directory if needed
slap_configuration_directory = os.path.normpath('/'.join([mount_dir_path, slap_configuration_directory = os.path.normpath('/'.join([mount_dir_path,
...@@ -294,16 +303,21 @@ def run(config): ...@@ -294,16 +303,21 @@ def run(config):
finally: finally:
_call(['umount', mount_dir_path], dry_run=dry_run) if not config.virtual:
_call(['umount', mount_dir_path], dry_run=dry_run)
else:
print "Umount Virtual Machine"
_call(["vmware-mount","-x"],dry_run=dry_run)
finally: finally:
# Always delete temporary directory # Always delete temporary directory
#print "No deleting"
print "Deleting temp directory: %s" % mount_dir_path print "Deleting temp directory: %s" % mount_dir_path
if not dry_run: if not dry_run:
shutil.rmtree(mount_dir_path) shutil.rmtree(mount_dir_path)
print "Deleting temp file: %s" % fdisk_output_path print "Deleting temp file: %s" % fdisk_output_path
if not dry_run: if not dry_run:
os.remove(fdisk_output_path) os.remove(fdisk_output_path)
# Copying # Copying
if not config.no_usb: if not config.no_usb:
print "\nStarting the copy of the raw file, it may take some time...\n" print "\nStarting the copy of the raw file, it may take some time...\n"
...@@ -356,5 +370,6 @@ def main(): ...@@ -356,5 +370,6 @@ def main():
# Catch exception raise by optparse # Catch exception raise by optparse
return_code = err return_code = err
sys.exit(return_code) sys.exit(return_code)
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