CentOS Stream 9
Sponsored Link

OpenStack Zed : CloudKitty 利用方法2022/11/14

 
OpenStack Rating Service (CloudKitty) の利用方法です。
当例では以下のような環境を例に CloudKitty をインストールしています。
------------+-----------------------------+-----------------------------+------------
            |                             |                             |
        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] レートを設定したい各々のプロジェクトで、[cloudkitty] ユーザーを [rating] ロールに追加しておきます。
[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] [Hashmap] モジュールを有効にします。
[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] Instance Uptime にレートを設定します。
[1] で設定したプロジェクト所属ユーザーが、設定した [flavor_id] でインスタンスを起動した場合、[cloudkitty.conf] で設定した [period] の間隔毎に、設定したレートで課金されます。
# サービス マッチング ルールを追加

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

+----------+--------------------------------------+
| Name     | Service ID                           |
+----------+--------------------------------------+
| instance | 11fb6e6f-1590-456b-91f9-6cc6dfc624fe |
+----------+--------------------------------------+

# フィールド マッチング ルールを追加

[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      |
+----+----------+------+------+-----------+-------+-----------+

# マッピングを作成
# [flavor_id] が [0] のインスタンスに [0.5] ドルのコストを設定
[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] [1] で CloudKitty と関連付けたプロジェクトに所属する任意の Openstack ユーザーで、インスタンスを操作して、動作確認します。
[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
# 一定時間経過後 レートが加算される

[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 |
+----------------------------------+---------------+------+---------------------+---------------------+

# インスタンス稼働中は [period] の間隔毎に 設定したレートがさらに課金される

[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 |
+----------------------------------+---------------+------+---------------------+---------------------+

# データフレーム表示

[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] Volume Size にレートを設定します。
[1] で設定したプロジェクト所属ユーザーが、Cinder ボリュームを作成した場合、1 GB 毎に、設定したレートで課金されます。
# サービス マッチング ルールを追加

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

+-------------+--------------------------------------+
| Name        | Service ID                           |
+-------------+--------------------------------------+
| volume.size | 94277f7f-f9fe-4399-9757-263ccae13168 |
+-------------+--------------------------------------+

# マッピングを作成
# 1 GB 毎に [1.5] ドルのコストを設定
[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       |
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+

# 30 GB 以上のボリュームに対して [1.5] ドルのコスト設定から
# 10 % 引きのディスカウントを設定
[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] [1] で CloudKitty と関連付けたプロジェクトに所属する任意の Openstack ユーザーで、ボリュームを作成して、動作確認します。
[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 |             |
+--------------------------------------+--------+-----------+------+-------------+

# 一定時間経過後 レートが加算される

[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 |             |
+--------------------------------------+--------+-----------+------+-------------+

# 一定時間経過後 レートが加算される
# 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'}] |
----------------------------------------------------------------------------------------------------------------------------------+
関連コンテンツ