Exemple #1
0
    def sync(self):
        """
        :return:
        """
        LOG.info('Syncing controllers for storage id:{0}'.format(
            self.storage_id))
        try:
            # collect the controllers list from driver and database
            storage_controllers = self.driver_api.list_controllers(
                self.context, self.storage_id)
            db_controllers = db.controller_get_all(
                self.context, filters={"storage_id": self.storage_id})

            add_list, update_list, delete_id_list = self._classify_resources(
                storage_controllers, db_controllers, 'native_controller_id')

            LOG.info('###StorageControllerTask for {0}:add={1},delete={2},'
                     'update={3}'.format(self.storage_id, len(add_list),
                                         len(delete_id_list),
                                         len(update_list)))
            if delete_id_list:
                db.controllers_delete(self.context, delete_id_list)

            if update_list:
                db.controllers_update(self.context, update_list)

            if add_list:
                db.controllers_create(self.context, add_list)
        except AttributeError as e:
            LOG.error(e)
        except Exception as e:
            msg = _('Failed to sync controllers entry in DB: {0}'.format(e))
            LOG.error(msg)
        else:
            LOG.info("Syncing controllers successful!!!")
Exemple #2
0
    def _cb_fun(self, state_reference, context_engine_id, context_name,
                var_binds, cb_ctx):
        """Callback function to process the incoming trap."""
        exec_context = self.snmp_engine.observer.getExecutionContext(
            'rfc3412.receiveMessage:request')
        LOG.debug("Get notification from: %s" %
                  "#".join([str(x) for x in exec_context['transportAddress']]))
        alert = {}

        try:
            # transportAddress contains both ip and port, extract ip address
            source_ip = exec_context['transportAddress'][0]
            alert_source = self._get_alert_source_by_host(source_ip)

            # In case of non v3 version, community string is used to map the
            # trap. Pysnmp library helps to filter traps whose community string
            # are not configured. But if a given community name x is configured
            # for storage1, if the trap is received with x from storage 2,
            # library will allow the trap. So for non v3 version, we need to
            # verify that community name is configured at alert source db for
            # the storage which is sending traps.
            # context_name contains the incoming community string value
            if exec_context['securityModel'] != constants.SNMP_V3_INT \
                    and cryptor.decode(alert_source['community_string']) \
                    != str(context_name):
                msg = (_("Community string not matching with alert source %s, "
                         "dropping it.") % source_ip)
                raise exception.InvalidResults(msg)

            for oid, val in var_binds:
                # Fill raw oid and values
                oid_str = str(oid)
                alert[oid_str] = str(val)

            # Fill additional info to alert info
            alert['transport_address'] = source_ip
            alert['storage_id'] = alert_source['storage_id']
            filters = {
                'mgmt_ip': source_ip,
                'storage_id': alert_source['storage_id']
            }
            ctxt = context.RequestContext()
            controllers = db.controller_get_all(ctxt, filters=filters)
            if controllers:
                alert['controller_name'] = controllers[0].get('name')

            # Handover to alert processor for model translation and export
            self.alert_processor.process_alert_info(alert)
        except exception.DelfinException as e:
            # Log and end the trap processing error flow
            err_msg = _("Failed to process alert report (%s).") % e.msg
            LOG.exception(err_msg)
        except Exception as e:
            err_msg = six.text_type(e)
            LOG.exception(err_msg)
Exemple #3
0
    def index(self, req):
        ctxt = req.environ['delfin.context']
        query_params = {}
        query_params.update(req.GET)
        # update options  other than filters
        sort_keys, sort_dirs = api_utils.get_sort_params(query_params)
        marker, limit, offset = api_utils.get_pagination_params(query_params)
        # strip out options except supported search  options
        api_utils.remove_invalid_options(
            ctxt, query_params, self._get_controllers_search_options())

        controllers = db.controller_get_all(ctxt, marker, limit, sort_keys,
                                            sort_dirs, query_params, offset)
        return controller_view.build_controllers(controllers)
Exemple #4
0
 def db_resource_get_all(self, filters):
     return db.controller_get_all(self.context, filters=filters)