yuyu/README.md

175 lines
3.8 KiB
Markdown
Raw Normal View History

2022-03-18 13:04:43 +07:00
# Yuyu
2022-03-03 19:35:45 +07:00
2022-03-18 13:04:43 +07:00
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
2022-03-03 19:35:45 +07:00
2022-03-18 13:04:43 +07:00
## Yuyu API
Main component to communicate with Yuyu Dashboard.
2022-03-03 19:35:45 +07:00
2022-03-18 13:04:43 +07:00
## Yuyu Cron
2022-03-03 19:35:45 +07:00
Provide invoice calculation and rolling capabilities that needed to run every month.
2022-03-18 13:04:43 +07:00
## Yuyu Event Monitor
2022-03-03 19:35:45 +07:00
Monitor event from openstack to calculate billing spent.
# System Requirement
- Python 3
- Openstack
- Virtualenv
- Linux environment with Systemd
# Pre-Installation
### Virtualenv
2022-03-18 13:04:43 +07:00
Make sure you installed virtualenv before installing Yuyu
2022-03-03 19:35:45 +07:00
```bash
pip3 install virtualenv
```
### Openstack Service Notification
You need to enable notification for this openstack service:
2022-03-03 19:38:03 +07:00
- Nova (nova.conf)
- Cinder (cinder.conf)
- Neutron (neutron.conf)
2022-03-03 19:35:45 +07:00
### Nova
Add configuration below on `[oslo_messaging_notifications]`
```
driver = messagingv2
topics = notifications
```
2022-03-03 19:38:03 +07:00
Add configuration below on `[notifications]`
2022-03-03 19:35:45 +07:00
2022-03-04 08:06:24 +00:00
```
2022-03-03 19:35:45 +07:00
notify_on_state_change = vm_and_task_state
notification_format = unversioned
2022-03-04 08:06:24 +00:00
```
2022-03-03 19:35:45 +07:00
### Cinder & Neutron
Add configuration below on `[oslo_messaging_notifications]`
```
driver = messagingv2
topics = notifications
```
### Kolla Note
If you using Kolla, please add configuration above on all service container. For example on Nova you should put the config on `nova-api`, `nova-scheduler`, etc.
# Installation
2022-03-18 13:04:43 +07:00
Clone the latest source code and put it on any directory you want. Here i assume you put it on `/var/yuyu/`
2022-03-03 19:35:45 +07:00
```bash
2022-03-18 13:04:43 +07:00
cd /var/yuyu/
2022-03-03 19:35:45 +07:00
git clone {repository}
2022-03-18 13:04:43 +07:00
cd yuyu
2022-03-03 19:35:45 +07:00
```
Then create virtualenv and activate it
```bash
virtualenv env --python=python3.8
source env/bin/activate
pip install -r requirements.txt
```
Then create a configuration file, just copy from sample file and modify as your preference.
```bash
2022-03-18 13:04:43 +07:00
cp yuyu/local_settings.py.sample yuyu/local_settings.py
2022-03-03 19:35:45 +07:00
```
Please read [Local Setting Configuration](#local-setting-configuration) to get to know about what configuration you should change.
Then run the database migration
```bash
python manage.py migrate
```
Then create first superuser
```bash
python manage.py createsuperuser
```
## Local Setting Configuration
2022-03-18 13:04:43 +07:00
### YUYU_NOTIFICATION_URL (required)
2022-03-03 19:35:45 +07:00
A Messaging Queue URL that used by Openstack, usually it is a RabbitMQ URL.
Example:
```
2022-03-18 13:04:43 +07:00
YUYU_NOTIFICATION_URL = "rabbit://openstack:password@127.0.0.1:5672/"
2022-03-03 19:35:45 +07:00
```
2022-03-18 13:04:43 +07:00
### YUYU_NOTIFICATION_TOPICS (required)
2022-03-03 19:35:45 +07:00
A list of topic notification topic that is configured on each openstack service
Example:
```
2022-03-18 13:04:43 +07:00
YUYU_NOTIFICATION_TOPICS = ["notifications"]
2022-03-03 19:35:45 +07:00
```
### DATABASE
By default, it will use Sqlite. If you want to change it to other database please refer to Django Setting documentation.
- https://docs.djangoproject.com/en/3.2/ref/settings/#databases
- https://docs.djangoproject.com/en/3.2/ref/databases/
## API Installation
2022-03-18 13:04:43 +07:00
To install Yuyu API, you need to execute this command.
2022-03-03 19:35:45 +07:00
```bash
./bin/setup_api.sh
```
2022-03-18 13:04:43 +07:00
This will install `yuyu_api` service
2022-03-03 19:35:45 +07:00
To start the service use this command
```bash
2022-03-18 13:04:43 +07:00
systemctl enable yuyu_api
systemctl start yuyu_api
2022-03-03 19:35:45 +07:00
```
An API server will be open on port `8182`.
## Event Monitor Installation
2022-03-18 13:04:43 +07:00
To install Yuyu API, you need to execute this command.
2022-03-03 19:35:45 +07:00
```bash
2022-03-18 13:13:12 +07:00
./bin/setup_event_monitor.sh
2022-03-03 19:35:45 +07:00
```
2022-03-18 13:04:43 +07:00
This will install `yuyu_event_monitor` service
2022-03-03 19:35:45 +07:00
To start the service use this command
```bash
2022-03-18 13:04:43 +07:00
systemctl enable yuyu_event_monitor
systemctl start yuyu_event_monitor
2022-03-03 19:35:45 +07:00
```
## Cron Installation
There is a cronjob that needed to be run every month on 00:01 AM. This cronjob will finish all in progress invoice and start new invoice for the next month.
To install it, you can use `crontab -e`.
Put this expression on the crontab
```
2022-03-18 13:04:43 +07:00
1 0 1 * * $yuyu_dir/bin/process_invoice.sh
2022-03-03 19:35:45 +07:00
```
2022-03-18 13:04:43 +07:00
Replace $yuyu_dir with the directory of where yuyu is located. Example
2022-03-03 19:35:45 +07:00
```
2022-03-18 13:04:43 +07:00
1 0 1 * * /etc/yuyu/bin/process_invoice.sh
2022-03-04 08:06:24 +00:00
```