CentOS Stream 9
Sponsored Link

OpenStack Zed : How to use CloudKitty2022/11/14

 
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      |
+----------------------------------+-----------+
| 28b6e37c787240e4a975d3614821cc71 | hiroshima |
| 62f531f4d2934e75b8d7f11cd7d53be3 | service   |
| 939974d6fc8e400eb01f7dd749935ea3 | admin     |
+----------------------------------+-----------+

[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 | 11fb6e6f-1590-456b-91f9-6cc6dfc624fe |
+----------+--------------------------------------+

# add field matching rule

[root@dlp ~(keystone)]#
openstack rating hashmap field create 11fb6e6f-1590-456b-91f9-6cc6dfc624fe flavor_id

+-----------+--------------------------------------+--------------------------------------+
| Name      | Field ID                             | Service ID                           |
+-----------+--------------------------------------+--------------------------------------+
| flavor_id | 6cf3cbaf-17e5-4aa7-a3f4-ede7a7d79a9b | 11fb6e6f-1590-456b-91f9-6cc6dfc624fe |
+-----------+--------------------------------------+--------------------------------------+

[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 6cf3cbaf-17e5-4aa7-a3f4-ede7a7d79a9b \
--value 0 -t flat 
+--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+
| Mapping ID                           | Value | Cost                           | Type | Field ID                             | Service ID | Group ID | Project ID |
+--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+
| 3cb4871c-0314-4b41-a328-605cfb60198a | 0     | 0.5000000000000000000000000000 | flat | 6cf3cbaf-17e5-4aa7-a3f4-ede7a7d79a9b | None       | None     | None       |
+--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+
[4] Verify settings with an user who is in the project you set on [1] to create or start an instance.
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+------------+---------+------------------------------------+----------------+----------+
| ID                                   | Name       | Status  | Networks                           | Image          | Flavor   |
+--------------------------------------+------------+---------+------------------------------------+----------------+----------+
| 158685ed-8159-4aad-a294-3227b427f7e1 | CentOS-St9 | SHUTOFF | private=10.0.0.218, 192.168.100.75 | CentOS-Stream9 | m1.small |
+--------------------------------------+------------+---------+------------------------------------+----------------+----------+
[cent@dlp ~(keystone)]$
openstack server start CentOS-St9
# after a certain period of time, costs are charged

[cent@dlp ~(keystone)]$
openstack rating summary get

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| 28b6e37c787240e4a975d3614821cc71 | ALL           | 0.5  | 2022-11-01T00:00:00 | 2022-12-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

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

[cent@dlp ~(keystone)]$
openstack rating summary get

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| 28b6e37c787240e4a975d3614821cc71 | ALL           | 1.0  | 2022-11-01T00:00:00 | 2022-12-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

# display data frames

[cent@dlp ~(keystone)]$
openstack rating dataframes get

+---------------------+---------------------+----------------------------------
| Begin               | End                 | Project ID                       
+---------------------+---------------------+----------------------------------
| 2022-11-14T02:30:00 | 2022-11-14T02:40:00 | 28b6e37c787240e4a975d3614821cc71 
| 2022-11-14T02:40:00 | 2022-11-14T02:50:00 | 28b6e37c787240e4a975d3614821cc71 
+---------------------+---------------------+----------------------------------
+-------------------------------------------------------------------------------
| 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': '158685ed-8159-4aad-a294-3227b427f7e1', 'project_id': 
'flavor_id': '0', 'vcpus': '', 'id': '158685ed-8159-4aad-a294-3227b427f7e1', 'project_id': 
-------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
                                                                                                
------------------------------------------------------------------------------------------------
'28b6e37c787240e4a975d3614821cc71', 'user_id': '9e8824a151c949ad9105535ead452501', 'tenant_id': 
'28b6e37c787240e4a975d3614821cc71', 'user_id': '9e8824a151c949ad9105535ead452501', 'tenant_id': 
------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------+
                                                                                |
--------------------------------------------------------------------------------+
'28b6e37c787240e4a975d3614821cc71'}, 'volume': '1', 'rate_value': '0.5000'}]    |
'28b6e37c787240e4a975d3614821cc71'}, '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 | 94277f7f-f9fe-4399-9757-263ccae13168 |
+-------------+--------------------------------------+

# add mapping rule
# set a cost of [1.5] per gigabyte
[root@dlp ~(keystone)]# openstack rating hashmap mapping create 1.5 \
-s 94277f7f-f9fe-4399-9757-263ccae13168 \
-t flat 
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| Mapping ID                           | Value | Cost                           | Type | Field ID | Service ID                           | Group ID | Project ID |
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| a68705fc-1895-4054-97d9-64a951413443 | None  | 1.5000000000000000000000000000 | flat | None     | 94277f7f-f9fe-4399-9757-263ccae13168 | None     | None       |
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+

