Ubuntu 22.04
Sponsored Link

OpenStack Antelope : How to use CloudKitty2023/03/29

 
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 you like to rate.
root@dlp ~(keystone)#
openstack project list

+----------------------------------+-----------+
| ID                               | Name      |
+----------------------------------+-----------+
| cac657ec003e4c95aaaa30bc0321895f | admin     |
| d3dd87fb1a034f7883539a6a4f83781f | service   |
| e294bd7c00314facacdb46c36fb54ee9 | hiroshima |
+----------------------------------+-----------+

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 | e42aae57-507e-4e7d-96ca-aa860e0b510b |
+----------+--------------------------------------+

# add field matching rule

root@dlp ~(keystone)#
openstack rating hashmap field create e42aae57-507e-4e7d-96ca-aa860e0b510b flavor_id

+-----------+--------------------------------------+--------------------------------------+
| Name      | Field ID                             | Service ID                           |
+-----------+--------------------------------------+--------------------------------------+
| flavor_id | b342c47b-a43e-47bf-a443-e069f5e7efc7 | e42aae57-507e-4e7d-96ca-aa860e0b510b |
+-----------+--------------------------------------+--------------------------------------+

root@dlp ~(keystone)#
openstack flavor list

+----+-----------+------+------+-----------+-------+-----------+
| ID | Name      |  RAM | Disk | Ephemeral | VCPUs | Is Public |
+----+-----------+------+------+-----------+-------+-----------+
| 1  | m1.small  | 2048 |   10 |         0 |     1 | True      |
| 2  | m1.medium | 4096 |   10 |         0 |     2 | True      |
| 3  | m1.large  | 8192 |   20 |        10 |     4 | True      |
+----+-----------+------+------+-----------+-------+-----------+

# add mapping rule
# set a cost of [0.5] to instances with [flavor_id] = [2]
root@dlp ~(keystone)# openstack rating hashmap mapping create 0.5 \
--field-id b342c47b-a43e-47bf-a443-e069f5e7efc7 \
--value 2 -t flat 
+--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+
| Mapping ID                           | Value | Cost                           | Type | Field ID                             | Service ID | Group ID | Project ID |
+--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+
| 82393b12-94b1-4047-8453-17369285888b | 2     | 0.5000000000000000000000000000 | flat | b342c47b-a43e-47bf-a443-e069f5e7efc7 | 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    |
+--------------------------------------+-------------+---------+-------------------------------------+------------+-----------+
| 11987eec-fb38-4de1-a386-3d1d6001bbd3 | Ubuntu-2204 | SHUTOFF | private=10.0.0.252, 192.168.100.100 | Ubuntu2204 | m1.medium |
+--------------------------------------+-------------+---------+-------------------------------------+------------+-----------+
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            |
+----------------------------------+---------------+------+---------------------+---------------------+
| e294bd7c00314facacdb46c36fb54ee9 | ALL           | 0.5  | 2023-03-01T00:00:00 | 2023-04-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            |
+----------------------------------+---------------+------+---------------------+---------------------+
| e294bd7c00314facacdb46c36fb54ee9 | ALL           | 1.0  | 2023-03-01T00:00:00 | 2023-04-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

# display data frames

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

