"Fossies" - the Fresh Open Source Software Archive

Member "panko-8.1.0/panko/storage/base.py" (4 Aug 2021, 4003 Bytes) of package /linux/misc/openstack/panko-8.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #
    2 # Copyright 2012 New Dream Network, LLC (DreamHost)
    3 #
    4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    5 # not use this file except in compliance with the License. You may obtain
    6 # a copy of the License at
    7 #
    8 #      http://www.apache.org/licenses/LICENSE-2.0
    9 #
   10 # Unless required by applicable law or agreed to in writing, software
   11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   13 # License for the specific language governing permissions and limitations
   14 # under the License.
   15 """Base classes for storage engines
   16 """
   17 
   18 import six
   19 
   20 import panko
   21 
   22 
   23 class Model(object):
   24     """Base class for storage API models."""
   25 
   26     def __init__(self, **kwds):
   27         self.fields = list(kwds)
   28         for k, v in six.iteritems(kwds):
   29             setattr(self, k, v)
   30 
   31     def as_dict(self):
   32         d = {}
   33         for f in self.fields:
   34             v = getattr(self, f)
   35             if isinstance(v, Model):
   36                 v = v.as_dict()
   37             elif isinstance(v, list) and v and isinstance(v[0], Model):
   38                 v = [sub.as_dict() for sub in v]
   39             d[f] = v
   40         return d
   41 
   42     def __eq__(self, other):
   43         return self.as_dict() == other.as_dict()
   44 
   45     def __ne__(self, other):
   46         return not self.__eq__(other)
   47 
   48 
   49 class Connection(object):
   50     """Base class for event storage system connections."""
   51 
   52     # A dictionary representing the capabilities of this driver.
   53     CAPABILITIES = {
   54         'events': {'query': {'simple': False}},
   55     }
   56 
   57     STORAGE_CAPABILITIES = {
   58         'storage': {'production_ready': False},
   59     }
   60 
   61     @staticmethod
   62     def __init__(url, conf):
   63         pass
   64 
   65     @staticmethod
   66     def upgrade():
   67         """Migrate the database to `version` or the most recent version."""
   68 
   69     @staticmethod
   70     def clear():
   71         """Clear database."""
   72 
   73     @staticmethod
   74     def record_events(events):
   75         """Write the events to the backend storage system.
   76 
   77         :param events: a list of model.Event objects.
   78         """
   79         raise panko.NotImplementedError('Events not implemented.')
   80 
   81     @staticmethod
   82     def get_events(event_filter, pagination=None):
   83         """Return an iterable of model.Event objects."""
   84 
   85     @staticmethod
   86     def get_event_types():
   87         """Return all event types as an iterable of strings."""
   88         raise panko.NotImplementedError('Events not implemented.')
   89 
   90     @staticmethod
   91     def get_trait_types(event_type):
   92         """Return a dictionary containing the name and data type of the trait.
   93 
   94         Only trait types for the provided event_type are
   95         returned.
   96         :param event_type: the type of the Event
   97         """
   98         raise panko.NotImplementedError('Events not implemented.')
   99 
  100     @staticmethod
  101     def get_traits(event_type, trait_type=None):
  102         """Return all trait instances associated with an event_type.
  103 
  104         If trait_type is specified, only return instances of that trait type.
  105         :param event_type: the type of the Event to filter by
  106         :param trait_type: the name of the Trait to filter by
  107         """
  108 
  109         raise panko.NotImplementedError('Events not implemented.')
  110 
  111     @classmethod
  112     def get_capabilities(cls):
  113         """Return an dictionary with the capabilities of each driver."""
  114         return cls.CAPABILITIES
  115 
  116     @classmethod
  117     def get_storage_capabilities(cls):
  118         """Return a dictionary representing the performance capabilities.
  119 
  120         This is needed to evaluate the performance of each driver.
  121         """
  122         return cls.STORAGE_CAPABILITIES
  123 
  124     @staticmethod
  125     def clear_expired_data(ttl, max_count=None):
  126         """Clear expired data from the backend storage system.
  127 
  128         Clearing occurs according to the time-to-live.
  129         :param ttl: Number of seconds to keep records for.
  130         :param max_count: Number of records to delete.
  131         """
  132         raise panko.NotImplementedError('Clearing events not implemented')