# set a 10% discount on over 30 GB volumes
[root@dlp ~(keystone)]# openstack rating hashmap threshold create 30 0.90 \
-s 94277f7f-f9fe-4399-9757-263ccae13168 \
-t rate 
+--------------------------------------+-------------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| Threshold ID                         | Level       | Cost                           | Type | Field ID | Service ID                           | Group ID | Project ID |
+--------------------------------------+-------------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| 10a83151-44d6-42ec-b926-7cb94c88838b | 30.00000000 | 0.9000000000000000222044604925 | rate | None     | 94277f7f-f9fe-4399-9757-263ccae13168 | None     | None       |
+--------------------------------------+-------------+--------------------------------+------+----------+--------------------------------------+----------+------------+
[6] Verify settings with an user who is in the project you set on [1] to create volumes.
[cent@dlp ~(keystone)]$
openstack rating summary get

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| 28b6e37c787240e4a975d3614821cc71 | ALL           | 2.0  | 2022-11-01T00:00:00 | 2022-12-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

[cent@dlp ~(keystone)]$ openstack volume create --size 10 disk01 

[cent@dlp ~(keystone)]$
openstack volume list

+--------------------------------------+--------+-----------+------+-------------+
| ID                                   | Name   | Status    | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------+
| c64e53ed-3ad3-48b1-99f1-5937b5cfd032 | disk01 | available |   10 |             |
+--------------------------------------+--------+-----------+------+-------------+

# after a certain period of time, costs are charged

[cent@dlp ~(keystone)]$
openstack rating summary get

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| 28b6e37c787240e4a975d3614821cc71 | ALL           | 17.0 | 2022-11-01T00:00:00 | 2022-12-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

[cent@dlp ~(keystone)]$
openstack rating dataframes get

+---------------------+---------------------+----------------------------------
| Begin               | End                 | Project ID                       
+---------------------+---------------------+----------------------------------
| 2022-11-14T02:30:00 | 2022-11-14T02:40:00 | 28b6e37c787240e4a975d3614821cc71 
| 2022-11-14T02:40:00 | 2022-11-14T02:50:00 | 28b6e37c787240e4a975d3614821cc71 
| 2022-11-14T02:50:00 | 2022-11-14T03:00:00 | 28b6e37c787240e4a975d3614821cc71 
| 2022-11-14T03:00:00 | 2022-11-14T03:10:00 | 28b6e37c787240e4a975d3614821cc71 
| 2022-11-14T03:10:00 | 2022-11-14T03:20:00 | 28b6e37c787240e4a975d3614821cc71 
+---------------------+---------------------+----------------------------------
+--------------------------------------------------------------------------------------------------------------
| 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': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.small', 'flavor_id': '0', 'vcpus': '', 
| [{'rating': '15.0', 'service': 'volume.size', 'desc': {'volume_type': '833841d2-80f5-4caf-abc6-564f77c48268',
+--------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
                                                                                                           
-----------------------------------------------------------------------------------------------------------
'id': '158685ed-8159-4aad-a294-3227b427f7e1', 'project_id': '28b6e37c787240e4a975d3614821cc71', 'user_id': 
'id': '158685ed-8159-4aad-a294-3227b427f7e1', 'project_id': '28b6e37c787240e4a975d3614821cc71', 'user_id': 
'id': '158685ed-8159-4aad-a294-3227b427f7e1', 'project_id': '28b6e37c787240e4a975d3614821cc71', 'user_id': 
'id': '158685ed-8159-4aad-a294-3227b427f7e1', 'project_id': '28b6e37c787240e4a975d3614821cc71', 'user_id': 
 'id': 'c64e53ed-3ad3-48b1-99f1-5937b5cfd032', 'project_id': '28b6e37c787240e4a975d3614821cc71', 'user_id':
-----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------+
                                                                                                                                  |
----------------------------------------------------------------------------------------------------------------------------------+
'9e8824a151c949ad9105535ead452501', 'tenant_id': '28b6e37c787240e4a975d3614821cc71'}, 'volume': '1', 'rate_value': '0.5000'}]     |
'9e8824a151c949ad9105535ead452501', 'tenant_id': '28b6e37c787240e4a975d3614821cc71'}, 'volume': '1', 'rate_value': '0.5000'}]     |
'9e8824a151c949ad9105535ead452501', 'tenant_id': '28b6e37c787240e4a975d3614821cc71'}, 'volume': '1', 'rate_value': '0.5000'}]     |
'9e8824a151c949ad9105535ead452501', 'tenant_id': '28b6e37c787240e4a975d3614821cc71'}, 'volume': '1', 'rate_value': '0.5000'}]     |
 '9e8824a151c949ad9105535ead452501', 'tenant_id': '28b6e37c787240e4a975d3614821cc71'}, 'volume': '1E+1', 'rate_value': '1.5000'}] |
