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,6 +147,7 @@ def run(config): ...@@ -145,6 +147,7 @@ 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:
if not config.virtual:
offset = 0 offset = 0
fdisk_output_file = open(fdisk_output_path, 'w') fdisk_output_file = open(fdisk_output_path, 'w')
_call(['sfdisk', '-d', '-uS', config.system_path], stdout=fdisk_output_file) _call(['sfdisk', '-d', '-uS', config.system_path], stdout=fdisk_output_file)
...@@ -158,6 +161,12 @@ def run(config): ...@@ -158,6 +161,12 @@ def run(config):
offset = offset * 512 offset = offset * 512
_call(['mount', '-o', 'loop,offset=%i' % offset, config.system_path, _call(['mount', '-o', 'loop,offset=%i' % offset, config.system_path,
mount_dir_path], dry_run=dry_run) 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,9 +303,14 @@ def run(config): ...@@ -294,9 +303,14 @@ def run(config):
finally: finally:
if not config.virtual:
_call(['umount', mount_dir_path], dry_run=dry_run) _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)
...@@ -358,3 +372,4 @@ def main(): ...@@ -358,3 +372,4 @@ def main():
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