Esempio n. 1
0
File: wsgi.py Progetto: dizz/occi-os
    def _refresh_os_mixins(self, extras):
        """
        Register images as OsTemplate mixins from
        information retrieved from glance (shared and user-specific).
        """
        template_schema = 'http://schemas.openstack.org/template/os#'
        image_service = image.get_default_image_service()

        images = image_service.detail(extras['nova_ctx'])
        filter_kernel_and_ram_images = \
                                FLAGS.get("filter_kernel_and_ram_images", True)

        for img in images:
            # If the image is a kernel or ram one
            # and we're not to filter them out then register it.
            if (((img['container_format'] or img['disk_format'])
                    in ('ari', 'aki')) and filter_kernel_and_ram_images):
                msg = 'Not registering kernel/RAM image.'
                LOG.warn(msg)
                continue

            os_template = templates.OsTemplate(
                                term=img['name'],
                                scheme=template_schema,
                                os_id=img['id'],
                                related=[templates.OS_TEMPLATE],
                                attributes=None,
                                title='This is an OS ' + img['name'] + \
                                                            ' VM image',
                                location='/' + img['name'] + '/')

            msg = ('Registering an OS image type as: %s') % str(os_template)
            LOG.debug(msg)

            try:
                self.registry.get_backend(os_template, extras)
            except AttributeError:
                self.register_backend(os_template, MIXIN_BACKEND)
Esempio n. 2
0
 def setUp(self):
     super(_VirtDriverTestCase, self).setUp()
     self.connection = self.driver_module.get_connection('')
     self.ctxt = test_utils.get_test_admin_context()
     self.image_service = image.get_default_image_service()
Esempio n. 3
0
 def setUp(self):
     super(_VirtDriverTestCase, self).setUp()
     self.connection = self.driver_module.get_connection('')
     self.ctxt = test_utils.get_test_admin_context()
     self.image_service = image.get_default_image_service()
Esempio n. 4
0
 def __init__(self, service=None, *args, **kwargs):
     self.service = service or image.get_default_image_service()
     self.service.__init__(*args, **kwargs)
Esempio n. 5
0
    def verify_base_images(self, context):
        """Verify that base images are in a reasonable state."""
        # TODO(mikal): Write a unit test for this method

        base_dir = os.path.join(FLAGS.instances_path, '_base')
        if not os.path.exists(base_dir):
            LOG.debug(_('Skipping verification, no base directory at %s'),
                      base_dir)
            return

        LOG.debug(_('Verify base images'))
        self._list_base_images(base_dir)
        self._list_running_instances(context)

        # Determine what images are in glance
        image_service = image.get_default_image_service()

        self.active_base_files = []
        self.corrupt_base_files = []
        self.removable_base_files = []

        # GlanceImageService.detail uses _fetch_images which handles pagination
        # for us
        for img in image_service.detail(context):
            if img['container_format'] != 'ami':
                continue

            fingerprint = hashlib.sha1(str(img['id'])).hexdigest()
            for base_file, image_small in self._find_base_file(base_dir,
                                                               fingerprint):
                self._handle_base_image(img, base_file, image_small)

        # Elements remaining in unexplained_images are not currently in
        # glance. That doesn't mean that they're really not in use though
        # (consider images which have been removed from glance but are still
        # used by instances). So, we check the backing file for any running
        # instances as well.
        if self.unexplained_images:
            inuse_backing_images = self._list_backing_images()
            if inuse_backing_images:
                for backing_path in inuse_backing_images:
                    self.active_base_files.append(backing_path)

        # Anything left is an unknown base image
        for img in self.unexplained_images:
            LOG.warning(_('Unknown base file: %s'), img)
            self.removable_base_files.append(img)

        # Dump these lists
        if self.active_base_files:
            LOG.info(_('Active base files: %s'),
                     ' '.join(self.active_base_files))
        if self.corrupt_base_files:
            LOG.info(_('Corrupt base files: %s'),
                     ' '.join(self.corrupt_base_files))

        if self.removable_base_files:
            LOG.info(_('Removable base files: %s'),
                     ' '.join(self.removable_base_files))

            if FLAGS.remove_unused_base_images:
                for base_file in self.removable_base_files:
                    self._remove_base_file(base_file)

        # That's it
        LOG.debug(_('Verification complete'))
Esempio n. 6
0
 def __init__(self, service=None, *args, **kwargs):
     self.service = service or image.get_default_image_service()
     self.service.__init__(*args, **kwargs)
Esempio n. 7
0
 def __init__(self, service=None, *args, **kwargs):
     self.cert_rpcapi = nova.cert.rpcapi.CertAPI()
     self.service = service or image.get_default_image_service()
     self.service.__init__(*args, **kwargs)
