Ubuntu 22.04
Sponsored Link

OpenStack Zed : CloudKitty 利用方法2022/10/19

 
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      |
+----------------------------------+-----------+
| 231a529f51394426b07c56f2c5ec580e | admin     |
| 4dd1e1f6bac441ff9c77002c3ab4c58a | hiroshima |
| ee51c09c765e4a4d958c2bcc4dbb5665 | service   |
+----------------------------------+-----------+

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 | 8e038b68-3457-4745-83a0-2688535ccfb7 |
+----------+--------------------------------------+

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

root@dlp ~(keystone)#
openstack rating hashmap field create 8e038b68-3457-4745-83a0-2688535ccfb7 flavor_id

+-----------+--------------------------------------+--------------------------------------+
| Name      | Field ID                             | Service ID                           |
+-----------+--------------------------------------+--------------------------------------+
| flavor_id | 379e680e-8a1d-440e-b3a7-bb3136b48c48 | 8e038b68-3457-4745-83a0-2688535ccfb7 |
+-----------+--------------------------------------+--------------------------------------+

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 379e680e-8a1d-440e-b3a7-bb3136b48c48 \
--value 0 -t flat 
+--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+
| Mapping ID                           | Value | Cost                           | Type | Field ID                             | Service ID | Group ID | Project ID |
+--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+
| 33582a2a-bc4b-40de-a956-d3ed67c29dab | 0     | 0.5000000000000000000000000000 | flat | 379e680e-8a1d-440e-b3a7-bb3136b48c48 | None       | None     | None       |
+--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+
[4] [1] で CloudKitty と関連付けたプロジェクトに所属する任意の Openstack ユーザーで、インスタンスを操作して、動作確認します。
ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+-------------+---------+-------------------------------------+------------+----------+
| ID                                   | Name        | Status  | Networks                            | Image      | Flavor   |
+--------------------------------------+-------------+---------+-------------------------------------+------------+----------+
| a456ee32-b105-4c5e-8eae-ddccb48f913e | Ubuntu-2204 | SHUTOFF | private=10.0.0.228, 192.168.100.187 | Ubuntu2204 | m1.small |
+--------------------------------------+-------------+---------+-------------------------------------+------------+----------+
ubuntu@dlp ~(keystone)$
openstack server start Ubuntu-2204
# 一定時間経過後 レートが加算される

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

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| 4dd1e1f6bac441ff9c77002c3ab4c58a | ALL           | 0.5  | 2022-10-01T00:00:00 | 2022-11-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

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

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

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| 4dd1e1f6bac441ff9c77002c3ab4c58a | ALL           | 1.0  | 2022-10-01T00:00:00 | 2022-11-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

# データフレーム表示

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

+---------------------+---------------------+----------------------------------
| Begin               | End                 | Project ID                       
+---------------------+---------------------+----------------------------------
| 2022-10-18T14:10:00 | 2022-10-18T14:20:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T14:20:00 | 2022-10-18T14:30:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
+---------------------+---------------------+----------------------------------
+-------------------------------------------------------------------------------
| 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': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': 
'flavor_id': '0', 'vcpus': '', 'id': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': 
-------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
                                                                                   
-----------------------------------------------------------------------------------
'4dd1e1f6bac441ff9c77002c3ab4c58a', 'user_id': '9345b7f4de21427abf31ad308cf952f8', 
'4dd1e1f6bac441ff9c77002c3ab4c58a', 'user_id': '9345b7f4de21427abf31ad308cf952f8', 
-----------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------+
                                                                                             |
---------------------------------------------------------------------------------------------+
'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1', 'rate_value': '0.5000'}]    |
'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, '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 | ba16a032-a03f-47cf-92b3-1d8e2100fd79 |
+-------------+--------------------------------------+

# マッピングを作成
# 1 GB 毎に [1.5] ドルのコストを設定
root@dlp ~(keystone)# openstack rating hashmap mapping create 1.5 \
-s ba16a032-a03f-47cf-92b3-1d8e2100fd79 \
-t flat 
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| Mapping ID                           | Value | Cost                           | Type | Field ID | Service ID                           | Group ID | Project ID |
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| f8fe830f-5514-4bd0-802f-f3e36b2ea685 | None  | 1.5000000000000000000000000000 | flat | None     | ba16a032-a03f-47cf-92b3-1d8e2100fd79 | None     | None       |
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+

