Ubuntu 22.04
Sponsored Link

OpenStack Zed : How to use CloudKitty2022/10/19

 
This is how to use OpenStack Rating Service (CloudKitty).
This example is based on the environment like follows.
------------+-----------------------------+-----------------------------+------------
            |                             |                             |
        eth0|10.0.0.30                eth0|10.0.0.50                eth0|10.0.0.51
+-----------+-----------+     +-----------+-----------+     +-----------+-----------+
|   [ dlp.srv.world ]   |     | [ network.srv.world ] |     |  [ node01.srv.world ] |
|     (Control Node)    |     |     (Network Node)    |     |     (Compute Node)    |
|                       |     |                       |     |                       |
|  MariaDB    RabbitMQ  |     |      Open vSwitch     |     |        Libvirt        |
|  Memcached  Nginx     |     |     Neutron Server    |     |      Nova Compute     |
|  Keystone   httpd     |     |      OVN-Northd       |     |      Open vSwitch     |
|  Glance     Nova API  |     |  Nginx  iSCSI Target  |     |   OVN Metadata Agent  |
|  Cinder API           |     |     Cinder Volume     |     |     OVN-Controller    |
|                       |     |     Gnocchi httpd     |     |   Ceilometer Compute  |
|                       |     |   Ceilometer Central  |     |                       |
|                       |     |     CloudKitty API    |     |                       |
+-----------------------+     +-----------------------+     +-----------------------+

[1] Add [cloudkitty] user in [rating] role for each project rated.
root@dlp ~(keystone)#
openstack project list

+----------------------------------+-----------+
| ID                               | Name      |
+----------------------------------+-----------+
| 231a529f51394426b07c56f2c5ec580e | admin     |
| 4dd1e1f6bac441ff9c77002c3ab4c58a | hiroshima |
| ee51c09c765e4a4d958c2bcc4dbb5665 | service   |
+----------------------------------+-----------+

root@dlp ~(keystone)#
openstack role add --user cloudkitty --project hiroshima rating

[2] Enable [Hashmap] module.
root@dlp ~(keystone)#
openstack rating module list

+-----------+---------+----------+
| Module    | Enabled | Priority |
+-----------+---------+----------+
| hashmap   | False   |        1 |
| noop      | True    |        1 |
| pyscripts | False   |        1 |
+-----------+---------+----------+

root@dlp ~(keystone)#
openstack rating module enable hashmap

+---------+---------+----------+
| Module  | Enabled | Priority |
+---------+---------+----------+
| hashmap | True    |        1 |
+---------+---------+----------+

root@dlp ~(keystone)#
openstack rating module list

+-----------+---------+----------+
| Module    | Enabled | Priority |
+-----------+---------+----------+
| hashmap   | True    |        1 |
| noop      | True    |        1 |
| pyscripts | False   |        1 |
+-----------+---------+----------+
[3] Set rate to Instance Uptime.
When users in the project set on [1] create and start instances with [flavor_id] you set, target project is charged at the rate you set every interval of the [period] you set in [cloudkitty.conf].
# add service matching rule

root@dlp ~(keystone)#
openstack rating hashmap service create instance

+----------+--------------------------------------+
| Name     | Service ID                           |
+----------+--------------------------------------+
| instance | 8e038b68-3457-4745-83a0-2688535ccfb7 |
+----------+--------------------------------------+

# add field matching rule

root@dlp ~(keystone)#
openstack rating hashmap field create 8e038b68-3457-4745-83a0-2688535ccfb7 flavor_id

+-----------+--------------------------------------+--------------------------------------+
| Name      | Field ID                             | Service ID                           |
+-----------+--------------------------------------+--------------------------------------+
| flavor_id | 379e680e-8a1d-440e-b3a7-bb3136b48c48 | 8e038b68-3457-4745-83a0-2688535ccfb7 |
+-----------+--------------------------------------+--------------------------------------+

root@dlp ~(keystone)#
openstack flavor list

+----+----------+------+------+-----------+-------+-----------+
| ID | Name     |  RAM | Disk | Ephemeral | VCPUs | Is Public |
+----+----------+------+------+-----------+-------+-----------+
| 0  | m1.small | 2048 |   10 |         0 |     1 | True      |
+----+----------+------+------+-----------+-------+-----------+

