Example #1
0
    def create_image_format(self):
        """
        Create vagrant box for libvirt provider. This includes

        * creation of qcow2 disk image format as box.img
        * creation of box metadata.json
        * creation of box Vagrantfile
        * creation of result format tarball from the files created above
        """
        self.temp_image_dir = mkdtemp(prefix='kiwi_vagrant_box.')

        qcow = DiskFormatQcow2(self.xml_state, self.root_dir, self.target_dir)
        qcow.create_image_format()
        box_img = os.sep.join([self.temp_image_dir, 'box.img'])
        Command.run([
            'mv',
            self.get_target_name_for_format(qcow.image_format), box_img
        ])

        metadata_json = os.sep.join([self.temp_image_dir, 'metadata.json'])
        with open(metadata_json, 'w') as meta:
            meta.write(self._create_box_metadata())

        vagrantfile = os.sep.join([self.temp_image_dir, 'Vagrantfile'])
        with open(vagrantfile, 'w') as vagrant:
            vagrant.write(self._create_box_vagrantconfig())

        Command.run([
            'tar', '-C', self.temp_image_dir, '-czf',
            self.get_target_name_for_format(self.image_format),
            os.path.basename(box_img),
            os.path.basename(metadata_json),
            os.path.basename(vagrantfile)
        ])
Example #2
0
 def __new__(self, name, xml_state, root_dir, target_dir):  # noqa: C901
     custom_args = xml_state.get_build_type_format_options()
     if name == 'qcow2':
         return DiskFormatQcow2(xml_state, root_dir, target_dir,
                                custom_args)
     elif name == 'vdi':
         return DiskFormatVdi(xml_state, root_dir, target_dir, custom_args)
     elif name == 'vhd':
         return DiskFormatVhd(xml_state, root_dir, target_dir, custom_args)
     elif name == 'vhdx':
         return DiskFormatVhdx(xml_state, root_dir, target_dir, custom_args)
     elif name == 'vhd-fixed':
         disk_tag = xml_state.build_type.get_vhdfixedtag()
         if disk_tag:
             custom_args.update({'--tag': disk_tag})
         return DiskFormatVhdFixed(xml_state, root_dir, target_dir,
                                   custom_args)
     elif name == 'gce':
         gce_license_tag = xml_state.build_type.get_gcelicense()
         if gce_license_tag:
             custom_args.update({'--tag': gce_license_tag})
         return DiskFormatGce(xml_state, root_dir, target_dir, custom_args)
     elif name == 'vmdk' or name == 'ova':
         vmdisk_section = xml_state.get_build_type_vmdisk_section()
         if vmdisk_section:
             disk_mode = vmdisk_section.get_diskmode()
             disk_controller = vmdisk_section.get_controller()
             if disk_mode:
                 custom_args.update(
                     {'subformat={0}'.format(disk_mode): None})
             if disk_controller:
                 custom_args.update(
                     {'adapter_type={0}'.format(disk_controller): None})
         if name == 'vmdk':
             return DiskFormatVmdk(xml_state, root_dir, target_dir,
                                   custom_args)
         else:
             return DiskFormatOva(xml_state, root_dir, target_dir,
                                  custom_args)
     elif name == 'vagrant':
         vagrant_config = xml_state.get_build_type_vagrant_config_section()
         if vagrant_config:
             custom_args.update({'vagrantconfig': vagrant_config})
             provider = vagrant_config.get_provider()
         else:
             provider = 'undefined'
         if provider == 'libvirt':
             return DiskFormatVagrantLibVirt(xml_state, root_dir,
                                             target_dir, custom_args)
         else:
             raise KiwiDiskFormatSetupError(
                 'No support for {0} format with {1} provider'.format(
                     name, provider))
     elif name == 'raw':
         return DiskFormatBase(xml_state, root_dir, target_dir, custom_args)
     else:
         raise KiwiDiskFormatSetupError(
             'No support for {0} disk format'.format(name))
 def setup(self, mock_machine):
     mock_machine.return_value = 'x86_64'
     xml_data = mock.Mock()
     xml_data.get_name = mock.Mock(return_value='some-disk-image')
     self.xml_state = mock.Mock()
     self.xml_state.xml_data = xml_data
     self.xml_state.get_image_version = mock.Mock(return_value='1.2.3')
     self.disk_format = DiskFormatQcow2(self.xml_state, 'root_dir',
                                        'target_dir')
