示例#1
0
    def build_image(self, params):
        self.validate_params(params)

        # Create work space
        with utils.tempdir() as workdir:
            # Copy out the contents of the ISO file.
            iso_dir = self.mount_iso(workdir, self.install_cdrom)
            try:
                output_dir = self.copy_iso(workdir, iso_dir)
            finally:
                self.umount_iso(iso_dir)
                shutil.rmtree(iso_dir)

            # Write the kickstarter config.
            self.write_ks(output_dir)

            # Update isolinux to not have a timeout.
            self.set_timeout_zero(output_dir)

            # Create the final ISO for installation.
            try:
                self.install_cdrom = self.create_iso(workdir, output_dir)
            finally:
                shutil.rmtree(output_dir)

            super(RHELBuilder, self).build_image(params)
示例#2
0
    def build_image(self, params):
        self.validate_params(params)

        # Create work space
        with utils.tempdir() as workdir:

            # Build the install.iso
            install_iso = self.build_install_iso(
                workdir,
                params.arch,
                with_updates=params.windows_updates,
                drivers_path=params.windows_drivers,
                cloudbase_init=params.cloudbase_init)

            # Create the floppy with the Autounattend.xml
            floppy_path = self.prepare_floppy_disk(
                workdir,
                params.arch,
                params.windows_edition,
                params.windows_language,
                license_key=params.windows_license_key,
                enable_updates=params.windows_updates)

            # Create the disk image
            disk_path = os.path.join(workdir, 'output.img')
            self.create_disk_image(disk_path, '16G')

            # Create tap device, if installing Windows updates
            # as the VM needs access to microsoft.com
            tap_name = None
            if params.windows_updates:
                tap_name = net.create_tap(params.interface)

            try:
                # Start the Windows installation
                self.spawn_vm(params.ram,
                              params.vcpus,
                              params.windows_iso,
                              floppy_path,
                              install_iso,
                              disk_path,
                              tap=tap_name)
            finally:
                # Destroy the tap
                if tap_name is not None:
                    net.delete_tap(tap_name)

            # Installation has finished, mount the disk
            mount_path = self.mount_partition(workdir, disk_path, 1)

            try:
                # Check that installation went as expected
                error_filename = 'windows-%s-%s-error.log' % (
                    params.windows_edition, params.arch)
                save_error_path = os.path.join(
                    tempfile.mkdtemp(prefix="mib-windows"), error_filename)
                self.check_success(mount_path, save_error_path)

                # Install the curtin scripts into the root
                self.install_curtin(mount_path)

                # Remove serial output from cloudbase-init.conf
                self.remove_serial_log(mount_path)

            finally:
                # Unmount and clean
                self.umount_partition(disk_path, mount_path, 1)

            # Convert to raw, to save on some sparse space
            clean_disk_path = os.path.join(workdir, 'clean-output.img')
            self.qemu_convert(disk_path, clean_disk_path)
            os.unlink(disk_path)

            # Create the tarball of raw image
            tarball_path = os.path.join(workdir, 'output.ddtgz')
            self.create_tarball(clean_disk_path, tarball_path)

            # Move to output
            shutil.move(tarball_path, params.output)
示例#3
0
    def build_image(self, params):
        """Builds the image with virt-install."""
        # Check for valid location
        if self.install_location is None and self.install_cdrom is None:
            raise BuildError(
                "Missing install_location or install_cdrom for virt-install.")

        # Naming
        full_name = self.full_name(params)

        # Create work space
        with utils.tempdir() as workdir:
            # virt-install fails to access the directory
            # unless the following permissions are used
            utils.subp(['chmod', '777', workdir])

            # Create the disk, and set the permissions
            # that will allow virt-install to access it
            disk_path = os.path.join(workdir, 'disk.img')
            virt.create_disk(disk_path, self.disk_size, disk_format='raw')
            utils.subp(['chmod', '777', disk_path])
            disk_str = "path=%s,format=raw" % disk_path

            # Start the installation
            vm_name = 'img-build-%s' % full_name
            network_str = 'bridge=%s' % params.interface
            if self.nic_model is not None:
                network_str = '%s,model=%s' % (network_str, self.nic_model)
            if self.install_location:
                virt.install_location(vm_name,
                                      params.ram,
                                      params.arch,
                                      params.vcpus,
                                      self.os_type,
                                      self.os_variant,
                                      disk_str,
                                      network_str,
                                      self.install_location,
                                      initrd_inject=self.initrd_inject,
                                      extra_args=self.extra_arguments)
            else:
                virt.install_cdrom(vm_name, params.ram, params.arch,
                                   params.vcpus, self.os_type, self.os_variant,
                                   disk_str, network_str, self.install_cdrom)

            # Remove the finished installation from virsh
            virt.undefine(vm_name)

            # Mount the disk image
            mount_path = os.path.join(workdir, "mount")
            os.mkdir(mount_path)
            try:
                utils.mount_loop(disk_path, mount_path)

                # Allow the osystem module to install any needed files
                # into the filesystem
                self.modify_mount(mount_path)

                # Create the tarball
                output_path = os.path.join(workdir, "output.tar.gz")
                utils.create_tarball(output_path, mount_path)
            finally:
                utils.umount_loop(disk_path, mount_path)

            # Place in output
            shutil.move(output_path, params.output)