# add mapping rule
# set a cost of [0.5] to instances with [flavor_id] = [0]
root@dlp ~(keystone)# openstack rating hashmap mapping create 0.5 \
--field-id 379e680e-8a1d-440e-b3a7-bb3136b48c48 \
--value 0 -t flat 
+--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+
| Mapping ID                           | Value | Cost                           | Type | Field ID                             | Service ID | Group ID | Project ID |
+--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+
| 33582a2a-bc4b-40de-a956-d3ed67c29dab | 0     | 0.5000000000000000000000000000 | flat | 379e680e-8a1d-440e-b3a7-bb3136b48c48 | None       | None     | None       |
+--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+
[4] Verify settings with an user who is in the project you set on [1] to create or start an instance.
ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+-------------+---------+-------------------------------------+------------+----------+
| ID                                   | Name        | Status  | Networks                            | Image      | Flavor   |
+--------------------------------------+-------------+---------+-------------------------------------+------------+----------+
| a456ee32-b105-4c5e-8eae-ddccb48f913e | Ubuntu-2204 | SHUTOFF | private=10.0.0.228, 192.168.100.187 | Ubuntu2204 | m1.small |
+--------------------------------------+-------------+---------+-------------------------------------+------------+----------+
ubuntu@dlp ~(keystone)$
openstack server start Ubuntu-2204
# after a certain period of time, costs are charged

ubuntu@dlp ~(keystone)$
openstack rating summary get

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| 4dd1e1f6bac441ff9c77002c3ab4c58a | ALL           | 0.5  | 2022-10-01T00:00:00 | 2022-11-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

# if the instance continues to run, costs are charged every [period] of time

ubuntu@dlp ~(keystone)$
openstack rating summary get

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| 4dd1e1f6bac441ff9c77002c3ab4c58a | ALL           | 1.0  | 2022-10-01T00:00:00 | 2022-11-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

# display data frames

ubuntu@dlp ~(keystone)$
openstack rating dataframes get

+---------------------+---------------------+----------------------------------
| Begin               | End                 | Project ID                       
+---------------------+---------------------+----------------------------------
| 2022-10-18T14:10:00 | 2022-10-18T14:20:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T14:20:00 | 2022-10-18T14:30:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
+---------------------+---------------------+----------------------------------
+-------------------------------------------------------------------------------
| Resources                                                                     
+-------------------------------------------------------------------------------
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.small', 
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.small', 
+-------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
                                                                                           
-------------------------------------------------------------------------------------------
'flavor_id': '0', 'vcpus': '', 'id': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': 
'flavor_id': '0', 'vcpus': '', 'id': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': 
-------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
                                                                                   
-----------------------------------------------------------------------------------
'4dd1e1f6bac441ff9c77002c3ab4c58a', 'user_id': '9345b7f4de21427abf31ad308cf952f8', 
'4dd1e1f6bac441ff9c77002c3ab4c58a', 'user_id': '9345b7f4de21427abf31ad308cf952f8', 
-----------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------+
                                                                                             |
---------------------------------------------------------------------------------------------+
'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1', 'rate_value': '0.5000'}]    |
'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1', 'rate_value': '0.5000'}]    |
---------------------------------------------------------------------------------------------+
[5] Set rate to Volume Size.
When users in the project set on [1] create cinder volumes, target project is charged at the rate you set per gigabyte.
# add service matching rule

root@dlp ~(keystone)#
openstack rating hashmap service create volume.size

+-------------+--------------------------------------+
| Name        | Service ID                           |
+-------------+--------------------------------------+
| volume.size | ba16a032-a03f-47cf-92b3-1d8e2100fd79 |
+-------------+--------------------------------------+

# add mapping rule
# set a cost of [1.5] per gigabyte
root@dlp ~(keystone)# openstack rating hashmap mapping create 1.5 \
-s ba16a032-a03f-47cf-92b3-1d8e2100fd79 \
-t flat 
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| Mapping ID                           | Value | Cost                           | Type | Field ID | Service ID                           | Group ID | Project ID |
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| f8fe830f-5514-4bd0-802f-f3e36b2ea685 | None  | 1.5000000000000000000000000000 | flat | None     | ba16a032-a03f-47cf-92b3-1d8e2100fd79 | None     | None       |
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+

# set a 10% discount on over 30 GB volumes
root@dlp ~(keystone)# openstack rating hashmap threshold create 30 0.90 \
-s ba16a032-a03f-47cf-92b3-1d8e2100fd79 \
-t rate 
+--------------------------------------+-------------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| Threshold ID                         | Level       | Cost                           | Type | Field ID | Service ID                           | Group ID | Project ID |
+--------------------------------------+-------------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| ab5ba7a9-4f4a-48fe-8e5f-5853bf16755a | 30.00000000 | 0.9000000000000000222044604925 | rate | None     | ba16a032-a03f-47cf-92b3-1d8e2100fd79 | None     | None       |
+--------------------------------------+-------------+--------------------------------+------+----------+--------------------------------------+----------+------------+
[6] Verify settings with an user who is in the project you set on [1] to create volumes.
ubuntu@dlp ~(keystone)$
openstack rating summary get

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| 4dd1e1f6bac441ff9c77002c3ab4c58a | ALL           | 1.5  | 2022-10-01T00:00:00 | 2022-11-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

ubuntu@dlp ~(keystone)$ openstack volume create --size 10 disk01 

ubuntu@dlp ~(keystone)$
openstack volume list

