def clean_hook(self, image_path, mount_point, exclude=[], *args, **kwargs): """ The image resides in <image_path> and is mounted to <mount_point>. Remove all filepaths listed in <exclude> Run any driver-specific cleaning here """ #Begin removing user-specified files (Matches wildcards) if exclude and exclude[0]: logger.info("User-initiated files to be removed: %s" % exclude) remove_files(exclude, mount_point) return
def _perform_cleaning(mounted_path, rm_files=None, remove_line_files=None, overwrite_list=None, replace_line_files=None, multiline_delete_files=None, dry_run=False): """ Runs the commands to perform all cleaning operations. For more information see the specific function """ apt_uninstall(mounted_path, ['avahi-daemon']) remove_files(rm_files, mounted_path, dry_run) overwrite_files(overwrite_list, mounted_path, dry_run) remove_line_in_files(remove_line_files, mounted_path, dry_run) replace_line_in_files(replace_line_files, mounted_path, dry_run) remove_multiline_in_files(multiline_delete_files, mounted_path, dry_run)
def debian_mount(self, image_path, mounted_path): """ Convert the disk image at <image_path>, mounted at <mounted_path>, from XEN to KVM """ #This list will add a single line to an already-existing file append_line_file_list = [ #("line to add", "file_to_append") ("exec /sbin/getty -L 38400 ttyS0 vt102", "etc/init/getty.conf"), ("exec /sbin/getty -L 38400 ttyS1 vt102", "etc/init/getty.conf"), ] #If etc/init/getty.conf doesn't exist, use this template to create it kvm_getty_script = """# getty - ttyS* # This service maintains a getty on ttyS0/S1 # from the point the system is started until # it is shut down again. start on stopped rc RUNLEVEL=[2345] stop on runlevel [!2345] respawn exec /sbin/getty -L 38400 ttyS0 vt102 exec /sbin/getty -L 38400 ttyS1 vt102 """ #This list removes lines matching the pattern from an existing file remove_line_file_list = [ #("pattern_match", "file_to_test") ("atmo_boot", "etc/rc.local"), # Save /dev/sda1, /dev/vda, /dev/xvda # Delete all other partitions in etc/fstab ("sda[2-9]", "etc/fstab"), ("sda1[0-9]", "etc/fstab"), ("vd[b-z]", "etc/fstab"), ] # This list contains all files that should be deleted remove_file_list = ['etc/init/hvc0.conf'] remove_line_in_files(remove_line_file_list, mounted_path) remove_files(remove_file_list, mounted_path) if not create_file("etc/init/getty.conf", mounted_path, kvm_getty_script): #Didn't need to create the file, but we still need to append our # new lines append_line_in_files(append_line_file_list, mounted_path) return
def debian_mount(self, image_path, mounted_path): """ Convert the disk image at <image_path>, mounted at <mounted_path>, from XEN to KVM """ #This list will add a single line to an already-existing file append_line_file_list = [ #("line to add", "file_to_append") ("exec /sbin/getty -L 38400 ttyS0 vt102", "etc/init/getty.conf"), ("exec /sbin/getty -L 38400 ttyS1 vt102", "etc/init/getty.conf"), ] #If etc/init/getty.conf doesn't exist, use this template to create it kvm_getty_script = """# getty - ttyS* # This service maintains a getty on ttyS0/S1 # from the point the system is started until # it is shut down again. start on stopped rc RUNLEVEL=[2345] stop on runlevel [!2345] respawn exec /sbin/getty -L 38400 ttyS0 vt102 exec /sbin/getty -L 38400 ttyS1 vt102 """ #This list removes lines matching the pattern from an existing file remove_line_file_list = [ #("pattern_match", "file_to_test") ("atmo_boot", "etc/rc.local"), # Save /dev/sda1, /dev/vda, /dev/xvda # Delete all other partitions in etc/fstab ("sda[2-9]", "etc/fstab"), ("sda1[0-9]", "etc/fstab"), ("vd[b-z]", "etc/fstab"), ] # This list contains all files that should be deleted remove_file_list = [ 'etc/init/hvc0.conf'] remove_line_in_files(remove_line_file_list, mounted_path) remove_files(remove_file_list, mounted_path) if not create_file("etc/init/getty.conf", mounted_path, kvm_getty_script): #Didn't need to create the file, but we still need to append our # new lines append_line_in_files(append_line_file_list, mounted_path) return
def _perform_cleaning(mounted_path, rm_files=None, remove_line_files=None, overwrite_list=None, replace_line_files=None, multiline_delete_files=None, append_line_files=None, execute_lines=None, dry_run=False): """ Runs the commands to perform all cleaning operations. For more information see the specific function """ remove_files(rm_files, mounted_path, dry_run) overwrite_files(overwrite_list, mounted_path, dry_run) remove_line_in_files(remove_line_files, mounted_path, dry_run) replace_line_in_files(replace_line_files, mounted_path, dry_run) remove_multiline_in_files(multiline_delete_files, mounted_path, dry_run) append_line_in_files(append_line_files, mounted_path, dry_run) execute_chroot_commands(execute_lines, mounted_path, dry_run)