def _get_stage_files(root_dir, distro): """ Stage 1 is located in the MBR and mainly points to Stage 2, since the MBR is too small to contain all of the needed data. Stage 2 points to its configuration file, which contains all of the complex user interface and options we are normally familiar with when talking about GRUB. Stage 2 can be located anywhere on the disk. If Stage 2 cannot find its configuration table, GRUB will cease the boot sequence and present the user with a command line for manual configuration. Stage 1.5 also exists and might be used if the boot information is small enough to fit in the area immediately after MBR. """ if distro == 'CentOS': run_command([ '/bin/bash', '-c', 'cp -f %s/extras/export/grub_files/centos/* %s/boot/grub/' % (settings.PROJECT_ROOT, root_dir) ]) elif distro == 'Ubuntu': run_command([ '/bin/bash', '-c', 'cp -f %s/extras/export/grub_files/ubuntu/* %s/boot/grub/' % (settings.PROJECT_ROOT, root_dir) ])
def _readd_atmo_boot(self, mount_point): #TODO: This function should no longer be necessary. #If it is, we need to recreate goodies/atmo_boot host_atmoboot = os.path.join(self.extras_root, 'extras/goodies/atmo_boot') atmo_boot_path = os.path.join(mount_point, 'usr/sbin/atmo_boot') run_command(['/bin/cp', '%s' % host_atmoboot, '%s' % atmo_boot_path])
def _rewrite_grub_conf(mount_point, distro): latest_rmdisk, rmdisk_version = get_latest_ramdisk(mount_point, distro) new_grub_conf = """default=0 timeout=3 splashimage=(hd0,0)/boot/grub/splash.xpm.gz title Atmosphere VM (%s) root (hd0,0) kernel /boot/vmlinuz-%s root=/dev/sda1 ro enforcing=0 initrd /boot/%s """ % (rmdisk_version, rmdisk_version, latest_rmdisk) with open(os.path.join(mount_point, 'boot/grub/grub.conf'), 'w') as grub_file: grub_file.write(new_grub_conf) run_command([ '/bin/bash', '-c', 'cd %s/boot/grub/;ln -s grub.conf grub.cfg' % mount_point ]) run_command([ '/bin/bash', '-c', 'cd %s/boot/grub/;ln -s grub.conf menu.lst' % mount_point ])
def remove_sensu(mounted_path): try: prepare_chroot_env(mounted_path) run_command(["/usr/sbin/chroot", mounted_path, 'yum', 'remove', '-qy', 'sensu']) finally: remove_chroot_env(mounted_path)
def _build_new_export_vm(self, name, harddrive_path, vm_opts={}, distro='Linux'): export_dir = os.path.dirname(harddrive_path) hostname_out, _ = run_command(['hostname']) export_file = os.path.join(export_dir,'%s_%s_%s.ova' % (name, hostname_out.strip(), timezone.now().strftime("%Y_%m_%d_%H_%M_%S"))) if os.path.exists(export_file): #Remove vm method here.. pass out, err = run_command(['VBoxManage','createvm','--basefolder', export_dir, '--name', name, '--ostype', distro, '--register']) vm_uuid = self._strip_uuid(out) modify_vm_opts = { 'vram':'16', # vram <= 8 MB causes poor performance.. 'memory':512, 'acpi': 'on', 'ioapic':'on' } modify_vm_opts.update(vm_opts) modify_vm_command = ['VBoxManage','modifyvm', vm_uuid] for (k,v) in modify_vm_opts.items(): modify_vm_command.append('--%s' % k) modify_vm_command.append('%s' % v) run_command(modify_vm_command) run_command(['VBoxManage', 'storagectl', vm_uuid, '--name', 'Hard Drive', '--add', 'sata', '--controller', 'IntelAHCI']) run_command(['VBoxManage', 'storageattach', vm_uuid, '--storagectl', 'Hard Drive', '--type', 'hdd', '--medium', harddrive_path, '--port','0','--device','0']) run_command(['VBoxManage', 'export', vm_uuid, '--output', export_file]) return export_file
def reset_root_password(mounted_path, new_password='******'): try: prepare_chroot_env(mounted_path) run_command(["/usr/sbin/chroot", mounted_path, "/bin/bash", "-c", "echo %s | passwd root --stdin" % new_password]) finally: remove_chroot_env(mounted_path)
def _prepare_kvm_export(self, image_path, download_dir): """ Prepare a KVM export (For OpenStack) Will also remove Euca-Specific files and add OS-Specific files """ (kernel_dir, ramdisk_dir, mount_point) = self._export_dirs(download_dir) #Labeling the image as 'root' allows for less reliance on UUID run_command(['e2label', image_path, 'root']) out, err = mount_image(image_path, mount_point) if err: raise Exception("Encountered errors mounting the image: %s" % err) xen_to_kvm_centos(mount_point) #Determine the latest (KVM) ramdisk to use latest_rmdisk, rmdisk_version = get_latest_ramdisk(mount_point) #Copy new kernel & ramdisk to the folder local_ramdisk_path = _copy_ramdisk(mount_point, rmdisk_version, ramdisk_dir) local_kernel_path = _copy_kernel(mount_point, rmdisk_version, kernel_dir) run_command(["umount", mount_point]) #Your new image is ready for upload to OpenStack return (image_path, local_kernel_path, local_ramdisk_path)
def rhel_chroot(cls, image_path, mounted_path): #Here is an example of how to run a command in chroot: #run_command(["/usr/sbin/chroot", mounted_path, "/bin/bash", "-c", # "./single/command.sh arg1 arg2 ..."]) run_command(["/usr/sbin/chroot", mounted_path, "/bin/bash", "-c", "yum install -qy kernel mkinitrd grub"]) pass
def debian_chroot(cls, image_path, mounted_path): #Here is an example of how to run a command in chroot: #run_command(["/usr/sbin/chroot", mounted_path, "/bin/bash", "-c", # "./single/command.sh arg1 arg2 ..."]) #Run this command in a prepared chroot run_command(["/usr/sbin/chroot", mounted_path, "/bin/bash", "-c", "apt-get install -qy linux-image initramfs-tools grub"]) pass
def rhel_chroot(cls, image_path, mounted_path): #Here is an example of how to run a command in chroot: #run_command(["/usr/sbin/chroot", mounted_path, "/bin/bash", "-c", # "./single/command.sh arg1 arg2 ..."]) run_command([ "/usr/sbin/chroot", mounted_path, "/bin/bash", "-c", "yum install -qy kernel mkinitrd grub" ]) pass
def debian_chroot(cls, image_path, mounted_path): #Here is an example of how to run a command in chroot: #run_command(["/usr/sbin/chroot", mounted_path, "/bin/bash", "-c", # "./single/command.sh arg1 arg2 ..."]) #Run this command in a prepared chroot run_command([ "/usr/sbin/chroot", mounted_path, "/bin/bash", "-c", "apt-get install -qy linux-image initramfs-tools grub" ]) pass
def mount_and_clean(image_path, mount_point, created_by=None, status_hook=None, method_hook=None, **kwargs): """ Clean the local image at <image_path> Mount it to <mount_point> """ #Prepare the paths if not os.path.exists(image_path): logger.error("Could not find local image!") raise Exception("Image file not found") if not os.path.exists(mount_point): os.makedirs(mount_point) #FSCK the image, FIRST! fsck_image(image_path) #Mount the directory #NOTE: the 'nbd_device' is not being properly passed through here. As a result, the FINAL umount does not use `qemu-nbd -d` result, nbd_device = mount_image(image_path, mount_point) if not result: raise Exception("Encountered errors mounting the image: %s" % image_path) if status_hook and hasattr(status_hook, 'on_update_status'): status_hook.on_update_status("mounted + cleaning image") try: #Required cleaning remove_user_data(mount_point, author=created_by) remove_atmo_data(mount_point) remove_vm_specific_data(mount_point) #Filesystem cleaning (From within the image) file_hook_cleaning(mount_point, **kwargs) #Driver specific cleaning if method_hook: method_hook(image_path, mount_point, **kwargs) #Required for atmosphere atmo_required_files(mount_point) #TODO: call `df -h <mount_point>` and record the `Use%` #TODO: IF `Use%` > 90%, set 'new_image=True' if status_hook and hasattr(status_hook, 'on_update_status'): status_hook.on_update_status("cleaning completed") except Exception as exc: if status_hook and hasattr(status_hook, 'on_update_status'): status_hook.on_update_status("cleaning failed - %s" % exc) finally: #Don't forget to unmount! run_command(['umount', '-lf', mount_point], check_return=True) if nbd_device: run_command(['qemu-nbd', '-d', nbd_device]) return True
def apt_install(mounted_path, install_list): distro = check_distro(mounted_path) try: prepare_chroot_env(mounted_path) for install_item in install_list: run_command([ "/usr/sbin/chroot", mounted_path, 'apt-get', '-qy', 'install', install_item ]) finally: remove_chroot_env(mounted_path)
def remove_vnc(mounted_path): try: prepare_chroot_env(mounted_path) run_command(["/usr/sbin/chroot", mounted_path, 'yum', 'remove', '-qy', 'realvnc-vnc-server']) #remove rpmsave.. to get rid of vnc for good. #["/usr/sbin/chroot", mounted_path, 'find', '/', #'-type', 'f', '-name', '*.rpmsave', '-exec', 'rm', '-f', #'{}', ';'] finally: remove_chroot_env(mounted_path)
def apt_uninstall(mounted_path, uninstall_list): distro = check_distro(mounted_path) if 'ubuntu' not in distro.lower(): return try: prepare_chroot_env(mounted_path) for uninstall_item in uninstall_list: run_command(["/usr/sbin/chroot", mounted_path, 'apt-get', '-qy', 'purge', uninstall_item]) finally: remove_chroot_env(mounted_path)
def _install_grub(image_path): fdisk_stats = fdisk_image(image_path) disk = fdisk_stats['disk'] grub_stdin = """device (hd0) %s geometry (hd0) %s %s %s root (hd0,0) setup (hd0) quit""" % (image_path, disk['cylinders'], disk['heads'], disk['sectors_per_track']) run_command(['grub', '--device-map=/dev/null', '--batch'], stdin=grub_stdin)
def _install_grub(image_path): fdisk_stats = fdisk_image(image_path) disk = fdisk_stats['disk'] grub_stdin = """device (hd0) %s geometry (hd0) %s %s %s root (hd0,0) setup (hd0) quit""" % (image_path, disk['cylinders'], disk['heads'], disk['sectors_per_track']) run_command( ['grub', '--device-map=/dev/null', '--batch'], stdin=grub_stdin)
def _get_stage_files(self, root_dir, distro): if distro == 'centos': run_command([ '/bin/bash', '-c', 'cp -f %s/extras/export/grub_files/centos/* %s/boot/grub/' % (self.extras_root, root_dir) ]) elif distro == 'ubuntu': run_command([ '/bin/bash', '-c', 'cp -f %s/extras/export/grub_files/ubuntu/* %s/boot/grub/' % (self.extras_root, root_dir) ])
def yum_uninstall(mounted_path, uninstall_list): distro = check_distro(mounted_path) if 'centos' not in distro.lower(): return try: prepare_chroot_env(mounted_path) for uninstall_item in uninstall_list: run_command([ "/usr/sbin/chroot", mounted_path, 'yum', '-qy', 'remove', uninstall_item ]) finally: remove_chroot_env(mounted_path)
def apt_uninstall(mounted_path, uninstall_list): distro = check_distro(mounted_path) if 'ubuntu' not in distro.lower(): return try: prepare_chroot_env(mounted_path) for uninstall_item in uninstall_list: run_command([ "/usr/sbin/chroot", mounted_path, 'apt-get', '-qy', 'purge', uninstall_item ]) finally: remove_chroot_env(mounted_path)
def mount_and_clean(self, image_path, mount_point, *args, **kwargs): """ Clean the local image at <image_path> Mount it to <mount_point> """ #Prepare the paths if not os.path.exists(image_path): logger.error("Could not find local image!") raise Exception("Image file not found") if not os.path.exists(mount_point): os.makedirs(mount_point) #FSCK the image, FIRST! fsck_image(image_path) #Mount the directory #NOTE: the 'nbd_device' is not being properly passed through here. As a result, the FINAL umount does not use `qemu-nbd -d` result, nbd_device = mount_image(image_path, mount_point) if getattr(self, 'hook') and hasattr(self.hook, 'on_update_status'): self.hook.on_update_status("mount + cleaning image") if not result: raise Exception("Encountered errors mounting the image: %s" % image_path) try: #Required cleaning remove_user_data(mount_point, author=kwargs.get('created_by')) remove_atmo_data(mount_point) remove_vm_specific_data(mount_point) #Filesystem cleaning (From within the image) self.file_hook_cleaning(mount_point, **kwargs) #Driver specific cleaning self.clean_hook(image_path, mount_point, *args, **kwargs) #Required for atmosphere atmo_required_files(mount_point) #TODO: call `df -h <mount_point>` and record the `Use%` #TODO: IF `Use%` > 90%, set 'new_image=True' finally: #Don't forget to unmount! run_command(['umount', mount_point]) if nbd_device: run_command(['qemu-nbd', '-d', nbd_device]) if getattr(self, 'hook') and hasattr(self.hook, 'on_update_status'): self.hook.on_update_status("cleaning completed") #TODO: If `new_image=True` # replace disk image location with the 'new, larger disk' return
def _get_stage_files(root_dir, distro): """ Stage 1 is located in the MBR and mainly points to Stage 2, since the MBR is too small to contain all of the needed data. Stage 2 points to its configuration file, which contains all of the complex user interface and options we are normally familiar with when talking about GRUB. Stage 2 can be located anywhere on the disk. If Stage 2 cannot find its configuration table, GRUB will cease the boot sequence and present the user with a command line for manual configuration. Stage 1.5 also exists and might be used if the boot information is small enough to fit in the area immediately after MBR. """ if distro == 'CentOS': run_command(['/bin/bash','-c','cp -f %s/extras/export/grub_files/centos/* %s/boot/grub/' % (settings.PROJECT_ROOT, root_dir)]) elif distro == 'Ubuntu': run_command(['/bin/bash','-c','cp -f %s/extras/export/grub_files/ubuntu/* %s/boot/grub/' % (settings.PROJECT_ROOT, root_dir)])
def _get_latest_ramdisk(self, mount_point): (output,stder) = run_command(["/usr/sbin/chroot", mount_point, "/bin/bash", "-c", "ls -Fah /boot/"]) latest_rmdisk = '' rmdisk_version = '' for line in output.split('\n'): if 'initrd' in line and 'xen' not in line: latest_rmdisk = line rmdisk_version = line.replace('.img','').replace('initrd-','') return latest_rmdisk, rmdisk_version
def _build_new_export_vm(self, name, harddrive_path, vm_opts={}, distro='Linux'): export_dir = os.path.dirname(harddrive_path) hostname_out, _ = run_command(['hostname']) export_file = os.path.join( export_dir, '%s_%s_%s.ova' % (name, hostname_out.strip(), timezone.now().strftime("%Y_%m_%d_%H_%M_%S"))) if os.path.exists(export_file): #Remove vm method here.. pass out, err = run_command([ 'VBoxManage', 'createvm', '--basefolder', export_dir, '--name', name, '--ostype', distro, '--register' ]) vm_uuid = self._strip_uuid(out) modify_vm_opts = { 'vram': '16', # vram <= 8 MB causes poor performance.. 'memory': 512, 'acpi': 'on', 'ioapic': 'on' } modify_vm_opts.update(vm_opts) modify_vm_command = ['VBoxManage', 'modifyvm', vm_uuid] for (k, v) in modify_vm_opts.items(): modify_vm_command.append('--%s' % k) modify_vm_command.append('%s' % v) run_command(modify_vm_command) run_command([ 'VBoxManage', 'storagectl', vm_uuid, '--name', 'Hard Drive', '--add', 'sata', '--controller', 'IntelAHCI' ]) run_command([ 'VBoxManage', 'storageattach', vm_uuid, '--storagectl', 'Hard Drive', '--type', 'hdd', '--medium', harddrive_path, '--port', '0', '--device', '0' ]) run_command(['VBoxManage', 'export', vm_uuid, '--output', export_file]) return export_file
def add_gnome_support(mounted_path): """ RHEL only at this point. TODO: Add ubuntu, then add deterine_distro code """ prepare_chroot_env(mounted_path) run_command([ "/usr/sbin/chroot", mounted_path, "/bin/bash", "-c", "yum groupinstall" " -y \"X Window System\" \"GNOME Desktop Environment\""]) #Selinux was enabled in the process. lets fix that: selinux_conf = os.path.join(mounted_path, 'etc/sysconfig/selinux') sed_replace("SELINUX=enforcing", "SELINUX=disabled", selinux_conf) remove_chroot_env(mounted_path) #Make it the default on boot replace_line_file_list = [ (":[0-6]:initdefault",":5:initdefault", "etc/inittab"), ] replace_line_in_files(replace_line_file_list, mounted_path)
def _rewrite_grub_conf(mount_point, distro): latest_rmdisk, rmdisk_version = get_latest_ramdisk(mount_point, distro) new_grub_conf = """default=0 timeout=3 splashimage=(hd0,0)/boot/grub/splash.xpm.gz title Atmosphere VM (%s) root (hd0,0) kernel /boot/vmlinuz-%s root=/dev/sda1 ro enforcing=0 initrd /boot/%s """ % (rmdisk_version, rmdisk_version, latest_rmdisk) with open(os.path.join( mount_point,'boot/grub/grub.conf'), 'w') as grub_file: grub_file.write(new_grub_conf) run_command(['/bin/bash','-c', 'cd %s/boot/grub/;ln -s grub.conf grub.cfg' % mount_point]) run_command(['/bin/bash','-c', 'cd %s/boot/grub/;ln -s grub.conf menu.lst' % mount_point])
def convert(cls, image_path, upload_dir): (kernel_dir, ramdisk_dir, mount_point) = build_imaging_dirs(upload_dir, full_image=True) apply_label(image_path, label='root') # TODO: Is this necessary? try: out, err = mount_image(image_path, mount_point) if err: raise Exception("Encountered errors mounting image:%s" % err) #Our mount_point is in use, the image is mounted at this path mounted_path = mount_point distro = check_distro(mounted_path) #Hooks for debian/rhel specific cleaning commands if distro == 'ubuntu': cls.debian_mount(image_path, mount_point) elif distro == 'centos': cls.rhel_mount(image_path, mount_point) try: prepare_chroot_env(mounted_path) #Hooks for debian/rhel specific chroot commands if distro == 'ubuntu': cls.debian_chroot(image_path, mount_point) elif distro == 'centos': cls.rhel_chroot(image_path, mount_point) finally: remove_chroot_env(mounted_path) (kernel_path, ramdisk_path) = cls.get_kernel_ramdisk(mount_point, kernel_dir, ramdisk_dir) #Use the image, kernel, and ramdisk paths #to initialize any driver that implements 'upload_full_image' return (image_path, kernel_path, ramdisk_path) finally: run_command(["umount", mount_point])
def mount_and_clean(self, image_path, mount_point, *args, **kwargs): """ Clean the local image at <image_path> Mount it to <mount_point> """ #Prepare the paths if not os.path.exists(image_path): logger.error("Could not find local image!") raise Exception("Image file not found") if not os.path.exists(mount_point): os.makedirs(mount_point) #FSCK the image, FIRST! fsck_image(image_path) #Mount the directory result, nbd_device = mount_image(image_path, mount_point) if not result: raise Exception("Encountered errors mounting the image: %s" % image_path) try: #Required cleaning remove_user_data(mount_point) remove_atmo_data(mount_point) remove_vm_specific_data(mount_point) #Filesystem cleaning (From within the image) self.file_hook_cleaning(mount_point, **kwargs) #Driver specific cleaning self.clean_hook(image_path, mount_point, *args, **kwargs) #Required for atmosphere atmo_required_files(mount_point) finally: #Don't forget to unmount! run_command(['umount', mount_point]) if nbd_device: run_command(['qemu-nbd', '-d', nbd_device]) return
def _read_file_type(self, local_image): out, _ = run_command(['file', local_image]) logger.info("FileOutput: %s" % out) if 'qemu qcow' in out.lower(): if 'v2' in out.lower(): return 'qcow2' else: return 'qcow' elif 'Linux rev 1.0' in out.lower() and 'ext' in out.lower(): return 'img' else: raise Exception("Could not guess the type of file. Output=%s" % out)
def file_hook_cleaning(self, mounted_path, **kwargs): """ Look for a 'file_hook' on the actual filesystem (Mounted at mounted_path) If it exists, prepare a chroot and execute the file """ #File hooks inside the local image clean_filename = kwargs.get('file_hook',"/etc/chromogenic/clean") #Ignore the lead / when doing path.join not_root_filename = clean_filename[1:] mounted_clean_path = os.path.join(mounted_path,not_root_filename) if not os.path.exists(mounted_clean_path): return False try: prepare_chroot_env(mounted_path) #Run this command in a prepared chroot run_command( ["/usr/sbin/chroot", mounted_path, "/bin/bash", "-c", clean_filename]) except Exception, e: logger.exception(e) return False
def file_hook_cleaning(mounted_path, **kwargs): """ Look for a 'file_hook' on the actual filesystem (Mounted at mounted_path) If it exists, prepare a chroot and execute the file """ #File hooks inside the local image clean_filename = kwargs.get('file_hook', "/etc/chromogenic/clean") #Ignore the lead / when doing path.join not_root_filename = clean_filename[1:] mounted_clean_path = os.path.join(mounted_path, not_root_filename) if not os.path.exists(mounted_clean_path): return False try: prepare_chroot_env(mounted_path) #Run this command in a prepared chroot run_command([ "/usr/sbin/chroot", mounted_path, "/bin/bash", "-c", clean_filename ]) except Exception, e: logger.exception(e) return False
def scp_remote_file(self, remote_path=None, local_path=None, user='******', hostname='localhost', port=22, check_key=False, private_key=None): """ Build up the SCP command based on arguments """ # This SSH key file may be used and will self-destruct after scp is complete ssh_file_loc = '/tmp/_chromo_tmp_ssh.key' try: if local_path: if os.path.exists(local_path): logger.info( "SCP Remote file canceled. Local file <%s> exists!" % local_path) return local_path scp_command_list = ['scp'] if not check_key: scp_command_list.extend(['-o', 'stricthostkeychecking=no']) if private_key: #SCP the file if an SSH Key has been added! with open(ssh_file_loc, 'w') as ssh_key_file: run_command(['echo', private_key], stdout=ssh_key_file) #run_command(['whoami']) # - Useful when debugging ssh problems # SSH keys require specific permissions run_command(['chmod', '600', ssh_file_loc]) scp_command_list.extend(['-i', ssh_file_loc]) if port != 22: scp_command_list.extend(['-P%s' % port]) scp_command_list.extend( ['%s@%s:%s' % (user, hostname, remote_path)]) #Where should the file go scp_command_list.extend([local_path]) #Print and execute logger.info("Downloading image: <%s>" % (' '.join(map(str, scp_command_list)), )) run_command(scp_command_list) return local_path finally: if private_key: run_command(['rm', '-rf', ssh_file_loc])
def scp_remote_file(self, remote_path=None, local_path=None, user='******', hostname='localhost', port=22, check_key=False, private_key=None): """ Build up the SCP command based on arguments """ # This SSH key file may be used and will self-destruct after scp is complete ssh_file_loc = '/tmp/_chromo_tmp_ssh.key' try: if local_path: if os.path.exists(local_path): logger.info("SCP Remote file canceled. Local file <%s> exists!" % local_path) return local_path scp_command_list = ['scp'] if not check_key: scp_command_list.extend(['-o', 'stricthostkeychecking=no']) if private_key: #SCP the file if an SSH Key has been added! with open(ssh_file_loc, 'w') as ssh_key_file: run_command(['echo', private_key], stdout=ssh_key_file) #run_command(['whoami']) # - Useful when debugging ssh problems # SSH keys require specific permissions run_command(['chmod', '600', ssh_file_loc]) scp_command_list.extend(['-i', ssh_file_loc]) if port != 22: scp_command_list.extend(['-P%s' % port]) scp_command_list.extend(['%s@%s:%s' % (user, hostname, remote_path)]) #Where should the file go scp_command_list.extend([local_path]) #Print and execute logger.info("Downloading image: <%s>" % (' '.join(map(str,scp_command_list)),)) run_command(scp_command_list) return local_path finally: if private_key: run_command(['rm', '-rf', ssh_file_loc])
def _create_virtual_harddrive(self, local_img_path, disk_type): if 'vmdk' in disk_type: convert_img_path = os.path.splitext(local_img_path)[0] + '.vmdk' run_command(['qemu-img', 'convert', local_img_path, '-O', 'vmdk', convert_img_path]) elif 'vdi' in disk_type: raw_img_path = os.path.splitext(local_img_path)[0] + '.raw' #Convert to raw if its anything else.. if '.raw' not in local_img_path: run_command(['qemu-img', 'convert', local_img_path, '-O', 'raw', raw_img_path]) #Convert from raw to vdi convert_img_path = os.path.splitext(local_img_path)[0] + '.vdi' #NOTE: Must DELETE first! run_command(['VBoxManage', 'convertdd',raw_img_path, convert_img_path]) else: convert_img_path = None logger.warn("Failed to export. Unknown type: %s" % (disk_type,) ) return convert_img_path
def _create_virtual_harddrive(self, local_img_path, disk_type): if 'vmdk' in disk_type: convert_img_path = os.path.splitext(local_img_path)[0] + '.vmdk' run_command([ 'qemu-img', 'convert', local_img_path, '-O', 'vmdk', convert_img_path ]) elif 'vdi' in disk_type: raw_img_path = os.path.splitext(local_img_path)[0] + '.raw' #Convert to raw if its anything else.. if '.raw' not in local_img_path: run_command([ 'qemu-img', 'convert', local_img_path, '-O', 'raw', raw_img_path ]) #Convert from raw to vdi convert_img_path = os.path.splitext(local_img_path)[0] + '.vdi' #NOTE: Must DELETE first! run_command( ['VBoxManage', 'convertdd', raw_img_path, convert_img_path]) else: convert_img_path = None logger.warn("Failed to export. Unknown type: %s" % (disk_type, )) return convert_img_path
def _get_stage_files(self, root_dir, distro): if distro == 'centos': run_command(['/bin/bash','-c','cp -f %s/extras/export/grub_files/centos/* %s/boot/grub/' % (self.extras_root, root_dir)]) elif distro == 'ubuntu': run_command(['/bin/bash','-c','cp -f %s/extras/export/grub_files/ubuntu/* %s/boot/grub/' % (self.extras_root, root_dir)])