+--------------------------------------+--------+-----------+------+-------------+
| ID                                   | Name   | Status    | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------+
| e61f677f-bdd2-4e04-874f-582471263d1c | disk01 | available |   10 |             |
+--------------------------------------+--------+-----------+------+-------------+

# after a certain period of time, costs are charged

ubuntu@dlp ~(keystone)$
openstack rating summary get

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| 4dd1e1f6bac441ff9c77002c3ab4c58a | ALL           | 16.5 | 2022-10-01T00:00:00 | 2022-11-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

ubuntu@dlp ~(keystone)$
openstack rating dataframes get

+---------------------+---------------------+----------------------------------
| Begin               | End                 | Project ID                       
+---------------------+---------------------+----------------------------------
| 2022-10-18T14:10:00 | 2022-10-18T14:20:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T14:20:00 | 2022-10-18T14:30:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T14:30:00 | 2022-10-18T14:40:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T14:40:00 | 2022-10-18T14:50:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
+---------------------+---------------------+----------------------------------
+--------------------------------------------------------------------------------------------------------------
| Resources                                                                                                    
+--------------------------------------------------------------------------------------------------------------
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.small', 'flavor_id': '0', 'vcpus': '', 
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.small', 'flavor_id': '0', 'vcpus': '', 
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.small', 'flavor_id': '0', 'vcpus': '', 
| [{'rating': '15.0', 'service': 'volume.size', 'desc': {'volume_type': '14cf70ec-0fb5-4fec-9cfd-9d719bedc097',
+--------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
                                                                                                
------------------------------------------------------------------------------------------------
'id': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a', 
'id': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a', 
'id': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a', 
 'id': 'e61f677f-bdd2-4e04-874f-582471263d1c', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a',
------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------+
                                                                                                                                             |
---------------------------------------------------------------------------------------------------------------------------------------------+
'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1', 'rate_value': '0.5000'}]     |
'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1', 'rate_value': '0.5000'}]     |
'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1', 'rate_value': '0.5000'}]     |
 'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1E+1', 'rate_value': '1.5000'}] |
---------------------------------------------------------------------------------------------------------------------------------------------+

ubuntu@dlp ~(keystone)$
openstack volume create --size 30 disk02

ubuntu@dlp ~(keystone)$
openstack volume list

+--------------------------------------+--------+-----------+------+-------------+
| ID                                   | Name   | Status    | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------+
| 48a6eb5d-3e72-414a-9996-70b377fb66b1 | disk02 | available |   30 |             |
| e61f677f-bdd2-4e04-874f-582471263d1c | disk01 | available |   10 |             |
+--------------------------------------+--------+-----------+------+-------------+

# after a certain period of time, costs are charged
# 1.5 x 30 x 0.9 = 40.5

ubuntu@dlp ~(keystone)$
openstack rating summary get

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| 4dd1e1f6bac441ff9c77002c3ab4c58a | ALL           | 57.0 | 2022-10-01T00:00:00 | 2022-11-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

ubuntu@dlp ~(keystone)$
openstack rating dataframes get

+---------------------+---------------------+----------------------------------
| Begin               | End                 | Project ID                       
+---------------------+---------------------+----------------------------------
| 2022-10-18T14:10:00 | 2022-10-18T14:20:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T14:20:00 | 2022-10-18T14:30:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T14:30:00 | 2022-10-18T14:40:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T14:40:00 | 2022-10-18T14:50:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T15:20:00 | 2022-10-18T15:30:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
+---------------------+---------------------+----------------------------------
+--------------------------------------------------------------------------------------------------------------
| Resources                                                                                                    
+--------------------------------------------------------------------------------------------------------------
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.small', 'flavor_id': '0', 'vcpus': '', 
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.small', 'flavor_id': '0', 'vcpus': '', 
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.small', 'flavor_id': '0', 'vcpus': '', 
| [{'rating': '15.0', 'service': 'volume.size', 'desc': {'volume_type': '14cf70ec-0fb5-4fec-9cfd-9d719bedc097',
| [{'rating': '40.5', 'service': 'volume.size', 'desc': {'volume_type': '14cf70ec-0fb5-4fec-9cfd-9d719bedc097',
+--------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
                                                                                                
------------------------------------------------------------------------------------------------
'id': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a', 
'id': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a', 
'id': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a', 
 'id': 'e61f677f-bdd2-4e04-874f-582471263d1c', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a',
 'id': '48a6eb5d-3e72-414a-9996-70b377fb66b1', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a',
------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------+
                                                                                                                                             |
---------------------------------------------------------------------------------------------------------------------------------------------+
'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1', 'rate_value': '0.5000'}]     |
'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1', 'rate_value': '0.5000'}]     |
'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1', 'rate_value': '0.5000'}]     |
 'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1E+1', 'rate_value': '1.5000'}] |
 'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '3E+1', 'rate_value': '1.3500'}] |
---------------------------------------------------------------------------------------------------------------------------------------------+
Matched Content