Example #4
0
 def create_box_img(self, temp_image_dir):
     """
     Creates the qcow2 disk image box for libvirt vagrant provider
     """
     qcow = DiskFormatQcow2(self.xml_state, self.root_dir, self.target_dir)
     qcow.create_image_format()
     box_img = os.sep.join([temp_image_dir, 'box.img'])
     Command.run([
         'mv',
         self.get_target_file_path_for_format(qcow.image_format), box_img
     ])
     return [box_img]
Example #5
0
 def setup(self, mock_machine):
     mock_machine.return_value = 'x86_64'
     xml_data = Mock()
     xml_data.get_name = Mock(return_value='some-disk-image')
     self.xml_state = Mock()
     self.xml_state.xml_data = xml_data
     self.xml_state.get_image_version = Mock(return_value='1.2.3')
     self.runtime_config = Mock()
     self.runtime_config.get_bundle_compression.return_value = False
     kiwi.storage.subformat.base.RuntimeConfig = Mock(
         return_value=self.runtime_config)
     self.disk_format = DiskFormatQcow2(self.xml_state, 'root_dir',
                                        'target_dir')
Example #6
0
 def __new__(self, name, xml_state, root_dir, target_dir):
     if name == 'qcow2':
         return DiskFormatQcow2(xml_state, root_dir, target_dir)
     elif name == 'vdi':
         return DiskFormatVdi(xml_state, root_dir, target_dir)
     elif name == 'vhd':
         return DiskFormatVhd(xml_state, root_dir, target_dir)
     elif name == 'vhd-fixed':
         custom_args = None
         disk_tag = xml_state.build_type.get_vhdfixedtag()
         if disk_tag:
             custom_args = {'--tag': disk_tag}
         return DiskFormatVhdFixed(xml_state, root_dir, target_dir,
                                   custom_args)
     elif name == 'gce':
         custom_args = None
         gce_license_tag = xml_state.build_type.get_gcelicense()
         if gce_license_tag:
             custom_args = {'--tag': gce_license_tag}
         return DiskFormatGce(xml_state, root_dir, target_dir, custom_args)
     elif name == 'vmdk':
         custom_args = None
         vmdisk_section = xml_state.get_build_type_vmdisk_section()
         if vmdisk_section:
             custom_args = {}
             disk_mode = vmdisk_section.get_diskmode()
             disk_controller = vmdisk_section.get_controller()
             if disk_mode:
                 custom_args['subformat=%s' % disk_mode] = None
             if disk_controller:
                 custom_args['adapter_type=%s' % disk_controller] = None
         return DiskFormatVmdk(xml_state, root_dir, target_dir, custom_args)
     elif name == 'vagrant':
         vagrant_config = xml_state.get_build_type_vagrant_config_section()
         if vagrant_config:
             provider = vagrant_config.get_provider()
         else:
             provider = 'undefined'
         if provider == 'libvirt':
             return DiskFormatVagrantLibVirt(
                 xml_state, root_dir, target_dir,
                 {'vagrantconfig': vagrant_config})
         else:
             raise KiwiDiskFormatSetupError(
                 'No support for {0} format with {1} provider'.format(
                     name, provider))
     elif name == 'raw':
         return DiskFormatBase(xml_state, root_dir, target_dir)
     else:
         raise KiwiDiskFormatSetupError(
             'No support for {0} disk format'.format(name))
Example #7
0
    def create_box_img(self, temp_image_dir: str) -> List[str]:
        """
        Creates the qcow2 disk image box for libvirt vagrant provider

        :param str temp_image_dir:
            Path to the temporary directory used to build the box image

        :return:
            A list of files relevant for the libvirt box to be
            included in the vagrant box

        :rtype: list
        """
        qcow = DiskFormatQcow2(self.xml_state, self.root_dir, self.target_dir)
        qcow.create_image_format()
        box_img = os.sep.join([temp_image_dir, 'box.img'])
        Command.run([
            'mv',
            self.get_target_file_path_for_format(qcow.image_format), box_img
        ])
        return [box_img]