Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cloudkittydashboard/dashboards/admin/summary/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@
# License for the specific language governing permissions and limitations
# under the License.

from django.conf import settings
from django.utils.translation import gettext_lazy as _
from horizon import tables

from openstack_dashboard.api import keystone as api_keystone

from cloudkittydashboard.api import cloudkitty as api
from cloudkittydashboard.dashboards.admin.summary import tables as sum_tables
from cloudkittydashboard import utils

rate_prefix = getattr(settings,
'OPENSTACK_CLOUDKITTY_RATE_PREFIX', None)
rate_postfix = getattr(settings,
'OPENSTACK_CLOUDKITTY_RATE_POSTFIX', None)


class IndexView(tables.DataTableView):
Expand All @@ -39,6 +46,9 @@ def get_data(self):
for tenant in summary:
tenant['name'] = tenants.get(tenant.id, '-')
summary[-1]['name'] = 'Cloud Total'
for tenant in summary:
tenant['rate'] = utils.formatRate(tenant['rate'],
rate_prefix, rate_postfix)
return summary


Expand All @@ -65,4 +75,7 @@ def get_data(self):
'rate': sum([float(item['rate']) for item in summary]),
})
summary = api.identify(summary, key='res_type', name=True)
for item in summary:
item['rate'] = utils.formatRate(item['rate'],
rate_prefix, rate_postfix)
return summary
9 changes: 9 additions & 0 deletions cloudkittydashboard/dashboards/project/rating/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
from cloudkittydashboard.api import cloudkitty as api
from cloudkittydashboard.dashboards.project.rating \
import tables as rating_tables
from cloudkittydashboard import utils

rate_prefix = getattr(settings,
'OPENSTACK_CLOUDKITTY_RATE_PREFIX', None)
rate_postfix = getattr(settings,
'OPENSTACK_CLOUDKITTY_RATE_POSTFIX', None)


class IndexView(tables.DataTableView):
Expand All @@ -38,6 +44,9 @@ def get_data(self):
total = sum([r.get('rate') for r in data])

data.append({'type': 'TOTAL', 'rate': total})
for item in data:
item['rate'] = utils.formatRate(item['rate'],
rate_prefix, rate_postfix)
return data


Expand Down
9 changes: 9 additions & 0 deletions cloudkittydashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ def __getattr__(self, key):

def __setattr__(self, key, val):
self[key] = val


def formatRate(rate: float, prefix: str, postfix: str) -> str:
rate = str(rate)
if prefix:
rate = prefix + rate
if postfix:
rate = rate + postfix
return rate
34 changes: 34 additions & 0 deletions doc/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,37 @@ For more detailed information about CloudKitty installation check out the


.. _installation section: https://cloudkitty.readthedocs.org/en/latest/installation.html


Configuration
=============

To configure CloudKitty dashboard, add variables to your Horizon settings
file.
For more details about how to add variables to Horizon settings checkout the
`Horizon Settings Reference documentation`_.


.. _Horizon Settings Reference documentation: https://docs.openstack.org/horizon/latest/configuration/settings.html

Rate Pre/Postfix
----------------

You can configure pre/postfix to rate vaules shown at the dashboard.

Here's example of setting rate currency to US Dollar.

.. code-block:: python

# You can choose to have prefix or postfix or both.
# Prefix and postfix are not mutally exclusive.
OPENSTACK_CLOUDKITTY_RATE_PREFIX = '$'
OPENSTACK_CLOUDKITTY_RATE_POSTFIX = 'USD'

Some symbols (Such as Non-ASCII) might require to use unicode value directly.

.. code-block:: python

# British Pound
OPENSTACK_CLOUDKITTY_RATE_PREFIX = u'\xA3'
OPENSTACK_CLOUDKITTY_RATE_POSTFIX = 'GBP'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
features:
- |
Adds optional Horizon settings variable OPENSTACK_CLOUDKITTY_RATE_PREFIX
and OPENSTACK_CLOUDKITTY_RATE_POSTFIX. These allow users to attach
pre/postfix to their rate vaules shown at the dashboard such as currency.
These values can be set in ``.py`` settings snippets under
``openstack_dashboard/local/local_settings.d`` directory. Follow
https://docs.openstack.org/horizon/latest/configuration/settings.html
for more details.