예제 #1
0
파일: api.py 프로젝트: jjacob512/cinder-1
 def __init__(self, db_driver=None, image_service=None):
     self.image_service = (image_service
                           or glance.get_default_image_service())
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
     self.volume_rpcapi = volume_rpcapi.VolumeAPI()
     self.availability_zone_names = ()
     super(API, self).__init__(db_driver)
예제 #2
0
 def _get_image_snapshot(self, context, image_uuid):
     image_snapshot = None
     if image_uuid:
         image_service = glance.get_default_image_service()
         image_meta = image_service.show(context, image_uuid)
         if image_meta is not None:
             bdms = image_meta.get('properties',
                                   {}).get('block_device_mapping', [])
             if bdms:
                 boot_bdm = [
                     bdm for bdm in bdms
                     if (bdm.get('source_type') == 'snapshot'
                         and bdm.get('boot_index') == 0)
                 ]
                 if boot_bdm:
                     try:
                         image_snapshot = self.volume_api.get_snapshot(
                             context, boot_bdm[0].get('snapshot_id'))
                         return image_snapshot
                     except exception.NotFound:
                         explanation = _(
                             'Nova specific image is found, but boot '
                             'volume snapshot id:%s not found.'
                         ) % boot_bdm[0].get('snapshot_id')
                         raise exc.HTTPNotFound(explanation=explanation)
         return image_snapshot
예제 #3
0
파일: api.py 프로젝트: akutz/cinder
 def __init__(self, db_driver=None, image_service=None):
     self.image_service = (image_service or
                           glance.get_default_image_service())
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
     self.volume_rpcapi = volume_rpcapi.VolumeAPI()
     self.availability_zone_names = ()
     super(API, self).__init__(db_driver)
예제 #4
0
파일: api.py 프로젝트: vilobhmm/cinder
 def __init__(self, db_driver=None, image_service=None):
     self.image_service = image_service or glance.get_default_image_service()
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
     self.volume_rpcapi = volume_rpcapi.VolumeAPI()
     self.availability_zones = []
     self.availability_zones_last_fetched = None
     self.key_manager = keymgr.API()
     super(API, self).__init__(db_driver)
예제 #5
0
 def __init__(self, db_driver=None, image_service=None):
     self.image_service = (image_service
                           or glance.get_default_image_service())
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
     self.volume_rpcapi = volume_rpcapi.VolumeAPI()
     self.availability_zones = []
     self.availability_zones_last_fetched = None
     self.key_manager = keymgr.API()
     super(API, self).__init__(db_driver)
예제 #6
0
def validate_stores_id(context, image_service_store_id):
    image_service = glance.get_default_image_service()
    stores_info = image_service.get_stores(context)['stores']
    for info in stores_info:
        if image_service_store_id == info['id']:
            if info.get('read-only') == "true":
                raise exception.GlanceStoreReadOnly(
                    store_id=image_service_store_id)
            return

    raise exception.GlanceStoreNotFound(store_id=image_service_store_id)
예제 #7
0
def _image_accessible(driver, context, volume, image_meta):
    # Determine if image is accessible by current project
    pid = volume.get('project_id', '')
    public = False
    visibility = image_meta.get('visibility', None)
    LOG.debug("Image %(image)s visibility: %(vis)s", {
        "image": image_meta['id'],
        "vis": visibility
    })
    if visibility and visibility in ['public', 'community']:
        public = True
    elif visibility and visibility in ['shared', 'private']:
        # Do membership check.  Newton and before didn't have a 'shared'
        # visibility option, so we have to do this check for 'private'
        # as well
        gclient = glance.get_default_image_service()
        members = []
        # list_members is only available in Rocky+
        try:
            members = gclient.list_members(context, image_meta['id'])
        except AttributeError:
            # This is the fallback method for the same query
            try:
                members = gclient._client.call(context,
                                               'list',
                                               controller='image_members',
                                               image_id=image_meta['id'])
            except glance_exc.HTTPForbidden as e:
                LOG.warning(e)
        except glance_exc.HTTPForbidden as e:
            LOG.warning(e)
        members = list(members)
        LOG.debug("Shared image %(image)s members: %(members)s", {
            "image": image_meta['id'],
            "members": members
        })
        for member in members:
            if (member['member_id'] == pid and member['status'] == 'accepted'):
                public = True
                break
        if image_meta.get('is_public', False):
            public = True
        else:
            if image_meta.get('owner', '') == pid:
                public = True
    if not public:
        LOG.warning("Requested image is not " "accessible by current Project.")
    return public
