Ejemplo n.º 1
0
    def _storage_exist(self, context, access_info):
        access_info_dict = copy.deepcopy(access_info)

        # Remove unrelated query fields
        unrelated_fields = ['username', 'password']
        for key in unrelated_fields:
            access_info_dict.pop(key)

        # Check if storage is registered
        access_info_list = db.access_info_get_all(context,
                                                  filters=access_info_dict)
        for _access_info in access_info_list:
            try:
                storage = db.storage_get(context, _access_info['storage_id'])
                if storage:
                    return True
            except exception.StorageNotFound:
                # Suppose storage was not saved successfully after access
                # information was saved in database when registering storage.
                # Therefore, removing access info if storage doesn't exist to
                # ensure the database has no residual data.
                LOG.debug("Remove residual access information.")
                db.access_info_delete(context, _access_info['storage_id'])

        return False
Ejemplo n.º 2
0
    def put(self, req, id, body):
        """Create a new alert source or update an exist one."""
        ctx = req.environ['dolphin.context']
        alert_source = body

        try:
            alert_source["storage_id"] = id
            db.storage_get(ctx, id)
            alert_source = self._input_check(alert_source)

            if self._exist(ctx, id):
                alert_source = db.alert_source_update(ctx, id, alert_source)
            else:
                alert_source = db.alert_source_create(ctx, alert_source)
        except exception.StorageNotFound as e:
            msg = (_("Alert source cannot be created or updated for a"
                     " non-existing storage %s.") % id)
            raise exc.HTTPBadRequest(explanation=msg)
        except exception.InvalidInput as e:
            raise exc.HTTPBadRequest(explanation=e.msg)

        return alert_view.build_alert_source(alert_source.to_dict())
Ejemplo n.º 3
0
 def delete(self, req, id):
     ctxt = req.environ['dolphin.context']
     try:
         storage = db.storage_get(ctxt, id)
     except exception.StorageNotFound as e:
         LOG.error(e)
         raise exc.HTTPBadRequest(explanation=e.msg)
     else:
         for subclass in task.StorageResourceTask.__subclasses__():
             self.task_rpcapi.remove_storage_resource(
                 ctxt, storage['id'],
                 subclass.__module__ + '.' + subclass.__name__)
         self.task_rpcapi.remove_storage_in_cache(ctxt, storage['id'])
Ejemplo n.º 4
0
    def process_alert_info(self, alert):
        """Fills alert model using driver manager interface."""

        ctxt = context.get_admin_context()

        # Trap source ip should be configured as part of alert source
        # configuration. Incoming source ip will be mapped with Trap source
        # ip in db and storage id will be obtained As config flow not exists
        # now Currently source ip is mapped with access_info ip address

        # First retrieve access_info from source ip and get storage info
        # using storage id
        # This is a temporary mechanism till the alert config flow is handled
        filters = {'host': alert['transport_address']}

        try:
            access_info = db.access_info_get_all(ctxt, filters=filters)
        except Exception:
            msg = "Access information could not be found with host %s." \
                    % alert['transport_address']
            raise exception.AccessInfoNotFound(message=msg)

        # For given source ip, there should be unique access_info
        if len(access_info) != 1:
            msg = "Failed to get unique access information with host %s." \
                    % alert['transport_address']
            raise exception.InvalidResults(message=msg)

        try:
            storage = db.storage_get(context, access_info[0]['storage_id'])
        except Exception:
            raise exception.StorageNotFound(id=access_info[0]['storage_id'])

        # Fill storage specific info
        alert['storage_id'] = storage['id']
        alert['storage_name'] = storage['name']
        alert['vendor'] = storage['vendor']
        alert['model'] = storage['model']

        try:
            alert_model = self.driver_manager.parse_alert(context,
                                                          storage['id'], alert)
        except Exception as e:
            LOG.error(e)
            raise exception.InvalidResults(
                message="Failed to fill the alert model from driver.")

        self._export_alert_model(alert_model)
Ejemplo n.º 5
0
    def sync(self, req, id):
        """
        :param req:
        :param id:
        :return:
        """
        # validate the id
        ctxt = req.environ['dolphin.context']
        try:
            storage = db.storage_get(ctxt, id)
        except exception.StorageNotFound as e:
            LOG.error(e)
            raise exc.HTTPNotFound(explanation=e.msg)
        else:
            for subclass in task.StorageResourceTask.__subclasses__():
                self.task_rpcapi.sync_storage_resource(
                    ctxt, storage['id'],
                    subclass.__module__ + '.' + subclass.__name__)

        return
Ejemplo n.º 6
0
 def show(self, req, id):
     try:
         storage = db.storage_get(context, id)
     except exception.StorageNotFound as e:
         raise exc.HTTPNotFound(explanation=e.message)
     return storage_view.build_storage(storage)