panko  8.1.0
About: OpenStack Panko is an event storage service and REST API for Ceilometer.
The "Ussuri" series (maintained release).
  Fossies Dox: panko-8.1.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

base.py
Go to the documentation of this file.
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
18import six
19
20import panko
21
22
23class Model(object):
24 """Base class for storage API models."""
25
26 def __init__(self, **kwds):
27 self.fieldsfields = 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.fieldsfields:
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_dictas_dict() == other.as_dict()
44
45 def __ne__(self, other):
46 return not self.__eq____eq__(other)
47
48
49class 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
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
113 """Return an dictionary with the capabilities of each driver."""
114 return cls.CAPABILITIESCAPABILITIES
115
116 @classmethod
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_CAPABILITIESSTORAGE_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')
dictionary STORAGE_CAPABILITIES
Definition: base.py:57
def get_events(event_filter, pagination=None)
Definition: base.py:82
def record_events(events)
Definition: base.py:74
def get_trait_types(event_type)
Definition: base.py:91
dictionary CAPABILITIES
Definition: base.py:53
def get_storage_capabilities(cls)
Definition: base.py:117
def __init__(url, conf)
Definition: base.py:62
def clear_expired_data(ttl, max_count=None)
Definition: base.py:125
def get_traits(event_type, trait_type=None)
Definition: base.py:101
def as_dict(self)
Definition: base.py:31
def __eq__(self, other)
Definition: base.py:42
def __ne__(self, other)
Definition: base.py:45
def __init__(self, **kwds)
Definition: base.py:26