+---------------------+---------------------+----------------------------------
| Begin               | End                 | Project ID                       
+---------------------+---------------------+----------------------------------
| 2023-03-29T02:10:00 | 2023-03-29T02:20:00 | e294bd7c00314facacdb46c36fb54ee9 
| 2023-03-29T04:20:00 | 2023-03-29T04:30:00 | e294bd7c00314facacdb46c36fb54ee9 
| 2023-03-29T04:30:00 | 2023-03-29T04:40:00 | e294bd7c00314facacdb46c36fb54ee9 
+---------------------+---------------------+----------------------------------
+--------------------------------------------------------------------------------
| Resources                                                                      
+--------------------------------------------------------------------------------
| [{'rating': '0.0', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', 
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', 
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', 
+--------------------------------------------------------------------------------
-----------------------------------------------------------------------------
                                                                             
-----------------------------------------------------------------------------
'flavor_id': '2', 'vcpus': '', 'id': '11987eec-fb38-4de1-a386-3d1d6001bbd3', 
'flavor_id': '2', 'vcpus': '', 'id': '11987eec-fb38-4de1-a386-3d1d6001bbd3', 
'flavor_id': '2', 'vcpus': '', 'id': '11987eec-fb38-4de1-a386-3d1d6001bbd3', 
-----------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
                                                                                                 
-------------------------------------------------------------------------------------------------
'project_id': 'e294bd7c00314facacdb46c36fb54ee9', 'user_id': '85236576a97e492791abe70c217c8898', 
'project_id': 'e294bd7c00314facacdb46c36fb54ee9', 'user_id': '85236576a97e492791abe70c217c8898', 
'project_id': 'e294bd7c00314facacdb46c36fb54ee9', 'user_id': '85236576a97e492791abe70c217c8898', 
-------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------+
                                                                                             |
---------------------------------------------------------------------------------------------+
'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, 'volume': '1', 'rate_value': '0.0000'}]    |
'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, 'volume': '1', 'rate_value': '0.5000'}]    |
'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, '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 | f76586d4-e609-4f6f-a446-5ec5d52f8224 |
+-------------+--------------------------------------+

# add mapping rule
# set a cost of [1.5] per gigabyte
root@dlp ~(keystone)# openstack rating hashmap mapping create 1.5 \
-s f76586d4-e609-4f6f-a446-5ec5d52f8224 \
-t flat 
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| Mapping ID                           | Value | Cost                           | Type | Field ID | Service ID                           | Group ID | Project ID |
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| 96914ec1-3d01-4974-8f0a-50ee935ae602 | None  | 1.5000000000000000000000000000 | flat | None     | f76586d4-e609-4f6f-a446-5ec5d52f8224 | None     | None       |
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+

# set a 10% discount on over 30 GB volumes
root@dlp ~(keystone)# openstack rating hashmap threshold create 30 0.90 \
-s f76586d4-e609-4f6f-a446-5ec5d52f8224 \
-t rate 
+--------------------------------------+-------------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| Threshold ID                         | Level       | Cost                           | Type | Field ID | Service ID                           | Group ID | Project ID |
+--------------------------------------+-------------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| 4f75632a-22e3-47c6-a9d9-6abe22fbd203 | 30.00000000 | 0.9000000000000000222044604925 | rate | None     | f76586d4-e609-4f6f-a446-5ec5d52f8224 | 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            |
+----------------------------------+---------------+------+---------------------+---------------------+
| e294bd7c00314facacdb46c36fb54ee9 | ALL           | 1.0  | 2023-03-01T00:00:00 | 2023-04-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

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

ubuntu@dlp ~(keystone)$
openstack volume list

+--------------------------------------+--------+-----------+------+-------------+
| ID                                   | Name   | Status    | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------+
| d33457d5-34d5-4316-8a10-10e8198a7e7f | 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            |
+----------------------------------+---------------+------+---------------------+---------------------+
| e294bd7c00314facacdb46c36fb54ee9 | ALL           | 16.0 | 2023-03-01T00:00:00 | 2023-04-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

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

+---------------------+---------------------+----------------------------------
| Begin               | End                 | Project ID                       
+---------------------+---------------------+----------------------------------
| 2023-03-29T02:10:00 | 2023-03-29T02:20:00 | e294bd7c00314facacdb46c36fb54ee9 
| 2023-03-29T02:20:00 | 2023-03-29T02:30:00 | e294bd7c00314facacdb46c36fb54ee9 
| 2023-03-29T04:20:00 | 2023-03-29T04:30:00 | e294bd7c00314facacdb46c36fb54ee9 
| 2023-03-29T04:30:00 | 2023-03-29T04:40:00 | e294bd7c00314facacdb46c36fb54ee9 
| 2023-03-29T04:30:00 | 2023-03-29T04:40:00 | e294bd7c00314facacdb46c36fb54ee9 
+---------------------+---------------------+----------------------------------
+--------------------------------------------------------------------------------------------------------------
| Resources                                                                                                    
+--------------------------------------------------------------------------------------------------------------
| [{'rating': '0.0', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', 'flavor_id': '2', 'vcpus': '',
| [{'rating': '0.0', 'service': 'volume.size', 'desc': {'volume_type': '2740bc05-65be-4824-9224-d4a9645065fa', 
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', 'flavor_id': '2', 'vcpus': '',
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', 'flavor_id': '2', 'vcpus': '',
| [{'rating': '15.0', 'service': 'volume.size', 'desc': {'volume_type': '2740bc05-65be-4824-9224-d4a9645065fa',
+--------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
                                                                                                
------------------------------------------------------------------------------------------------
 'id': '11987eec-fb38-4de1-a386-3d1d6001bbd3', 'project_id': 'e294bd7c00314facacdb46c36fb54ee9',
'id': '3a3a1349-4cee-45d6-adc1-381d6467619e', 'project_id': 'e294bd7c00314facacdb46c36fb54ee9', 
 'id': '11987eec-fb38-4de1-a386-3d1d6001bbd3', 'project_id': 'e294bd7c00314facacdb46c36fb54ee9',
 'id': '11987eec-fb38-4de1-a386-3d1d6001bbd3', 'project_id': 'e294bd7c00314facacdb46c36fb54ee9',
 'id': '3a3a1349-4cee-45d6-adc1-381d6467619e', 'project_id': 'e294bd7c00314facacdb46c36fb54ee9',
------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------+
                                                                                                                                             |
---------------------------------------------------------------------------------------------------------------------------------------------+
 'user_id': '85236576a97e492791abe70c217c8898', 'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, 'volume': '1', 'rate_value': '0.0000'}]    |
'user_id': '85236576a97e492791abe70c217c8898', 'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, 'volume': '1E+1', 'rate_value': '0.0000'}]  |
 'user_id': '85236576a97e492791abe70c217c8898', 'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, 'volume': '1', 'rate_value': '0.5000'}]    |
 'user_id': '85236576a97e492791abe70c217c8898', 'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, 'volume': '1', 'rate_value': '0.5000'}]    |
 'user_id': '85236576a97e492791abe70c217c8898', 'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, '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 |
+--------------------------------------+--------+-----------+------+-------------+
| 15f94205-29eb-4b66-9401-930f456afe83 | disk02 | available |   30 |             |
| d33457d5-34d5-4316-8a10-10e8198a7e7f | 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            |
+----------------------------------+---------------+------+---------------------+---------------------+
| e294bd7c00314facacdb46c36fb54ee9 | ALL           | 56.5 | 2023-03-01T00:00:00 | 2023-04-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

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

+---------------------+---------------------+----------------------------------
| Begin               | End                 | Project ID                       
+---------------------+---------------------+----------------------------------
| 2023-03-29T02:10:00 | 2023-03-29T02:20:00 | e294bd7c00314facacdb46c36fb54ee9 
| 2023-03-29T02:20:00 | 2023-03-29T02:30:00 | e294bd7c00314facacdb46c36fb54ee9 
| 2023-03-29T04:20:00 | 2023-03-29T04:30:00 | e294bd7c00314facacdb46c36fb54ee9 
| 2023-03-29T04:30:00 | 2023-03-29T04:40:00 | e294bd7c00314facacdb46c36fb54ee9 
| 2023-03-29T04:30:00 | 2023-03-29T04:40:00 | e294bd7c00314facacdb46c36fb54ee9 
| 2023-03-29T05:00:00 | 2023-03-29T05:10:00 | e294bd7c00314facacdb46c36fb54ee9 
+---------------------+---------------------+----------------------------------
+--------------------------------------------------------------------------------------------------------------
| Resources                                                                                                    
+--------------------------------------------------------------------------------------------------------------
| [{'rating': '0.0', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', 'flavor_id': '2', 'vcpus': '',
| [{'rating': '0.0', 'service': 'volume.size', 'desc': {'volume_type': '2740bc05-65be-4824-9224-d4a9645065fa', 
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', 'flavor_id': '2', 'vcpus': '',
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', 'flavor_id': '2', 'vcpus': '',
| [{'rating': '15.0', 'service': 'volume.size', 'desc': {'volume_type': '2740bc05-65be-4824-9224-d4a9645065fa',
| [{'rating': '40.5', 'service': 'volume.size', 'desc': {'volume_type': '2740bc05-65be-4824-9224-d4a9645065fa',
+--------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
                                                                                                
------------------------------------------------------------------------------------------------
 'id': '11987eec-fb38-4de1-a386-3d1d6001bbd3', 'project_id': 'e294bd7c00314facacdb46c36fb54ee9',
'id': '3a3a1349-4cee-45d6-adc1-381d6467619e', 'project_id': 'e294bd7c00314facacdb46c36fb54ee9', 
 'id': '11987eec-fb38-4de1-a386-3d1d6001bbd3', 'project_id': 'e294bd7c00314facacdb46c36fb54ee9',
 'id': '11987eec-fb38-4de1-a386-3d1d6001bbd3', 'project_id': 'e294bd7c00314facacdb46c36fb54ee9',
 'id': '3a3a1349-4cee-45d6-adc1-381d6467619e', 'project_id': 'e294bd7c00314facacdb46c36fb54ee9',
 'id': '15f94205-29eb-4b66-9401-930f456afe83', 'project_id': 'e294bd7c00314facacdb46c36fb54ee9',
------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------+
                                                                                                                                             |
---------------------------------------------------------------------------------------------------------------------------------------------+
 'user_id': '85236576a97e492791abe70c217c8898', 'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, 'volume': '1', 'rate_value': '0.0000'}]    |
'user_id': '85236576a97e492791abe70c217c8898', 'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, 'volume': '1E+1', 'rate_value': '0.0000'}]  |
 'user_id': '85236576a97e492791abe70c217c8898', 'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, 'volume': '1', 'rate_value': '0.5000'}]    |
 'user_id': '85236576a97e492791abe70c217c8898', 'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, 'volume': '1', 'rate_value': '0.5000'}]    |
 'user_id': '85236576a97e492791abe70c217c8898', 'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, 'volume': '1E+1', 'rate_value': '1.5000'}] |
 'user_id': '85236576a97e492791abe70c217c8898', 'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, 'volume': '3E+1', 'rate_value': '1.3500'}] |
---------------------------------------------------------------------------------------------------------------------------------------------+
Matched Content