Example #1
0
    def _get_lxd_manifest(self, instance, image_meta):
        """Creates the LXD manifest, needed for split images

        :param instance: nova instance
        :param image_meta: image metadata dictionary

        """
        LOG.debug('_get_lxd_manifest called for instance', instance=instance)

        metadata_yaml = None
        try:
            # Create a basic LXD manifest from the image properties
            image_arch = image_meta.properties.get('hw_architecture')
            if image_arch is None:
                image_arch = arch.from_host()
            metadata = {
                'architecture': image_arch,
                'creation_date': int(os.stat(self.container_image).st_ctime)
            }

            metadata_yaml = (json.dumps(metadata, sort_keys=True,
                                        indent=4, separators=(',', ': '),
                                        ensure_ascii=False).encode('utf-8')
                             + b"\n")
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                LOG.error(_LE('Failed to generate manifest for %(image)s: '
                              '%(reason)s'),
                          {'image': instance.name, 'ex': ex},
                          instance=instance)
        try:
            # Compress the manifest using tar
            target_tarball = tarfile.open(self.container_manifest, "w:")
            metadata_file = tarfile.TarInfo()
            metadata_file.size = len(metadata_yaml)
            metadata_file.name = "metadata.yaml"
            target_tarball.addfile(metadata_file,
                                   io.BytesIO(metadata_yaml))
            target_tarball.close()
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                LOG.error(_LE('Failed to generate manifest tarball for'
                              ' %(image)s: %(reason)s'),
                          {'image': instance.name, 'ex': ex},
                          instance=instance)

        try:
            # Compress the manifest further using xz
            with fileutils.remove_path_on_error(self.container_manifest):
                utils.execute('xz', '-9', self.container_manifest,
                              check_exit_code=[0, 1])
        except processutils.ProcessExecutionError as ex:
            with excutils.save_and_reraise_exception:
                LOG.error(_LE('Failed to compress manifest for %(image)s:'
                              ' %(ex)s'), {'image': instance.image_ref,
                                           'ex': ex}, instance=instance)
Example #2
0
    def test_host(self, mock_uname):
        os.uname.return_value = (
            "Linux",
            "localhost.localdomain",
            "3.14.8-200.fc20.x86_64",
            "#1 SMP Mon Jun 16 21:57:53 UTC 2014",
            "i686",
        )

        self.assertEqual(arch.I686, arch.from_host())
def get_arch(image_meta):
    """Determine the architecture of the guest (or host).

    This method determines the CPU architecture that must be supported by
    the hypervisor. It gets the (guest) arch info from image_meta properties,
    and it will fallback to the nova-compute (host) arch if no architecture
    info is provided in image_meta.

    :param image_meta: the metadata associated with the instance image

    :returns: guest (or host) architecture
    """
    if image_meta:
        image_arch = image_meta.properties.get('hw_architecture')
        if image_arch is not None:
            return image_arch

    return arch.from_host()
Example #4
0
def get_arch(image_meta):
    """Determine the architecture of the guest (or host).

    This method determines the CPU architecture that must be supported by
    the hypervisor. It gets the (guest) arch info from image_meta properties,
    and it will fallback to the nova-compute (host) arch if no architecture
    info is provided in image_meta.

    :param image_meta: the metadata associated with the instance image

    :returns: guest (or host) architecture
    """
    if image_meta:
        image_arch = image_meta.get('properties', {}).get('architecture')
        if image_arch is not None:
            return arch.canonicalize(image_arch)

    return arch.from_host()
Example #5
0
    def test_host(self, mock_uname):
        os.uname.return_value = ('Linux', 'localhost.localdomain',
                                 '3.14.8-200.fc20.x86_64',
                                 '#1 SMP Mon Jun 16 21:57:53 UTC 2014', 'i686')

        self.assertEqual(arch.I686, arch.from_host())
Example #6
0
    def _get_lxd_manifest(self, instance, image_meta):
        """Creates the LXD manifest, needed for split images

        :param instance: nova instance
        :param image_meta: image metadata dictionary

        """
        LOG.debug('_get_lxd_manifest called for instance', instance=instance)

        metadata_yaml = None
        try:
            # Create a basic LXD manifest from the image properties
            image_arch = image_meta.properties.get('hw_architecture')
            if image_arch is None:
                image_arch = arch.from_host()
            metadata = {
                'architecture': image_arch,
                'creation_date': int(os.stat(self.container_image).st_ctime)
            }

            metadata_yaml = (json.dumps(metadata,
                                        sort_keys=True,
                                        indent=4,
                                        separators=(',', ': '),
                                        ensure_ascii=False).encode('utf-8') +
                             b"\n")
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                LOG.error(_LE('Failed to generate manifest for %(image)s: '
                              '%(reason)s'), {
                                  'image': instance.name,
                                  'ex': ex
                              },
                          instance=instance)
        try:
            # Compress the manifest using tar
            target_tarball = tarfile.open(self.container_manifest, "w:")
            metadata_file = tarfile.TarInfo()
            metadata_file.size = len(metadata_yaml)
            metadata_file.name = "metadata.yaml"
            target_tarball.addfile(metadata_file, io.BytesIO(metadata_yaml))
            target_tarball.close()
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                LOG.error(_LE('Failed to generate manifest tarball for'
                              ' %(image)s: %(reason)s'), {
                                  'image': instance.name,
                                  'ex': ex
                              },
                          instance=instance)

        try:
            # Compress the manifest further using xz
            with fileutils.remove_path_on_error(self.container_manifest):
                utils.execute('xz',
                              '-9',
                              self.container_manifest,
                              check_exit_code=[0, 1])
        except processutils.ProcessExecutionError as ex:
            with excutils.save_and_reraise_exception:
                LOG.error(_LE('Failed to compress manifest for %(image)s:'
                              ' %(ex)s'), {
                                  'image': instance.image_ref,
                                  'ex': ex
                              },
                          instance=instance)