----------------------------------------------------------------------------------------------------------------------------------+

[cent@dlp ~(keystone)]$
openstack volume create --size 30 disk02

[cent@dlp ~(keystone)]$
openstack volume list

+--------------------------------------+--------+-----------+------+-------------+
| ID                                   | Name   | Status    | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------+
| 1afe6dc0-536c-43fb-a93d-5712133499cf | disk02 | available |   30 |             |
| c64e53ed-3ad3-48b1-99f1-5937b5cfd032 | disk01 | available |   10 |             |
+--------------------------------------+--------+-----------+------+-------------+

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

[cent@dlp ~(keystone)]$
openstack rating summary get

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| 28b6e37c787240e4a975d3614821cc71 | ALL           | 57.5 | 2022-11-01T00:00:00 | 2022-12-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

[cent@dlp ~(keystone)]$
openstack rating dataframes get

+---------------------+---------------------+----------------------------------
| Begin               | End                 | Project ID                       
+---------------------+---------------------+----------------------------------
| 2022-11-14T02:30:00 | 2022-11-14T02:40:00 | 28b6e37c787240e4a975d3614821cc71 
| 2022-11-14T02:40:00 | 2022-11-14T02:50:00 | 28b6e37c787240e4a975d3614821cc71 
| 2022-11-14T02:50:00 | 2022-11-14T03:00:00 | 28b6e37c787240e4a975d3614821cc71 
| 2022-11-14T03:00:00 | 2022-11-14T03:10:00 | 28b6e37c787240e4a975d3614821cc71 
| 2022-11-14T03:10:00 | 2022-11-14T03:20:00 | 28b6e37c787240e4a975d3614821cc71 
| 2022-11-14T03:40:00 | 2022-11-14T03:50:00 | 28b6e37c787240e4a975d3614821cc71 
+---------------------+---------------------+----------------------------------
+--------------------------------------------------------------------------------------------------------------
| 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': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.small', 'flavor_id': '0', 'vcpus': '', 
| [{'rating': '15.0', 'service': 'volume.size', 'desc': {'volume_type': '833841d2-80f5-4caf-abc6-564f77c48268',
| [{'rating': '40.5', 'service': 'volume.size', 'desc': {'volume_type': '833841d2-80f5-4caf-abc6-564f77c48268',
+--------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
                                                                                                           
-----------------------------------------------------------------------------------------------------------
'id': '158685ed-8159-4aad-a294-3227b427f7e1', 'project_id': '28b6e37c787240e4a975d3614821cc71', 'user_id': 
'id': '158685ed-8159-4aad-a294-3227b427f7e1', 'project_id': '28b6e37c787240e4a975d3614821cc71', 'user_id': 
'id': '158685ed-8159-4aad-a294-3227b427f7e1', 'project_id': '28b6e37c787240e4a975d3614821cc71', 'user_id': 
'id': '158685ed-8159-4aad-a294-3227b427f7e1', 'project_id': '28b6e37c787240e4a975d3614821cc71', 'user_id': 
 'id': 'c64e53ed-3ad3-48b1-99f1-5937b5cfd032', 'project_id': '28b6e37c787240e4a975d3614821cc71', 'user_id':
 'id': '1afe6dc0-536c-43fb-a93d-5712133499cf', 'project_id': '28b6e37c787240e4a975d3614821cc71', 'user_id':
-----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------+
                                                                                                                                  |
----------------------------------------------------------------------------------------------------------------------------------+
'9e8824a151c949ad9105535ead452501', 'tenant_id': '28b6e37c787240e4a975d3614821cc71'}, 'volume': '1', 'rate_value': '0.5000'}]     |
'9e8824a151c949ad9105535ead452501', 'tenant_id': '28b6e37c787240e4a975d3614821cc71'}, 'volume': '1', 'rate_value': '0.5000'}]     |
'9e8824a151c949ad9105535ead452501', 'tenant_id': '28b6e37c787240e4a975d3614821cc71'}, 'volume': '1', 'rate_value': '0.5000'}]     |
'9e8824a151c949ad9105535ead452501', 'tenant_id': '28b6e37c787240e4a975d3614821cc71'}, 'volume': '1', 'rate_value': '0.5000'}]     |
 '9e8824a151c949ad9105535ead452501', 'tenant_id': '28b6e37c787240e4a975d3614821cc71'}, 'volume': '1E+1', 'rate_value': '1.5000'}] |
 '9e8824a151c949ad9105535ead452501', 'tenant_id': '28b6e37c787240e4a975d3614821cc71'}, 'volume': '3E+1', 'rate_value': '1.3500'}] |
----------------------------------------------------------------------------------------------------------------------------------+
Matched Content