Ubuntu 22.04
Sponsored Link

OpenStack Antelope : CloudKitty 利用方法2023/03/29

 
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      |
+----------------------------------+-----------+
| cac657ec003e4c95aaaa30bc0321895f | admin     |
| d3dd87fb1a034f7883539a6a4f83781f | service   |
| e294bd7c00314facacdb46c36fb54ee9 | hiroshima |
+----------------------------------+-----------+

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

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

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

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

root@dlp ~(keystone)#
openstack flavor list

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

# マッピングを作成
# [flavor_id] が [2] のインスタンスに [0.5] ドルのコストを設定
root@dlp ~(keystone)# openstack rating hashmap mapping create 0.5 \
--field-id b342c47b-a43e-47bf-a443-e069f5e7efc7 \
--value 2 -t flat 
+--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+
| Mapping ID                           | Value | Cost                           | Type | Field ID                             | Service ID | Group ID | Project ID |
+--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+
| 82393b12-94b1-4047-8453-17369285888b | 2     | 0.5000000000000000000000000000 | flat | b342c47b-a43e-47bf-a443-e069f5e7efc7 | None       | None     | None       |
+--------------------------------------+-------+--------------------------------+------+--------------------------------------+------------+----------+------------+
[4] [1] で CloudKitty と関連付けたプロジェクトに所属する任意の Openstack ユーザーで、インスタンスを操作して、動作確認します。
ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+-------------+---------+-------------------------------------+------------+-----------+
| ID                                   | Name        | Status  | Networks                            | Image      | Flavor    |
+--------------------------------------+-------------+---------+-------------------------------------+------------+-----------+
| 11987eec-fb38-4de1-a386-3d1d6001bbd3 | Ubuntu-2204 | SHUTOFF | private=10.0.0.252, 192.168.100.100 | Ubuntu2204 | m1.medium |
+--------------------------------------+-------------+---------+-------------------------------------+------------+-----------+
ubuntu@dlp ~(keystone)$
openstack server start Ubuntu-2204
# 一定時間経過後 レートが加算される

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

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| e294bd7c00314facacdb46c36fb54ee9 | ALL           | 0.5  | 2023-03-01T00:00:00 | 2023-04-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

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

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

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| e294bd7c00314facacdb46c36fb54ee9 | ALL           | 1.0  | 2023-03-01T00:00:00 | 2023-04-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

# データフレーム表示

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

+---------------------+---------------------+----------------------------------
| Begin               | End                 | Project ID                       
+---------------------+---------------------+----------------------------------
| 2023-03-29T02:10:00 | 2023-03-29T02:20:00 | e294bd7c00314facacdb46c36fb54ee9 
| 2023-03-29T04:20:00 | 2023-03-29T04:30:00 | e294bd7c00314facacdb46c36fb54ee9 
| 2023-03-29T04:30:00 | 2023-03-29T04:40:00 | e294bd7c00314facacdb46c36fb54ee9 
+---------------------+---------------------+----------------------------------
+--------------------------------------------------------------------------------
| Resources                                                                      
+--------------------------------------------------------------------------------
| [{'rating': '0.0', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', 
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', 
| [{'rating': '0.5', 'service': 'instance', 'desc': {'flavor_name': 'm1.medium', 
+--------------------------------------------------------------------------------
-----------------------------------------------------------------------------
                                                                             
-----------------------------------------------------------------------------
'flavor_id': '2', 'vcpus': '', 'id': '11987eec-fb38-4de1-a386-3d1d6001bbd3', 
'flavor_id': '2', 'vcpus': '', 'id': '11987eec-fb38-4de1-a386-3d1d6001bbd3', 
'flavor_id': '2', 'vcpus': '', 'id': '11987eec-fb38-4de1-a386-3d1d6001bbd3', 
-----------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
                                                                                                 
-------------------------------------------------------------------------------------------------
'project_id': 'e294bd7c00314facacdb46c36fb54ee9', 'user_id': '85236576a97e492791abe70c217c8898', 
'project_id': 'e294bd7c00314facacdb46c36fb54ee9', 'user_id': '85236576a97e492791abe70c217c8898', 
'project_id': 'e294bd7c00314facacdb46c36fb54ee9', 'user_id': '85236576a97e492791abe70c217c8898', 
-------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------+
                                                                                             |
---------------------------------------------------------------------------------------------+
'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, 'volume': '1', 'rate_value': '0.0000'}]    |
'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, 'volume': '1', 'rate_value': '0.5000'}]    |
'tenant_id': 'e294bd7c00314facacdb46c36fb54ee9'}, 'volume': '1', 'rate_value': '0.5000'}]    |
---------------------------------------------------------------------------------------------+
[5] Volume Size にレートを設定します。
[1] で設定したプロジェクト所属ユーザーが、Cinder ボリュームを作成した場合、1 GB 毎に、設定したレートで課金されます。
# サービス マッチング ルールを追加

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

+-------------+--------------------------------------+
| Name        | Service ID                           |
+-------------+--------------------------------------+
| volume.size | f76586d4-e609-4f6f-a446-5ec5d52f8224 |
+-------------+--------------------------------------+

# マッピングを作成
# 1 GB 毎に [1.5] ドルのコストを設定
root@dlp ~(keystone)# openstack rating hashmap mapping create 1.5 \
-s f76586d4-e609-4f6f-a446-5ec5d52f8224 \
-t flat 
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| Mapping ID                           | Value | Cost                           | Type | Field ID | Service ID                           | Group ID | Project ID |
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+
| 96914ec1-3d01-4974-8f0a-50ee935ae602 | None  | 1.5000000000000000000000000000 | flat | None     | f76586d4-e609-4f6f-a446-5ec5d52f8224 | None     | None       |
+--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+

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

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| e294bd7c00314facacdb46c36fb54ee9 | ALL           | 1.0  | 2023-03-01T00:00:00 | 2023-04-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

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

ubuntu@dlp ~(keystone)$
openstack volume list

+--------------------------------------+--------+-----------+------+-------------+
| ID                                   | Name   | Status    | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------+
| d33457d5-34d5-4316-8a10-10e8198a7e7f | disk01 | available |   10 |             |
+--------------------------------------+--------+-----------+------+-------------+

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

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

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| e294bd7c00314facacdb46c36fb54ee9 | ALL           | 16.0 | 2023-03-01T00:00:00 | 2023-04-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

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

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

ubuntu@dlp ~(keystone)$
openstack volume create --size 30 disk02

ubuntu@dlp ~(keystone)$
openstack volume list

+--------------------------------------+--------+-----------+------+-------------+
| ID                                   | Name   | Status    | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------+
| 15f94205-29eb-4b66-9401-930f456afe83 | disk02 | available |   30 |             |
| d33457d5-34d5-4316-8a10-10e8198a7e7f | disk01 | available |   10 |             |
+--------------------------------------+--------+-----------+------+-------------+

# 一定時間経過後 レートが加算される
# 1.5 x 30 x 0.9 = 40.5

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

+----------------------------------+---------------+------+---------------------+---------------------+
| Tenant ID                        | Resource Type | Rate | Begin Time          | End Time            |
+----------------------------------+---------------+------+---------------------+---------------------+
| e294bd7c00314facacdb46c36fb54ee9 | ALL           | 56.5 | 2023-03-01T00:00:00 | 2023-04-01T00:00:00 |
+----------------------------------+---------------+------+---------------------+---------------------+

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

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