OpenStack Antelope : CloudKitty 利用方法2023/04/20 |
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 | +----------------------------------+-----------+ | 40aa0807595447f0bd8d5b2dbfa1839b | hiroshima | | 6d680c2574034967ab496a59d1319a65 | service | | fa1902e20298477e9e065c0a330e1b6f | 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 | 7420d3ad-7d2a-4ec5-a440-cfc94f303762 | +----------+--------------------------------------+ # フィールド マッチング ルールを追加 [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 | +----+-----------+------+------+-----------+-------+-----------+ # マッピングを作成 # [flavor_id] が [2] のインスタンスに [0.5] ドルのコストを設定 [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] | [1] で CloudKitty と関連付けたプロジェクトに所属する任意の Openstack ユーザーで、インスタンスを操作して、動作確認します。 |
[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
# 一定時間経過後 レートが加算される [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 | +----------------------------------+---------------+------+---------------------+---------------------+ # インスタンス稼働中は [period] の間隔毎に 設定したレートがさらに課金される [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 | +----------------------------------+---------------+------+---------------------+---------------------+ # データフレーム表示 [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] | Volume Size にレートを設定します。 [1] で設定したプロジェクト所属ユーザーが、Cinder ボリュームを作成した場合、1 GB 毎に、設定したレートで課金されます。 |
# サービス マッチング ルールを追加 [root@dlp ~(keystone)]# openstack rating hashmap service create volume.size +-------------+--------------------------------------+ | Name | Service ID | +-------------+--------------------------------------+ | volume.size | c9ece4df-9956-4b7c-b8c8-5f3f85b2388a | +-------------+--------------------------------------+ # マッピングを作成 # 1 GB 毎に [1.5] ドルのコストを設定 [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 | +--------------------------------------+-------+--------------------------------+------+----------+--------------------------------------+----------+------------+ # 30 GB 以上のボリュームに対して [1.5] ドルのコスト設定から # 10 % 引きのディスカウントを設定 [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] | [1] で CloudKitty と関連付けたプロジェクトに所属する任意の Openstack ユーザーで、ボリュームを作成して、動作確認します。 |
[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 | | +--------------------------------------+--------+-----------+------+-------------+ # 一定時間経過後 レートが加算される [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 | | +--------------------------------------+--------+-----------+------+-------------+ # 一定時間経過後 レートが加算される # 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 |
|