From deb8b77b496c1b0fcdbe9ee8081ee5c0133ebced Mon Sep 17 00:00:00 2001 From: Setyo Nugroho Date: Tue, 1 Nov 2022 02:19:44 +0700 Subject: [PATCH] Add multi region support --- CHANGELOG.txt | 28 +++++++++++++++++++ README.md | 27 +++++++++++++++++- yuyu/core/yuyu_client.py | 9 +++++- .../templates/usage_cost/cost_tables.html | 2 +- 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 CHANGELOG.txt diff --git a/CHANGELOG.txt b/CHANGELOG.txt new file mode 100644 index 0000000..44dd81c --- /dev/null +++ b/CHANGELOG.txt @@ -0,0 +1,28 @@ +v1.0.1 +--------------------------- +- Add multi region support +- Update error message on project cost + +v1.0 +--------------------------- +- Fixing some bugs +- Upload logo for your invoice +- Add currency to overview +- Add description for setting form + + +v1.0-beta +---------------------------- +- Setting company profile +- Send invoice to email +- Notification center +- Update invoice format + + +v1.0-alpha +---------------------------- +- Price Configuration +- Project Overview +- Project Invoice +- Usage Cost +- Billing Settings diff --git a/README.md b/README.md index 5083204..def8c0c 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,35 @@ pip3 install -r requirements.txt Add this config to your horizon `local_settings.py` -```bash +```python YUYU_URL="http://yuyu_server_url:8182" CURRENCIES = ('IDR',) DEFAULT_CURRENCY = "IDR" ``` Then restart Horizon. + +## Multi Region + +If your openstack using multiple region, and each region have its own Yuyu server, you can specify Yuyu server URL for each region. + +To do that, you can add `YUYU_URL_REGION` to horizon `local_settings.py` + +`YUYU_URL_REGION` is a list of tuples which define a mapping from region name (as in horizon `AVAILABLE_REGIONS`) to Yuyu URL for each. The tuple format is ***('{{ region_name }}', 'http://{yuyu_url}')***. + +For example: + +```python +# Example AVAILABLE_REGIONS settings + +AVAILABLE_REGIONS = [ + ("https://172.12.12.10:5000/v3", 'US'), + ("https://172.12.12.11:5000/v3", 'Singapore') +] + +# Set Yuyu URL for each region +YUYU_URL_REGION = [ + ('US', 'http://region_a_yuyu_server_url:8182'), + ('Singapore', 'http://region_b_yuyu_server_url:8182'), +] +``` diff --git a/yuyu/core/yuyu_client.py b/yuyu/core/yuyu_client.py index 2bc5a0a..686fa64 100644 --- a/yuyu/core/yuyu_client.py +++ b/yuyu/core/yuyu_client.py @@ -7,7 +7,14 @@ def _get_header(request): def _yuyu_url(request, path): - return settings.YUYU_URL + "/api/" + path + yuyu_url = settings.YUYU_URL + if hasattr(settings, 'YUYU_URL_REGION'): + regions = dict(settings.YUYU_URL_REGION) + region_url = regions.get(request.session['region_name']) + if region_url: + yuyu_url = region_url + + return yuyu_url + "/api/" + path def get(request, path): diff --git a/yuyu/project/usage_cost/templates/usage_cost/cost_tables.html b/yuyu/project/usage_cost/templates/usage_cost/cost_tables.html index 8fb059b..5a19793 100644 --- a/yuyu/project/usage_cost/templates/usage_cost/cost_tables.html +++ b/yuyu/project/usage_cost/templates/usage_cost/cost_tables.html @@ -51,7 +51,7 @@ {% else %} -

Billing not enabled or you don't have any usage yet


+

You don't have any usage yet


{% endif %} {% endblock %} {% block js %}