Esempio n. 1
0
    def create(self, req, body):
        """Register a new storage device."""
        ctxt = req.environ['delfin.context']
        access_info_dict = body

        # Lock to avoid synchronous creating.
        for access in constants.ACCESS_TYPE:
            if access_info_dict.get(access) is not None:
                host = access_info_dict.get('rest').get('host')
                port = access_info_dict.get('rest').get('port')
                break
        lock_name = 'storage-create-' + host + '-' + str(port)
        coordination.synchronized(lock_name)

        if self._storage_exist(ctxt, access_info_dict):
            raise exception.StorageAlreadyExists()

        storage = self.driver_api.discover_storage(ctxt, access_info_dict)

        # Registration success, sync resource collection for this storage
        try:
            self.sync(req, storage['id'])
        except Exception as e:
            # Unexpected error occurred, while syncing resources.
            msg = _('Failed to sync resources for storage: %(storage)s. '
                    'Error: %(err)s') % {
                        'storage': storage['id'],
                        'err': e
                    }
            LOG.error(msg)
        return storage_view.build_storage(storage)
Esempio n. 2
0
    def create(self, req, body):
        """Register a new storage device."""
        ctxt = req.environ['delfin.context']
        access_info_dict = body

        # Lock to avoid synchronous creating.
        for access in constants.ACCESS_TYPE:
            if access_info_dict.get(access) is not None:
                host = access_info_dict.get(access).get('host')
                break
        lock_name = 'storage-create-' + host
        lock = coordination.Lock(lock_name)

        with lock:
            if self._storage_exist(ctxt, access_info_dict):
                raise exception.StorageAlreadyExists()
            storage = self.driver_api.discover_storage(ctxt, access_info_dict)

        # Registration success, sync resource collection for this storage
        try:
            self.sync(req, storage['id'])

            # Post registration, trigger alert sync
            self.task_rpcapi.sync_storage_alerts(ctxt,
                                                 storage['id'],
                                                 query_para=None)
        except Exception as e:
            # Unexpected error occurred, while syncing resources.
            msg = _('Failed to sync resources for storage: %(storage)s. '
                    'Error: %(err)s') % {
                        'storage': storage['id'],
                        'err': e
                    }
            LOG.error(msg)

        try:
            # Trigger Performance monitoring
            capabilities = self.driver_api.get_capabilities(
                context=ctxt, storage_id=storage['id'])
            validation.validate_capabilities(capabilities)
            perf_job_controller.create_perf_job(ctxt, storage['id'],
                                                capabilities)
        except exception.EmptyResourceMetrics:
            msg = _("Resource metric provided by capabilities is empty for "
                    "storage: %s") % storage['id']
            LOG.info(msg)
        except Exception as e:
            # Unexpected error occurred, while performance monitoring.
            msg = _('Failed to trigger performance monitoring for storage: '
                    '%(storage)s. Error: %(err)s') % {
                        'storage': storage['id'],
                        'err': six.text_type(e)
                    }
            LOG.error(msg)
        return storage_view.build_storage(storage)
Esempio n. 3
0
    def create(self, req, body):
        """Register a new storage device."""
        ctxt = req.environ['delfin.context']
        access_info_dict = body

        if self._storage_exist(ctxt, access_info_dict):
            raise exception.StorageAlreadyExists()

        storage = self.driver_api.discover_storage(ctxt, access_info_dict)

        # Registration success, sync resource collection for this storage
        try:
            self.sync(req, storage['id'])
        except Exception as e:
            # Unexpected error occurred, while syncing resources.
            msg = _('Failed to sync resources for storage: %(storage)s. '
                    'Error: %(err)s') % {
                        'storage': storage['id'],
                        'err': e
                    }
            LOG.error(msg)
        return storage_view.build_storage(storage)
Esempio n. 4
0
 def show(self, req, id):
     ctxt = req.environ['delfin.context']
     storage = db.storage_get(ctxt, id)
     return storage_view.build_storage(storage)