def sync_all(self, req): """ :param req: :return: it's a Asynchronous call. so return 202 on success. sync_all api performs the storage device info, storage_pool, volume etc. tasks on each registered storage device. """ ctxt = req.environ['delfin.context'] storages = db.storage_get_all(ctxt) LOG.debug("Total {0} registered storages found in database".format( len(storages))) resource_count = len(resources.StorageResourceTask.__subclasses__()) for storage in storages: try: _set_synced_if_ok(ctxt, storage['id'], resource_count) except exception.InvalidInput as e: LOG.warn('Can not start new sync task for %s, reason is %s' % (storage['id'], e.msg)) continue else: for subclass in \ resources.StorageResourceTask.__subclasses__(): self.task_rpcapi.sync_storage_resource( ctxt, storage['id'], subclass.__module__ + '.' + subclass.__name__)
def get_storage_from_parsed_alert(self, ctxt, storage, alert_model): # If parse_alert sets 'serial_number' or 'storage_name' in the # alert_model, we need to get corresponding storage details # from the db and fill that in alert_model storage_sn = alert_model.get('serial_number') storage_name = alert_model.get('storage_name') filters = { "vendor": storage['vendor'], "model": storage['model'], } try: if storage_sn and storage_sn != storage['serial_number']: filters['serial_number'] = storage_sn elif storage_name and storage_name != storage['name']: filters['name'] = storage_name else: return storage storage_list = db.storage_get_all(ctxt, filters=filters) if not storage_list: msg = "Failed to get destination storage for SNMP Trap. " \ "Storage with serial number {} or storage name {} " \ "not found in DB".format(storage_sn, storage_name) raise exception.AlertSourceNotFound(msg) db.alert_source_get(ctxt, storage_list[0]['id']) storage = storage_list[0] except exception.AlertSourceNotFound: LOG.info("Storage with serial number {} or name {} " "is not registered for receiving " "SNMP Trap".format(storage_sn, storage_name)) raise return storage
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_storages_search_options()) storages = db.storage_get_all(ctxt, marker, limit, sort_keys, sort_dirs, query_params, offset) return storage_view.build_storages(storages)
def check_storage_repetition(context, storage): if not storage: raise exception.StorageBackendNotFound() if not storage.get('serial_number'): msg = _("Serial number should be provided by storage.") raise exception.InvalidResults(msg) filters = dict(serial_number=storage['serial_number']) storage_list = db.storage_get_all(context, filters=filters) if storage_list: msg = (_("Failed to register storage. Reason: same serial number: " "%s detected.") % storage['serial_number']) LOG.error(msg) raise exception.StorageAlreadyExists()