예제 #8
0
    def __init__(self, service_name=None, *args, **kwargs):
        """Load the specified in args, or flags."""
        # update_service_capabilities needs service_name to be volume
        super(CinderProxy, self).__init__(service_name='volume',
                                          *args, **kwargs)
        self.configuration = Configuration(volume_manager_opts,
                                           config_group=service_name)
        self._tp = GreenPool()

        self.volume_api = volume.API()

        self._last_info_volume_state_heal = 0
        self._change_since_time = None
        self.volumes_mapping_cache = {'volumes': {}, 'snapshots': {}}
        self._init_volume_mapping_cache()
        self.image_service = glance.get_default_image_service()
예제 #9
0
파일: volumes.py 프로젝트: coreycb/cinder
    def _image_uuid_from_ref(self, image_ref, context):
        # If the image ref was generated by nova api, strip image_ref
        # down to an id.
        image_uuid = None
        try:
            image_uuid = image_ref.split('/').pop()
        except AttributeError:
            msg = _("Invalid imageRef provided.")
            raise exc.HTTPBadRequest(explanation=msg)

        image_service = glance.get_default_image_service()

        # First see if this is an actual image ID
        if uuidutils.is_uuid_like(image_uuid):
            try:
                image = image_service.show(context, image_uuid)
                if 'id' in image:
                    return image['id']
            except Exception:
                # Pass and see if there is a matching image name
                pass

        # Could not find by ID, check if it is an image name
        try:
            params = {'filters': {'name': image_ref}}
            images = list(image_service.detail(context, **params))
            if len(images) > 1:
                msg = _("Multiple matches found for '%s', use an ID to be more"
                        " specific.") % image_ref
                raise exc.HTTPConflict(explanation=msg)
            for img in images:
                return img['id']
        except exc.HTTPConflict:
            raise
        except Exception:
            # Pass the other exception and let default not found error
            # handling take care of it
            pass

        msg = _("Invalid image identifier or unable to "
                "access requested image.")
        raise exc.HTTPBadRequest(explanation=msg)
예제 #10
0
파일: volumes.py 프로젝트: mahak/cinder
    def _image_uuid_from_ref(self, image_ref, context):
        # If the image ref was generated by nova api, strip image_ref
        # down to an id.
        image_uuid = None
        try:
            image_uuid = image_ref.split('/').pop()
        except AttributeError:
            msg = _("Invalid imageRef provided.")
            raise exc.HTTPBadRequest(explanation=msg)

        image_service = glance.get_default_image_service()

        # First see if this is an actual image ID
        if uuidutils.is_uuid_like(image_uuid):
            try:
                image = image_service.show(context, image_uuid)
                if 'id' in image:
                    return image['id']
            except Exception:
                # Pass and see if there is a matching image name
                pass

        # Could not find by ID, check if it is an image name
        try:
            params = {'filters': {'name': image_ref}}
            images = list(image_service.detail(context, **params))
            if len(images) > 1:
                msg = _("Multiple matches found for '%s', use an ID to be more"
                        " specific.") % image_ref
                raise exc.HTTPConflict(explanation=msg)
            for img in images:
                return img['id']
        except exc.HTTPConflict:
            raise
        except Exception:
            # Pass the other exception and let default not found error
            # handling take care of it
            pass

        msg = _("Invalid image identifier or unable to "
                "access requested image.")
        raise exc.HTTPBadRequest(explanation=msg)
예제 #11
0
 def _get_image_snapshot(self, context, image_uuid):
     image_snapshot = None
     if image_uuid:
         image_service = glance.get_default_image_service()
         image_meta = image_service.show(context, image_uuid)
         if image_meta is not None:
             bdms = image_meta.get('properties', {}).get(
                 'block_device_mapping', [])
             if bdms:
                 boot_bdm = [bdm for bdm in bdms if (
                     bdm.get('source_type') == 'snapshot' and
                     bdm.get('boot_index') == 0)]
                 if boot_bdm:
                     try:
                         image_snapshot = self.volume_api.get_snapshot(
                             context, boot_bdm[0].get('snapshot_id'))
                         return image_snapshot
                     except exception.NotFound:
                         explanation = _(
                             'Nova specific image is found, but boot '
                             'volume snapshot id:%s not found.'
                         ) % boot_bdm[0].get('snapshot_id')
                         raise exc.HTTPNotFound(explanation=explanation)
         return image_snapshot
예제 #12
0
파일: api.py 프로젝트: tek-life/cinder
 def __init__(self, db_driver=None, image_service=None):
     self.image_service = (image_service or
                           glance.get_default_image_service())
     super(API, self).__init__(db_driver)
예제 #13
0
 def __init__(self, db_driver=None, image_service=None):
     self.image_service = (image_service or
                           glance.get_default_image_service())
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
     super(API, self).__init__(db_driver)