OpenStack Antelope : How to use CloudKitty2023/04/20 |
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 | +----------------------------------+-----------+ | 40aa0807595447f0bd8d5b2dbfa1839b | hiroshima | | 6d680c2574034967ab496a59d1319a65 | service | | fa1902e20298477e9e065c0a330e1b6f | 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 | 7420d3ad-7d2a-4ec5-a440-cfc94f303762 | +----------+--------------------------------------+ # add field matching rule [root@dlp ~(keystone)]# openstack rating hashmap field create 7420d3ad-7d2a-4ec5-a440-cfc94f303762 flavor_id +-----------+--------------------------------------+--------------------------------------+ | Name | Field ID | Service ID | +-----------+--------------------------------------+--------------------------------------+ | flavor_id | 2d1dcfa8-7f3f-416d-8e3c-8e06b6bfe16d | 7420d3ad-7d2a-4ec5-a440-cfc94f303762 | +-----------+--------------------------------------+--------------------------------------+[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 | 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 2d1dcfa8-7f3f-416d-8e3c-8e06b6bfe16d \ --value 2 -t flat +--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+ | Mapping ID | Value | Cost | Type | Field ID | Service ID | Group ID | Project ID | +--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+ | 0ce1f467-e1ea-4281-b5bd-bb0aa117584c | 2 | 0.5000000000000000000000000000 | flat | 2d1dcfa8-7f3f-416d-8e3c-8e06b6bfe16d | 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 | +--------------------------------------+------------+---------+-------------------------------------+----------------+-----------+ | 284a5b69-7b76-49c3-8180-c9b22284d429 | CentOS-St9 | SHUTOFF | private=10.0.0.229, 192.168.100.140 | CentOS-Stream9 | m1.medium | +--------------------------------------+------------+---------+-------------------------------------+----------------+-----------+
[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 | +----------------------------------+---------------+------+---------------------+---------------------+ | 40aa0807595447f0bd8d5b2dbfa1839b | ALL | 0.5 | 2023-04-01T00:00:00 | 2023-05-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 | +----------------------------------+---------------+------+---------------------+---------------------+ | 40aa0807595447f0bd8d5b2dbfa1839b | ALL | 1.0 | 2023-04-01T00:00:00 | 2023-05-01T00:00:00 | +----------------------------------+---------------+------+---------------------+---------------------+ # display data frames [cent@dlp ~(keystone)]$ openstack rating dataframes get +---------------------+---------------------+---------------------------------- | Begin | End | Project ID +---------------------+---------------------+---------------------------------- | 2023-04-20T01:00:00 | 2023-04-20T01:10:00 | 40aa0807595447f0bd8d5b2dbfa1839b | 2023-04-20T02:00:00 | 2023-04-20T02:10:00 | 40aa0807595447f0bd8d5b2dbfa1839b | 2023-04-20T02:10:00 | 2023-04-20T02:20:00 | 40aa0807595447f0bd8d5b2dbfa1839b +---------------------+---------------------+---------------------------------- +-------------------------------------------------------------------------------- | 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': '284a5b69-7b76-49c3-8180-c9b22284d429', 'project_id': 'flavor_id': '2', 'vcpus': '', 'id': '284a5b69-7b76-49c3-8180-c9b22284d429', 'project_id': 'flavor_id': '2', 'vcpus': '', 'id': '284a5b69-7b76-49c3-8180-c9b22284d429', 'project_id': ------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------ '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': ------------------------------------------------------------------------------------------------ -------------------------------------------------------------------------------+ | -------------------------------------------------------------------------------+ '40aa0807595447f0bd8d5b2dbfa1839b'}, 'volume': '1', 'rate_value': '0.0000'}] | '40aa0807595447f0bd8d5b2dbfa1839b'}, 'volume': '1', 'rate_value': '0.5000'}] | '40aa0807595447f0bd8d5b2dbfa1839b'}, '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 | c9ece4df-9956-4b7c-b8c8-5f3f85b2388a | +-------------+--------------------------------------+ # add mapping rule # set a cost of [1.5] per gigabyte [root@dlp ~(keystone)]# openstack rating hashmap mapping create 1.5 \ -s c9ece4df-9956-4b7c-b8c8-5f3f85b2388a \ -t flat +--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+ | Mapping ID | Value | Cost | Type | Field ID | Service ID | Group ID | Project ID | +--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+ | 81e7e1b6-0644-445c-96d3-ace145140451 | None | 1.5000000000000000000000000000 | flat | None | c9ece4df-9956-4b7c-b8c8-5f3f85b2388a | None | None | +--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+ # set a 10% discount on over 30 GB volumes [root@dlp ~(keystone)]# openstack rating hashmap threshold create 30 0.90 \ -s c9ece4df-9956-4b7c-b8c8-5f3f85b2388a \ -t rate +--------------------------------------+-------------+--------------------------------+------+----------+--------------------------------------+----------+------------+ | Threshold ID | Level | Cost | Type | Field ID | Service ID | Group ID | Project ID | +--------------------------------------+-------------+--------------------------------+------+----------+--------------------------------------+----------+------------+ | 18d97151-3b69-4c26-9abd-9afe8d173d08 | 30.00000000 | 0.9000000000000000222044604925 | rate | None | c9ece4df-9956-4b7c-b8c8-5f3f85b2388a | 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 |
+----------------------------------+---------------+------+---------------------+---------------------+
| 40aa0807595447f0bd8d5b2dbfa1839b | ALL | 2.0 | 2023-04-01T00:00:00 | 2023-05-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+
[cent@dlp ~(keystone)]$ openstack volume create --size 10 disk01
[cent@dlp ~(keystone)]$ openstack volume list +--------------------------------------+--------+-----------+------+-------------+ | ID | Name | Status | Size | Attached to | +--------------------------------------+--------+-----------+------+-------------+ | 6c113cba-e4b8-4983-bbe8-079f9f62498f | 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 | +----------------------------------+---------------+------+---------------------+---------------------+ | 40aa0807595447f0bd8d5b2dbfa1839b | ALL | 17.0 | 2023-04-01T00:00:00 | 2023-05-01T00:00:00 | +----------------------------------+---------------+------+---------------------+---------------------+[cent@dlp ~(keystone)]$ openstack rating dataframes get +---------------------+---------------------+---------------------------------- | Begin | End | Project ID +---------------------+---------------------+---------------------------------- | 2023-04-20T01:30:00 | 2023-04-20T01:40:00 | 40aa0807595447f0bd8d5b2dbfa1839b | 2023-04-20T02:00:00 | 2023-04-20T02:10:00 | 40aa0807595447f0bd8d5b2dbfa1839b | 2023-04-20T02:10:00 | 2023-04-20T02:20:00 | 40aa0807595447f0bd8d5b2dbfa1839b | 2023-04-20T02:20:00 | 2023-04-20T02:30:00 | 40aa0807595447f0bd8d5b2dbfa1839b | 2023-04-20T02:30:00 | 2023-04-20T02:40:00 | 40aa0807595447f0bd8d5b2dbfa1839b | 2023-04-20T02:40:00 | 2023-04-20T02:50:00 | 40aa0807595447f0bd8d5b2dbfa1839b +---------------------+---------------------+---------------------------------- +-------------------------------------------------------------------------------------------------------------- | Resources +-------------------------------------------------------------------------------------------------------------- | [{'rating': '0.0', 'service': 'volume.size', 'desc': {'volume_type': '9d8db814-8efc-4d34-a17f-17e83a1678a5', | [{'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': '9d8db814-8efc-4d34-a17f-17e83a1678a5', +-------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------- 'id': '0c22c348-b697-4791-ac73-cdcbb5f814fa', 'project_id': '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': 'id': '284a5b69-7b76-49c3-8180-c9b22284d429', 'project_id': '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': 'id': '284a5b69-7b76-49c3-8180-c9b22284d429', 'project_id': '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': 'id': '284a5b69-7b76-49c3-8180-c9b22284d429', 'project_id': '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': 'id': '284a5b69-7b76-49c3-8180-c9b22284d429', 'project_id': '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': 'id': '6c113cba-e4b8-4983-bbe8-079f9f62498f', 'project_id': '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': ----------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------+ | ----------------------------------------------------------------------------------------------------------------------------------+ '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': '40aa0807595447f0bd8d5b2dbfa1839b'}, 'volume': '1E+1', 'rate_value': '0.0000'}] | '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': '40aa0807595447f0bd8d5b2dbfa1839b'}, 'volume': '1', 'rate_value': '0.5000'}] | '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': '40aa0807595447f0bd8d5b2dbfa1839b'}, 'volume': '1', 'rate_value': '0.5000'}] | '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': '40aa0807595447f0bd8d5b2dbfa1839b'}, 'volume': '1', 'rate_value': '0.5000'}] | '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': '40aa0807595447f0bd8d5b2dbfa1839b'}, 'volume': '1', 'rate_value': '0.5000'}] | '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': '40aa0807595447f0bd8d5b2dbfa1839b'}, '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 | +--------------------------------------+--------+-----------+------+-------------+ | 58bf8dfd-f913-4413-88bb-4e8b271252cb | disk02 | available | 30 | | | 6c113cba-e4b8-4983-bbe8-079f9f62498f | 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 | +----------------------------------+---------------+------+---------------------+---------------------+ | 40aa0807595447f0bd8d5b2dbfa1839b | ALL | 57.5 | 2023-04-01T00:00:00 | 2023-05-01T00:00:00 | +----------------------------------+---------------+------+---------------------+---------------------+[cent@dlp ~(keystone)]$ openstack rating dataframes get +---------------------+---------------------+---------------------------------- | Begin | End | Project ID +---------------------+---------------------+---------------------------------- | 2023-04-20T01:30:00 | 2023-04-20T01:40:00 | 40aa0807595447f0bd8d5b2dbfa1839b | 2023-04-20T02:00:00 | 2023-04-20T02:10:00 | 40aa0807595447f0bd8d5b2dbfa1839b | 2023-04-20T02:10:00 | 2023-04-20T02:20:00 | 40aa0807595447f0bd8d5b2dbfa1839b | 2023-04-20T02:20:00 | 2023-04-20T02:30:00 | 40aa0807595447f0bd8d5b2dbfa1839b | 2023-04-20T02:30:00 | 2023-04-20T02:40:00 | 40aa0807595447f0bd8d5b2dbfa1839b | 2023-04-20T02:40:00 | 2023-04-20T02:50:00 | 40aa0807595447f0bd8d5b2dbfa1839b | 2023-04-20T03:00:00 | 2023-04-20T03:10:00 | 40aa0807595447f0bd8d5b2dbfa1839b +---------------------+---------------------+---------------------------------- +-------------------------------------------------------------------------------------------------------------- | Resources +-------------------------------------------------------------------------------------------------------------- | [{'rating': '0.0', 'service': 'volume.size', 'desc': {'volume_type': '9d8db814-8efc-4d34-a17f-17e83a1678a5', | [{'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': '9d8db814-8efc-4d34-a17f-17e83a1678a5', | [{'rating': '40.5', 'service': 'volume.size', 'desc': {'volume_type': '9d8db814-8efc-4d34-a17f-17e83a1678a5', +-------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------- 'id': '0c22c348-b697-4791-ac73-cdcbb5f814fa', 'project_id': '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': 'id': '284a5b69-7b76-49c3-8180-c9b22284d429', 'project_id': '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': 'id': '284a5b69-7b76-49c3-8180-c9b22284d429', 'project_id': '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': 'id': '284a5b69-7b76-49c3-8180-c9b22284d429', 'project_id': '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': 'id': '284a5b69-7b76-49c3-8180-c9b22284d429', 'project_id': '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': 'id': '6c113cba-e4b8-4983-bbe8-079f9f62498f', 'project_id': '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': 'id': '58bf8dfd-f913-4413-88bb-4e8b271252cb', 'project_id': '40aa0807595447f0bd8d5b2dbfa1839b', 'user_id': ----------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------+ | ----------------------------------------------------------------------------------------------------------------------------------+ '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': '40aa0807595447f0bd8d5b2dbfa1839b'}, 'volume': '1E+1', 'rate_value': '0.0000'}] | '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': '40aa0807595447f0bd8d5b2dbfa1839b'}, 'volume': '1', 'rate_value': '0.5000'}] | '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': '40aa0807595447f0bd8d5b2dbfa1839b'}, 'volume': '1', 'rate_value': '0.5000'}] | '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': '40aa0807595447f0bd8d5b2dbfa1839b'}, 'volume': '1', 'rate_value': '0.5000'}] | '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': '40aa0807595447f0bd8d5b2dbfa1839b'}, 'volume': '1', 'rate_value': '0.5000'}] | '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': '40aa0807595447f0bd8d5b2dbfa1839b'}, 'volume': '1E+1', 'rate_value': '1.5000'}] | '3c87f0d4e2e6413aa110a4240357cd97', 'tenant_id': '40aa0807595447f0bd8d5b2dbfa1839b'}, 'volume': '3E+1', 'rate_value': '1.3500'}] | ----------------------------------------------------------------------------------------------------------------------------------+ |
Sponsored Link |
|