Storage backend (v2)¶
Warning
This backend is considered unstable and should be used for upstream development only.
In order to implement a storage backend for cloudkitty, you’ll have to implement the following abstract class:
- class cloudkitty.storage.v2.BaseStorage(*args, **kwargs)[source]¶
Abstract class for v2 storage objects.
- abstract delete(begin=None, end=None, filters=None)[source]¶
Deletes all data from for the given period and filters.
- Parameters:
begin (datetime) – Start date
end (datetime) – End date
filters (dict) – Attributes to filter on. ex: {‘flavor_id’: ‘42’}
- static get_retention()[source]¶
Returns the retention period defined in the configuration.
- Return type:
datetime.timedelta
- abstract push(dataframes, scope_id=None)[source]¶
Pushes dataframes to the storage backend
- Parameters:
dataframes ([cloudkitty.dataframe.DataFrame]) – List of dataframes
- abstract retrieve(begin=None, end=None, filters=None, metric_types=None, offset=0, limit=1000, paginate=True)[source]¶
Returns the following dict:
{ 'total': int, # total amount of measures found 'dataframes': list of dataframes, }
- Parameters:
begin (datetime) – Start date
end (datetime) – End date
filters (dict) – Attributes to filter on. ex: {‘flavor_id’: ‘42’}
metric_types (str or list) – Metric type to filter on.
offset (int) – Offset for pagination
limit (int) – Maximum amount of elements to return
paginate (bool) – Defaults to True. If False, all found results will be returned.
- Return type:
dict
- abstract total(groupby=None, begin=None, end=None, metric_types=None, filters=None, custom_fields=None, offset=0, limit=1000, paginate=True)[source]¶
Returns a grouped total for given groupby.
- Parameters:
groupby (list of strings) – Attributes on which to group by. These attributes must be part of the ‘groupby’ section for the given metric type in metrics.yml. In order to group by metric type, add ‘type’ to the groupby list.
begin (datetime) – Start date
end (datetime) – End date
metric_types (str or list) – Metric type to filter on.
custom_fields – the custom fields that one desires to add in the summary reporting. Each driver must handle these values by themselves.
filters (dict) – Attributes to filter on. ex: {‘flavor_id’: ‘42’}
offset (int) – Offset for pagination
limit (int) – Maximum amount of elements to return
paginate (bool) – Defaults to True. If False, all found results will be returned.
- Type:
custom_fields: list of strings
- Return type:
dict
Returns a dict with the following format:
{ 'total': int, # total amount of results found 'results': list of results, }
Each result has the following format:
{ 'begin': XXX, 'end': XXX, 'rate': XXX, 'groupby1': XXX, 'groupby2': XXX }
You’ll then need to register an entrypoint corresponding to your storage
backend in the cloudkitty.storage.v2.backends
section of the setup.cfg
file.