# 30 GB 以上のボリュームに対して [1.5] ドルのコスト設定から
# 10 % 引きのディスカウントを設定
root@dlp ~(keystone)# openstack rating hashmap threshold create 30 0.90 \
-s ba16a032-a03f-47cf-92b3-1d8e2100fd79 \
-t rate 
+--------------------------------------+-------------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| Threshold ID                         | Level       | Cost                           | Type | Field ID | Service ID                           | Group ID | Project ID |
+--------------------------------------+-------------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| ab5ba7a9-4f4a-48fe-8e5f-5853bf16755a | 30.00000000 | 0.9000000000000000222044604925 | rate | None     | ba16a032-a03f-47cf-92b3-1d8e2100fd79 | None     | None       |
+--------------------------------------+-------------+--------------------------------+------+----------+--------------------------------------+----------+------------+
[6] [1] で CloudKitty と関連付けたプロジェクトに所属する任意の Openstack ユーザーで、ボリュームを作成して、動作確認します。
ubuntu@dlp ~(keystone)$
openstack rating summary get

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| 4dd1e1f6bac441ff9c77002c3ab4c58a | ALL           | 1.5  | 2022-10-01T00:00:00 | 2022-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 |
+--------------------------------------+--------+-----------+------+-------------+
| e61f677f-bdd2-4e04-874f-582471263d1c | disk01 | available |   10 |             |
+--------------------------------------+--------+-----------+------+-------------+

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

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

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| 4dd1e1f6bac441ff9c77002c3ab4c58a | ALL           | 16.5 | 2022-10-01T00:00:00 | 2022-11-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

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

+---------------------+---------------------+----------------------------------
| Begin               | End                 | Project ID                       
+---------------------+---------------------+----------------------------------
| 2022-10-18T14:10:00 | 2022-10-18T14:20:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T14:20:00 | 2022-10-18T14:30:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T14:30:00 | 2022-10-18T14:40:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T14:40:00 | 2022-10-18T14:50:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
+---------------------+---------------------+----------------------------------
+--------------------------------------------------------------------------------------------------------------
| 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': '15.0', 'service': 'volume.size', 'desc': {'volume_type': '14cf70ec-0fb5-4fec-9cfd-9d719bedc097',
+--------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
                                                                                                
------------------------------------------------------------------------------------------------
'id': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a', 
'id': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a', 
'id': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a', 
 'id': 'e61f677f-bdd2-4e04-874f-582471263d1c', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a',
------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------+
                                                                                                                                             |
---------------------------------------------------------------------------------------------------------------------------------------------+
'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1', 'rate_value': '0.5000'}]     |
'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1', 'rate_value': '0.5000'}]     |
'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1', 'rate_value': '0.5000'}]     |
 'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, '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 |
+--------------------------------------+--------+-----------+------+-------------+
| 48a6eb5d-3e72-414a-9996-70b377fb66b1 | disk02 | available |   30 |             |
| e61f677f-bdd2-4e04-874f-582471263d1c | disk01 | available |   10 |             |
+--------------------------------------+--------+-----------+------+-------------+

# 一定時間経過後 レートが加算される
# 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            |
+----------------------------------+---------------+------+---------------------+---------------------+
| 4dd1e1f6bac441ff9c77002c3ab4c58a | ALL           | 57.0 | 2022-10-01T00:00:00 | 2022-11-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

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

+---------------------+---------------------+----------------------------------
| Begin               | End                 | Project ID                       
+---------------------+---------------------+----------------------------------
| 2022-10-18T14:10:00 | 2022-10-18T14:20:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T14:20:00 | 2022-10-18T14:30:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T14:30:00 | 2022-10-18T14:40:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T14:40:00 | 2022-10-18T14:50:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
| 2022-10-18T15:20:00 | 2022-10-18T15:30:00 | 4dd1e1f6bac441ff9c77002c3ab4c58a 
+---------------------+---------------------+----------------------------------
+--------------------------------------------------------------------------------------------------------------
| 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': '15.0', 'service': 'volume.size', 'desc': {'volume_type': '14cf70ec-0fb5-4fec-9cfd-9d719bedc097',
| [{'rating': '40.5', 'service': 'volume.size', 'desc': {'volume_type': '14cf70ec-0fb5-4fec-9cfd-9d719bedc097',
+--------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
                                                                                                
------------------------------------------------------------------------------------------------
'id': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a', 
'id': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a', 
'id': 'a456ee32-b105-4c5e-8eae-ddccb48f913e', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a', 
 'id': 'e61f677f-bdd2-4e04-874f-582471263d1c', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a',
 'id': '48a6eb5d-3e72-414a-9996-70b377fb66b1', 'project_id': '4dd1e1f6bac441ff9c77002c3ab4c58a',
------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------+
                                                                                                                                             |
---------------------------------------------------------------------------------------------------------------------------------------------+
'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1', 'rate_value': '0.5000'}]     |
'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1', 'rate_value': '0.5000'}]     |
'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1', 'rate_value': '0.5000'}]     |
 'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '1E+1', 'rate_value': '1.5000'}] |
 'user_id': '9345b7f4de21427abf31ad308cf952f8', 'tenant_id': '4dd1e1f6bac441ff9c77002c3ab4c58a'}, 'volume': '3E+1', 'rate_value': '1.3500'}] |
---------------------------------------------------------------------------------------------------------------------------------------------+
関連コンテンツ