OpenStack Bobcat : How to use CloudKitty2023/10/10 |
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 that you like to rate. |
root@dlp ~(keystone)# openstack project list +----------------------------------+-----------+ | ID | Name | +----------------------------------+-----------+ | 04b6d7802d9043cbb09ceb31fd68987b | service | | 39e8c6d7a2d14ee581902f0703a53b66 | admin | | f30cd546632e484cb24414d83207694b | 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 | f60a859f-bb07-47db-abc5-8b22107a592b | +----------+--------------------------------------+ # add field matching rule root@dlp ~(keystone)# openstack rating hashmap field create f60a859f-bb07-47db-abc5-8b22107a592b flavor_id +-----------+--------------------------------------+--------------------------------------+ | Name | Field ID | Service ID | +-----------+--------------------------------------+--------------------------------------+ | flavor_id | 5a7250d8-8ed5-4c11-8557-4528f4d5eb03 | f60a859f-bb07-47db-abc5-8b22107a592b | +-----------+--------------------------------------+--------------------------------------+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 | 10 | 0 | 4 | True | | 4 | m2.large | 8192 | 20 | 0 | 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 5a7250d8-8ed5-4c11-8557-4528f4d5eb03 \ --value 2 -t flat +--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+ | Mapping ID | Value | Cost | Type | Field ID | Service ID | Group ID | Project ID | +--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+ | c5af95aa-1e83-40fe-b57b-67cd5c052c5d | 2 | 0.5000000000000000000000000000 | flat | 5a7250d8-8ed5-4c11-8557-4528f4d5eb03 | 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 | +--------------------------------------+-------------+---------+------------------------------------+------------+-----------+ | 530698ed-413e-4bda-b02e-8f6f60380bd1 | Ubuntu-2204 | SHUTOFF | private=10.0.0.222, 192.168.100.79 | 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 | +----------------------------------+---------------+------+---------------------+---------------------+ | f30cd546632e484cb24414d83207694b | ALL | 0.5 | 2023-10-01T00:00:00 | 2023-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 | +----------------------------------+---------------+------+---------------------+---------------------+ | f30cd546632e484cb24414d83207694b | ALL | 1.0 | 2023-10-01T00:00:00 | 2023-11-01T00:00:00 | +----------------------------------+---------------+------+---------------------+---------------------+ # display data frames ubuntu@dlp ~(keystone)$ openstack rating dataframes get +---------------------+---------------------+---------------------------------- | Begin | End | Project ID +---------------------+---------------------+---------------------------------- | 2023-10-10T00:10:00 | 2023-10-10T00:20:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T00:30:00 | 2023-10-10T00:40:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T00:50:00 | 2023-10-10T01:00:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T01:00:00 | 2023-10-10T01:10:00 | f30cd546632e484cb24414d83207694b +---------------------+---------------------+---------------------------------- +------------------------------------------------------------------------------------------------------------- | Resources +------------------------------------------------------------------------------------------------------------- | [{'rating': '0.0', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', 'flavor_id': '2', 'vcpus': '' | [{'rating': '0.0', 'service': 'volume.size', 'desc': {'volume_type': '05118a15-3b8d-44cd-aa39-d85c1611a863', | [{'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': '' +------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------- , 'id': '530698ed-413e-4bda-b02e-8f6f60380bd1', 'project_id': 'f30cd546632e484cb24414d83207694b', 'id': '26cfb920-601e-458d-b09c-c207a1852f8b', 'project_id': 'f30cd546632e484cb24414d83207694b', , 'id': '530698ed-413e-4bda-b02e-8f6f60380bd1', 'project_id': 'f30cd546632e484cb24414d83207694b', , 'id': '530698ed-413e-4bda-b02e-8f6f60380bd1', 'project_id': 'f30cd546632e484cb24414d83207694b', ------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------+ | --------------------------------------------------------------------------------------------------------------------------------------------+ 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, 'volume': '1', 'rate_value': '0.0000'}] | 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, 'volume': '1E+1', 'rate_value': '0.0000'}] | 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, 'volume': '1', 'rate_value': '0.5000'}] | 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, '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 | a4a3ce1d-bea0-44d3-b9e2-467f441d7d7c | +-------------+--------------------------------------+ # add mapping rule # set a cost of [1.5] per gigabyte root@dlp ~(keystone)# openstack rating hashmap mapping create 1.5 \ -s a4a3ce1d-bea0-44d3-b9e2-467f441d7d7c \ -t flat +--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+ | Mapping ID | Value | Cost | Type | Field ID | Service ID | Group ID | Project ID | +--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+ | 4fb844b7-513c-4303-b090-bb4f345b5dfc | None | 1.5000000000000000000000000000 | flat | None | a4a3ce1d-bea0-44d3-b9e2-467f441d7d7c | None | None | +--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+ # set a 10% discount on over 30 GB volumes root@dlp ~(keystone)# openstack rating hashmap threshold create 30 0.90 \ -s a4a3ce1d-bea0-44d3-b9e2-467f441d7d7c \ -t rate +--------------------------------------+-------------+--------------------------------+------+----------+--------------------------------------+----------+------------+ | Threshold ID | Level | Cost | Type | Field ID | Service ID | Group ID | Project ID | +--------------------------------------+-------------+--------------------------------+------+----------+--------------------------------------+----------+------------+ | a7c75b4d-f44f-40d3-b4e6-e50e0e3c4312 | 30.00000000 | 0.9000000000000000222044604925 | rate | None | a4a3ce1d-bea0-44d3-b9e2-467f441d7d7c | 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 |
+----------------------------------+---------------+------+---------------------+---------------------+
| f30cd546632e484cb24414d83207694b | ALL | 2.0 | 2023-10-01T00:00:00 | 2023-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 | +--------------------------------------+--------+-----------+------+-------------+ | 2acf2d5c-6eb5-4518-9866-68cf963a4438 | 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 | +----------------------------------+---------------+------+---------------------+---------------------+ | f30cd546632e484cb24414d83207694b | ALL | 17.0 | 2023-10-01T00:00:00 | 2023-11-01T00:00:00 | +----------------------------------+---------------+------+---------------------+---------------------+ubuntu@dlp ~(keystone)$ openstack rating dataframes get +---------------------+---------------------+---------------------------------- | Begin | End | Project ID +---------------------+---------------------+---------------------------------- | 2023-10-10T00:10:00 | 2023-10-10T00:20:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T00:30:00 | 2023-10-10T00:40:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T00:50:00 | 2023-10-10T01:00:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T01:00:00 | 2023-10-10T01:10:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T01:10:00 | 2023-10-10T01:20:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T01:20:00 | 2023-10-10T01:30:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T01:30:00 | 2023-10-10T01:40:00 | f30cd546632e484cb24414d83207694b +---------------------+---------------------+---------------------------------- +-------------------------------------------------------------------------------------------------------------- | Resources +-------------------------------------------------------------------------------------------------------------- | [{'rating': '0.0', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', 'flavor_id': '2', 'vcpus': '', | [{'rating': '0.0', 'service': 'volume.size', 'desc': {'volume_type': '05118a15-3b8d-44cd-aa39-d85c1611a863', | [{'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': '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': '__DEFAULT__', 'id': '2acf2d5c-6eb5-451 +-------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------- 'id': '530698ed-413e-4bda-b02e-8f6f60380bd1', 'project_id': 'f30cd546632e484cb24414d83207694b', 'id': '26cfb920-601e-458d-b09c-c207a1852f8b', 'project_id': 'f30cd546632e484cb24414d83207694b', ' 'id': '530698ed-413e-4bda-b02e-8f6f60380bd1', 'project_id': 'f30cd546632e484cb24414d83207694b', 'id': '530698ed-413e-4bda-b02e-8f6f60380bd1', 'project_id': 'f30cd546632e484cb24414d83207694b', 'id': '530698ed-413e-4bda-b02e-8f6f60380bd1', 'project_id': 'f30cd546632e484cb24414d83207694b', 'id': '530698ed-413e-4bda-b02e-8f6f60380bd1', 'project_id': 'f30cd546632e484cb24414d83207694b', 8-9866-68cf963a4438', 'project_id': 'f30cd546632e484cb24414d83207694b', 'user_id': '470c9323dad64 ------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------+ | -------------------------------------------------------------------------------------------------------------------------------------------+ 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, 'volume': '1', 'rate_value': '0.0000'}] | user_id': '470c9323dad64bbea8fb5ecca6381f72', 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, 'volume': '1E+1', 'rate_value': '0.0000'}] | 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, 'volume': '1', 'rate_value': '0.5000'}] | 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, 'volume': '1', 'rate_value': '0.5000'}] | 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, 'volume': '1', 'rate_value': '0.5000'}] | 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, 'volume': '1', 'rate_value': '0.5000'}] | bbea8fb5ecca6381f72', 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, '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 | +--------------------------------------+--------+-----------+------+-------------+ | cf06eba5-67ad-4a5a-bafe-07e0c1e023ab | disk02 | available | 30 | | | 2acf2d5c-6eb5-4518-9866-68cf963a4438 | 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 | +----------------------------------+---------------+------+---------------------+---------------------+ | f30cd546632e484cb24414d83207694b | ALL | 57.5 | 2023-10-01T00:00:00 | 2023-11-01T00:00:00 | +----------------------------------+---------------+------+---------------------+---------------------+ubuntu@dlp ~(keystone)$ openstack rating dataframes get +---------------------+---------------------+---------------------------------- | Begin | End | Project ID +---------------------+---------------------+---------------------------------- | 2023-10-10T00:10:00 | 2023-10-10T00:20:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T00:30:00 | 2023-10-10T00:40:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T00:50:00 | 2023-10-10T01:00:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T01:00:00 | 2023-10-10T01:10:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T01:10:00 | 2023-10-10T01:20:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T01:20:00 | 2023-10-10T01:30:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T01:30:00 | 2023-10-10T01:40:00 | f30cd546632e484cb24414d83207694b | 2023-10-10T01:50:00 | 2023-10-10T02:00:00 | f30cd546632e484cb24414d83207694b +---------------------+---------------------+---------------------------------- +-------------------------------------------------------------------------------- | Resources +-------------------------------------------------------------------------------- | [{'rating': '0.0', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', | [{'rating': '0.0', 'service': 'volume.size', 'desc': {'volume_type': '05118a15- | [{'rating': '0.5', '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', | [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', | [{'rating': '15.0', 'service': 'volume.size', 'desc': {'volume_type': '__DEFAUL | [{'rating': '40.5', 'service': 'volume.size', 'desc': {'volume_type': '__DEFAUL +-------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ 'flavor_id': '2', 'vcpus': '', 'id': '530698ed-413e-4bda-b02e-8f6f60380bd1', 'project_id': 3b8d-44cd-aa39-d85c1611a863', 'id': '26cfb920-601e-458d-b09c-c207a1852f8b', 'project_id': 'flavor_id': '2', 'vcpus': '', 'id': '530698ed-413e-4bda-b02e-8f6f60380bd1', 'project_id': 'flavor_id': '2', 'vcpus': '', 'id': '530698ed-413e-4bda-b02e-8f6f60380bd1', 'project_id': 'flavor_id': '2', 'vcpus': '', 'id': '530698ed-413e-4bda-b02e-8f6f60380bd1', 'project_id': 'flavor_id': '2', 'vcpus': '', 'id': '530698ed-413e-4bda-b02e-8f6f60380bd1', 'project_id': T__', 'id': '2acf2d5c-6eb5-4518-9866-68cf963a4438', 'project_id': 'f30cd546632e484cb24414d T__', 'id': 'cf06eba5-67ad-4a5a-bafe-07e0c1e023ab', 'project_id': 'f30cd546632e484cb24414d ------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------- ----------------------------------------------------------------------------------- 'f30cd546632e484cb24414d83207694b', 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'f30cd546632e484cb24414d83207694b', 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'f30cd546632e484cb24414d83207694b', 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'f30cd546632e484cb24414d83207694b', 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'f30cd546632e484cb24414d83207694b', 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'f30cd546632e484cb24414d83207694b', 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 83207694b', 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'tenant_id': 'f30cd54663 83207694b', 'user_id': '470c9323dad64bbea8fb5ecca6381f72', 'tenant_id': 'f30cd54663 ----------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------+ | ---------------------------------------------------------------------------------------------+ 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, 'volume': '1', 'rate_value': '0.0000'}] | 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, 'volume': '1E+1', 'rate_value': '0.0000'}] | 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, 'volume': '1', 'rate_value': '0.5000'}] | 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, 'volume': '1', 'rate_value': '0.5000'}] | 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, 'volume': '1', 'rate_value': '0.5000'}] | 'tenant_id': 'f30cd546632e484cb24414d83207694b'}, 'volume': '1', 'rate_value': '0.5000'}] | 2e484cb24414d83207694b'}, 'volume': '1E+1', 'rate_value': '1.5000'}] | 2e484cb24414d83207694b'}, 'volume': '3E+1', 'rate_value': '1.3500'}] | ---------------------------------------------------------------------------------------------+ |
Sponsored Link |