Esempio n. 8
0
File: vol.py Progetto: dizz/occi-os
Storage related glue :-)
"""

import random

from nova import image, exception
from nova import volume

from occi import exceptions

# Connection to the nova APIs
from nova_glue import vm

VOLUME_API = volume.API()

IMAGE_API = image.get_default_image_service()


def create_storage(size, context, name=None, description=None):
    """
    Create a storage instance.

    size -- Size of the storage. ('occi.storage.size')
    context -- The os context.
    name -- defaults to a random number if needed.
    description -- defaults to the name
    """
    # TODO: exception handling!
    # TODO(dizz): A blueprint?
    # OpenStack deals with size in terms of integer.
    # Need to convert float to integer for now and only if the float
Esempio n. 9
0
 def __init__(self):
     self.image_service = image.get_default_image_service()
Esempio n. 10
0
 def __init__(self):
     self.image_service = image.get_default_image_service()
Esempio n. 11
0
 def __init__(self, service=None, *args, **kwargs):
     self.cert_rpcapi = nova.cert.rpcapi.CertAPI()
     self.service = service or image.get_default_image_service()
     self.service.__init__(*args, **kwargs)
Esempio n. 12
0
    def verify_base_images(self, context):
        """Verify that base images are in a reasonable state."""
        # TODO(mikal): Write a unit test for this method
        # TODO(mikal): Handle "generated" images

        # NOTE(mikal): The new scheme for base images is as follows -- an
        # image is streamed from the image service to _base (filename is the
        # sha1 hash of the image id). If CoW is enabled, that file is then
        # resized to be the correct size for the instance (filename is the
        # same as the original, but with an underscore and the resized size
        # in bytes). This second file is then CoW'd to the instance disk. If
        # CoW is disabled, the resize occurs as part of the copy from the
        # cache to the instance directory. Files ending in _sm are no longer
        # created, but may remain from previous versions.
        self._reset_state()

        base_dir = os.path.join(FLAGS.instances_path, '_base')
        if not os.path.exists(base_dir):
            LOG.debug(_('Skipping verification, no base directory at %s'),
                      base_dir)
            return

        LOG.debug(_('Verify base images'))
        self._list_base_images(base_dir)
        self._list_running_instances(context)

        # Determine what images are in glance. GlanceImageService.detail uses
        # _fetch_images which handles pagination for us
        image_service = image.get_default_image_service()
        for img in image_service.detail(context):
            if img['container_format'] != 'ami':
                continue

            fingerprint = hashlib.sha1(str(img['id'])).hexdigest()
            for result in self._find_base_file(base_dir, fingerprint):
                base_file, image_small, image_resized = result
                self._handle_base_image(img, base_file)

                if not image_small and not image_resized:
                    self.originals.append(base_file)

        # Elements remaining in unexplained_images are not directly from
        # glance. That might mean they're from a image that was removed from
        # glance, but it might also mean that they're a resized image.
        inuse_backing_images = self._list_backing_images()
        for backing_path in inuse_backing_images:
            self.active_base_files.append(backing_path)

        # Anything left is an unknown base image
        for img in self.unexplained_images:
            LOG.warning(_('Unknown base file: %s'), img)
            self.removable_base_files.append(img)

        # Dump these lists
        if self.active_base_files:
            LOG.info(_('Active base files: %s'),
                     ' '.join(self.active_base_files))
        if self.corrupt_base_files:
            LOG.info(_('Corrupt base files: %s'),
                     ' '.join(self.corrupt_base_files))

        if self.removable_base_files:
            LOG.info(_('Removable base files: %s'),
                     ' '.join(self.removable_base_files))

            if FLAGS.remove_unused_base_images:
                for base_file in self.removable_base_files:
                    self._remove_base_file(base_file)

        # That's it
        LOG.debug(_('Verification complete'))
Esempio n. 13
0
    def verify_base_images(self, context):
        """Verify that base images are in a reasonable state."""
        # TODO(mikal): Write a unit test for this method
        # TODO(mikal): Handle "generated" images

        # NOTE(mikal): The new scheme for base images is as follows -- an
        # image is streamed from the image service to _base (filename is the
        # sha1 hash of the image id). If CoW is enabled, that file is then
        # resized to be the correct size for the instance (filename is the
        # same as the original, but with an underscore and the resized size
        # in bytes). This second file is then CoW'd to the instance disk. If
        # CoW is disabled, the resize occurs as part of the copy from the
        # cache to the instance directory. Files ending in _sm are no longer
        # created, but may remain from previous versions.

        self.unexplained_images = []
        self.active_base_files = []
        self.corrupt_base_files = []
        self.removable_base_files = []
        self.originals = []

        base_dir = os.path.join(FLAGS.instances_path, '_base')
        if not os.path.exists(base_dir):
            LOG.debug(_('Skipping verification, no base directory at %s'),
                      base_dir)
            return

        LOG.debug(_('Verify base images'))
        self._list_base_images(base_dir)
        self._list_running_instances(context)

        # Determine what images are in glance. GlanceImageService.detail uses
        # _fetch_images which handles pagination for us
        image_service = image.get_default_image_service()
        for img in image_service.detail(context):
            if img['container_format'] != 'ami':
                continue

            fingerprint = hashlib.sha1(str(img['id'])).hexdigest()
            for result in self._find_base_file(base_dir, fingerprint):
                base_file, image_small, image_resized = result
                self._handle_base_image(img, base_file)

                if not image_small and not image_resized:
                    self.originals.append(base_file)

        # Elements remaining in unexplained_images are not directly from
        # glance. That might mean they're from a image that was removed from
        # glance, but it might also mean that they're a resized image.
        inuse_backing_images = self._list_backing_images()
        for backing_path in inuse_backing_images:
            self.active_base_files.append(backing_path)

        # Anything left is an unknown base image
        for img in self.unexplained_images:
            LOG.warning(_('Unknown base file: %s'), img)
            self.removable_base_files.append(img)

        # Dump these lists
        if self.active_base_files:
            LOG.info(_('Active base files: %s'),
                     ' '.join(self.active_base_files))
        if self.corrupt_base_files:
            LOG.info(_('Corrupt base files: %s'),
                     ' '.join(self.corrupt_base_files))

        if self.removable_base_files:
            LOG.info(_('Removable base files: %s'),
                     ' '.join(self.removable_base_files))

            if FLAGS.remove_unused_base_images:
                for base_file in self.removable_base_files:
                    self._remove_base_file(base_file)

        # That's it
        LOG.debug(_('Verification complete'))