project YuYu
This commit is contained in:
parent
185d7484bb
commit
41c8be93a0
21 changed files with 103 additions and 88 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -45,6 +45,7 @@ share/python-wheels/
|
|||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
logs/*
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
|
|
52
README.md
52
README.md
|
@ -1,15 +1,15 @@
|
|||
|
||||
# Rintik
|
||||
# Yuyu
|
||||
|
||||
Rintik provide ability to manage openstack billing by listening to every openstack event. Rintik is a required component to use Rintik Dashboard. There are 3 main component in Rintik: API, Cron, Event Monitor
|
||||
Yuyu provide ability to manage openstack billing by listening to every openstack event. Yuyu is a required component to use Yuyu Dashboard. There are 3 main component in Yuyu: API, Cron, Event Monitor
|
||||
|
||||
## Rintik API
|
||||
Main component to communicate with Rintik Dashboard.
|
||||
## Yuyu API
|
||||
Main component to communicate with Yuyu Dashboard.
|
||||
|
||||
## Rintik Cron
|
||||
## Yuyu Cron
|
||||
Provide invoice calculation and rolling capabilities that needed to run every month.
|
||||
|
||||
## Rintik Event Monitor
|
||||
## Yuyu Event Monitor
|
||||
Monitor event from openstack to calculate billing spent.
|
||||
|
||||
# System Requirement
|
||||
|
@ -21,7 +21,7 @@ Monitor event from openstack to calculate billing spent.
|
|||
# Pre-Installation
|
||||
|
||||
### Virtualenv
|
||||
Make sure you installed virtualenv before installing Rintik
|
||||
Make sure you installed virtualenv before installing Yuyu
|
||||
|
||||
```bash
|
||||
pip3 install virtualenv
|
||||
|
@ -62,12 +62,12 @@ If you using Kolla, please add configuration above on all service container. For
|
|||
|
||||
# Installation
|
||||
|
||||
Clone the latest source code and put it on any directory you want. Here i assume you put it on `/var/rintik/`
|
||||
Clone the latest source code and put it on any directory you want. Here i assume you put it on `/var/yuyu/`
|
||||
|
||||
```bash
|
||||
cd /var/rintik/
|
||||
cd /var/yuyu/
|
||||
git clone {repository}
|
||||
cd rintik
|
||||
cd yuyu
|
||||
```
|
||||
|
||||
Then create virtualenv and activate it
|
||||
|
@ -80,7 +80,7 @@ pip install -r requirements.txt
|
|||
Then create a configuration file, just copy from sample file and modify as your preference.
|
||||
|
||||
```bash
|
||||
cp core/local_settings.py.sample core/local_settings.py
|
||||
cp yuyu/local_settings.py.sample yuyu/local_settings.py
|
||||
```
|
||||
|
||||
Please read [Local Setting Configuration](#local-setting-configuration) to get to know about what configuration you should change.
|
||||
|
@ -99,20 +99,20 @@ python manage.py createsuperuser
|
|||
|
||||
## Local Setting Configuration
|
||||
|
||||
### RINTIK_NOTIFICATION_URL (required)
|
||||
### YUYU_NOTIFICATION_URL (required)
|
||||
A Messaging Queue URL that used by Openstack, usually it is a RabbitMQ URL.
|
||||
|
||||
Example:
|
||||
```
|
||||
RINTIK_NOTIFICATION_URL = "rabbit://openstack:password@127.0.0.1:5672/"
|
||||
YUYU_NOTIFICATION_URL = "rabbit://openstack:password@127.0.0.1:5672/"
|
||||
```
|
||||
|
||||
### RINTIK_NOTIFICATION_TOPICS (required)
|
||||
### YUYU_NOTIFICATION_TOPICS (required)
|
||||
A list of topic notification topic that is configured on each openstack service
|
||||
|
||||
Example:
|
||||
```
|
||||
RINTIK_NOTIFICATION_TOPICS = ["notifications"]
|
||||
YUYU_NOTIFICATION_TOPICS = ["notifications"]
|
||||
```
|
||||
|
||||
|
||||
|
@ -124,37 +124,37 @@ By default, it will use Sqlite. If you want to change it to other database pleas
|
|||
|
||||
## API Installation
|
||||
|
||||
To install Rintik API, you need to execute this command.
|
||||
To install Yuyu API, you need to execute this command.
|
||||
|
||||
```bash
|
||||
./bin/setup_api.sh
|
||||
```
|
||||
|
||||
This will install `rintik_api` service
|
||||
This will install `yuyu_api` service
|
||||
|
||||
To start the service use this command
|
||||
```bash
|
||||
systemctl enable rintik_api
|
||||
systemctl start rintik_api
|
||||
systemctl enable yuyu_api
|
||||
systemctl start yuyu_api
|
||||
```
|
||||
|
||||
An API server will be open on port `8182`.
|
||||
|
||||
## Event Monitor Installation
|
||||
|
||||
To install Rintik API, you need to execute this command.
|
||||
To install Yuyu API, you need to execute this command.
|
||||
|
||||
```bash
|
||||
./bin/setup_event_montor.sh
|
||||
```
|
||||
|
||||
|
||||
This will install `rintik_event_monitor` service
|
||||
This will install `yuyu_event_monitor` service
|
||||
|
||||
To start the service use this command
|
||||
```bash
|
||||
systemctl enable rintik_event_monitor
|
||||
systemctl start rintik_event_monitor
|
||||
systemctl enable yuyu_event_monitor
|
||||
systemctl start yuyu_event_monitor
|
||||
```
|
||||
|
||||
## Cron Installation
|
||||
|
@ -166,10 +166,10 @@ To install it, you can use `crontab -e`.
|
|||
Put this expression on the crontab
|
||||
|
||||
```
|
||||
1 0 1 * * $rintik_dir/bin/process_invoice.sh
|
||||
1 0 1 * * $yuyu_dir/bin/process_invoice.sh
|
||||
```
|
||||
|
||||
Replace $rintik_dir with the directory of where rintik is located. Example
|
||||
Replace $yuyu_dir with the directory of where yuyu is located. Example
|
||||
```
|
||||
1 0 1 * * /etc/rintik/bin/process_invoice.sh
|
||||
1 0 1 * * /etc/yuyu/bin/process_invoice.sh
|
||||
```
|
|
@ -31,6 +31,8 @@ def generate_invoice_component_serializer(model):
|
|||
class InvoiceSerializer(serializers.ModelSerializer):
|
||||
subtotal = MoneyField(max_digits=10, decimal_places=0)
|
||||
subtotal_currency = serializers.CharField(source="subtotal.currency")
|
||||
total = MoneyField(max_digits=10, decimal_places=0)
|
||||
total_currency = serializers.CharField(source="total.currency")
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
@ -45,7 +47,10 @@ class InvoiceSerializer(serializers.ModelSerializer):
|
|||
class SimpleInvoiceSerializer(serializers.ModelSerializer):
|
||||
subtotal = MoneyField(max_digits=10, decimal_places=0)
|
||||
subtotal_currency = serializers.CharField(source="subtotal.currency")
|
||||
total = MoneyField(max_digits=10, decimal_places=0)
|
||||
total_currency = serializers.CharField(source="total.currency")
|
||||
|
||||
class Meta:
|
||||
model = Invoice
|
||||
fields = ['id', 'start_date', 'end_date', 'state', 'tax', 'subtotal', 'subtotal_currency', 'total']
|
||||
fields = ['id', 'start_date', 'end_date', 'state', 'tax', 'subtotal', 'subtotal_currency', 'total',
|
||||
'total_currency']
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "Installing Rintik API Service"
|
||||
rintik_dir=`pwd -P`
|
||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
cd $SCRIPT_DIR || exit
|
||||
cd ..
|
||||
|
||||
echo "Riktik dir is $rintik_dir"
|
||||
echo "Installing Yuyu API Service"
|
||||
yuyu_dir=`pwd -P`
|
||||
|
||||
rintik_dir_sub=${rintik_dir//\//\\\/}
|
||||
sed "s/{{rintik_dir}}/$rintik_dir_sub/g" "$rintik_dir"/script/rintik_api.service > /etc/systemd/system/rintik_api.service
|
||||
echo "Yuyu dir is $yuyu_dir"
|
||||
|
||||
echo "Rintik API Service Installed on /etc/systemd/system/rintik_api.service"
|
||||
echo "Done! you can enable Rintik API with systemctl start rintik_api"
|
||||
yuyu_dir_sub=${yuyu_dir//\//\\\/}
|
||||
sed "s/{{yuyu_dir}}/$yuyu_dir_sub/g" "$yuyu_dir"/script/yuyu_api.service > /etc/systemd/system/yuyu_api.service
|
||||
|
||||
echo "Yuyu API Service Installed on /etc/systemd/system/yuyu_api.service"
|
||||
echo "Done! you can enable Yuyu API with systemctl start yuyu_api"
|
|
@ -1,12 +1,17 @@
|
|||
#!/bin/bash
|
||||
|
||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
cd $SCRIPT_DIR || exit
|
||||
cd ..
|
||||
|
||||
|
||||
echo "Installing Rintik API Service"
|
||||
rintik_dir=`pwd -P`
|
||||
yuyu_dir=`pwd -P`
|
||||
|
||||
echo "Riktik dir is $rintik_dir"
|
||||
echo "Riktik dir is $yuyu_dir"
|
||||
|
||||
rintik_dir_sub=${rintik_dir//\//\\\/}
|
||||
sed "s/{{rintik_dir}}/$rintik_dir_sub/g" "$rintik_dir"/script/rintik_event_monitor.service > /etc/systemd/system/rintik_event_monitor.service
|
||||
yuyu_dir_sub=${yuyu_dir//\//\\\/}
|
||||
sed "s/{{yuyu_dir}}/$yuyu_dir_sub/g" "$yuyu_dir"/script/yuyu_event_monitor.service > /etc/systemd/system/yuyu_event_monitor.service
|
||||
|
||||
echo "Rintik API Service Installed on /etc/systemd/system/rintik_event_monitor.service"
|
||||
echo "Done! you can enable Rintik API with systemctl start rintik_event_monitor"
|
||||
echo "Yuyu API Service Installed on /etc/systemd/system/yuyu_event_monitor.service"
|
||||
echo "Done! you can enable Rintik API with systemctl start yuyu_event_monitor"
|
|
@ -5,7 +5,7 @@ from oslo_messaging import NotificationResult
|
|||
from core.component import component
|
||||
from core.utils.dynamic_setting import get_dynamic_settings, BILLING_ENABLED, get_dynamic_setting
|
||||
|
||||
LOG = logging.getLogger("rintik_notification")
|
||||
LOG = logging.getLogger("yuyu_notification")
|
||||
|
||||
|
||||
class EventEndpoint(object):
|
||||
|
|
|
@ -12,7 +12,7 @@ from django.core.management.base import BaseCommand
|
|||
|
||||
from core.event_endpoint import EventEndpoint
|
||||
|
||||
LOG = logging.getLogger("rintik_notification")
|
||||
LOG = logging.getLogger("yuyu_notification")
|
||||
|
||||
|
||||
class SignalExit(SystemExit):
|
||||
|
@ -22,7 +22,7 @@ class SignalExit(SystemExit):
|
|||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Start Rintik Event Monitor'
|
||||
help = 'Start Yuyu Event Monitor'
|
||||
|
||||
def signal_handler(self, signum, frame):
|
||||
raise SignalExit(signum)
|
||||
|
@ -53,19 +53,19 @@ class Command(BaseCommand):
|
|||
self.run_server(transport, server)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
url = settings.RINTIK_NOTIFICATION_URL
|
||||
url = settings.YUYU_NOTIFICATION_URL
|
||||
transport = messaging.get_notification_transport(cfg.CONF,
|
||||
url=url)
|
||||
|
||||
# oslo.config defaults
|
||||
cfg.CONF.heartbeat_interval = 5
|
||||
cfg.CONF.prog = os.path.basename(__file__)
|
||||
cfg.CONF.project = 'rintik'
|
||||
cfg.CONF.project = 'yuyu'
|
||||
|
||||
signal.signal(signal.SIGTERM, self.signal_handler)
|
||||
signal.signal(signal.SIGINT, self.signal_handler)
|
||||
|
||||
self.notify_server(
|
||||
transport=transport,
|
||||
topics=settings.RINTIK_NOTIFICATION_TOPICS,
|
||||
topics=settings.YUYU_NOTIFICATION_TOPICS,
|
||||
)
|
||||
|
|
|
@ -8,11 +8,11 @@ from core.models import Invoice, InvoiceComponentMixin
|
|||
from core.component import component, labels
|
||||
from core.utils.dynamic_setting import get_dynamic_setting, BILLING_ENABLED, INVOICE_TAX
|
||||
|
||||
LOG = logging.getLogger("rintik_new_invoice")
|
||||
LOG = logging.getLogger("yuyu_new_invoice")
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Rintik New Invoice'
|
||||
help = 'Yuyu New Invoice'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
print("Processing Invoice")
|
||||
|
|
|
@ -6,7 +6,7 @@ import sys
|
|||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rintik.settings')
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'yuyu.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
RINTIK_NOTIFICATION_URL = "rabbit://openstack:password@127.0.0.1:5672/"
|
||||
RINTIK_NOTIFICATION_TOPICS = ["notifications"]
|
||||
|
||||
# Currency Configuration
|
||||
CURRENCIES = ('IDR', 'USD')
|
||||
DEFAULT_CURRENCY = "IDR"
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
[Unit]
|
||||
Description=rintik api daemon
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
Group=root
|
||||
WorkingDirectory={{rintik_dir}}
|
||||
ExecStart={{rintik_dir}}/env/bin/gunicorn rintik.wsgi --workers 2 --bind 127.0.0.1:8000 --log-file=logs/gunicorn.log
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -1,12 +0,0 @@
|
|||
[Unit]
|
||||
Description=rintik event monitor daemon
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
Group=root
|
||||
WorkingDirectory={{rintik_dir}}
|
||||
ExecStart={{rintik_dir}}/env/bin/python manage.py event_monitor
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
12
script/yuyu_api.service
Normal file
12
script/yuyu_api.service
Normal file
|
@ -0,0 +1,12 @@
|
|||
[Unit]
|
||||
Description=yuyu api daemon
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
Group=root
|
||||
WorkingDirectory={{yuyu_dir}}
|
||||
ExecStart={{yuyu_dir}}/env/bin/gunicorn yuyu.wsgi --workers 2 --bind 127.0.0.1:8182 --log-file=logs/gunicorn.log
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
12
script/yuyu_event_monitor.service
Normal file
12
script/yuyu_event_monitor.service
Normal file
|
@ -0,0 +1,12 @@
|
|||
[Unit]
|
||||
Description=yuyu event monitor daemon
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
Group=root
|
||||
WorkingDirectory={{yuyu_dir}}
|
||||
ExecStart={{yuyu_dir}}/env/bin/python manage.py event_monitor
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
0
yuyu/__init__.py
Normal file
0
yuyu/__init__.py
Normal file
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
ASGI config for rintik project.
|
||||
ASGI config for yuyu project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
|
@ -11,6 +11,6 @@ import os
|
|||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rintik.settings')
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'yuyu.settings')
|
||||
|
||||
application = get_asgi_application()
|
7
yuyu/local_settings.py.sample
Normal file
7
yuyu/local_settings.py.sample
Normal file
|
@ -0,0 +1,7 @@
|
|||
YUYU_NOTIFICATION_URL = "rabbit://openstack:password@127.0.0.1:5672/"
|
||||
YUYU_NOTIFICATION_TOPICS = ["notifications"]
|
||||
|
||||
# Currency Configuration
|
||||
CURRENCIES = ('IDR', 'USD')
|
||||
DEFAULT_CURRENCY = "IDR"
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Django settings for rintik project.
|
||||
Django settings for yuyu project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 3.2.6.
|
||||
|
||||
|
@ -53,7 +53,7 @@ MIDDLEWARE = [
|
|||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'rintik.urls'
|
||||
ROOT_URLCONF = 'yuyu.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
|
@ -72,7 +72,7 @@ TEMPLATES = [
|
|||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'rintik.wsgi.application'
|
||||
WSGI_APPLICATION = 'yuyu.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
|
@ -1,4 +1,4 @@
|
|||
"""rintik URL Configuration
|
||||
"""yuyu URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/3.2/topics/http/urls/
|
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
WSGI config for rintik project.
|
||||
WSGI config for yuyu project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
|
@ -11,6 +11,6 @@ import os
|
|||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rintik.settings')
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'yuyu.settings')
|
||||
|
||||
application = get_wsgi_application()
|
Loading…
Add table
Reference in a new issue