Create a rating rule
To create mapping rules for your cloud service cost model, map metrics or resource fields to price values.
About this task Copy linkLink copied!
- Field mapping
- Create a mapping on the field of a resource to create rules based on the value of that field. For example, if you want to apply different rating rules depending on the type of volume, you would create a mapping for each possible value of the field "volume_type".
- Service mapping
- Create a mapping on a service, or metric name, to associate a rating directly with that metric.
Procedure Copy linkLink copied!
Example: Rate instance uptime by flavor Copy linkLink copied!
This example creates a rating rule that assigns a cost to instance uptime based on the flavor_id field, so that different instance sizes are rated at different prices.
- Access the remote shell for the
openstackclientpod from your workstation:$ oc rsh -n openstack openstackclient - Create the group to which you want to apply the
instance_uptime_flavor_idrating rule:$ openstack rating hashmap group create instance_uptime_flavor_id +---------------------------+--------------------------------------+ | Name | Group ID | +---------------------------+--------------------------------------+ | instance_uptime_flavor_id | 9a2ff37d-be86-4642-8b7d-567bace61f06 | +---------------------------+--------------------------------------+ - Confirm that the group is created:
$ openstack rating hashmap group list +---------------------------+--------------------------------------+ | Name | Group ID | +---------------------------+--------------------------------------+ | instance_uptime_flavor_id | 9a2ff37d-be86-4642-8b7d-567bace61f06 | +---------------------------+--------------------------------------+ - Create a service to map the matching rule to the metric type you want to rate:
$ openstack rating hashmap service create instance +----------+--------------------------------------+ | Name | Service ID | +----------+--------------------------------------+ | instance | b19d801d-e7d4-46f9-970b-3e6d60fc07b5 | +----------+--------------------------------------+ - Create a field matching rule:
$ openstack rating hashmap field create b19d801d-e7d4-46f9-970b-3e6d60fc07b5 flavor_id +-----------+--------------------------------------+--------------------------------------+ | Name | Field ID | Service ID | +-----------+--------------------------------------+--------------------------------------+ | flavor_id | 18aa50b6-6da8-4c47-8a1f-43236b971625 | b19d801d-e7d4-46f9-970b-3e6d60fc07b5 | +-----------+--------------------------------------+--------------------------------------+ - Create a mapping in the "instance_uptime_flavor" group that maps the
m1.tinyinstance to a cost of 0.01:- Retrieve the
flavor_idvalue:$ openstack flavor show m1.tiny +----------------------------+----------------------------------------+ | Field | Value | +----------------------------+----------------------------------------+ | OS-FLV-DISABLED:disabled | False | | OS-FLV-EXT-DATA:ephemeral | 0 | | access_project_ids | None | | disk | 20 | | id | 93195dd4-bbf3-4b13-929d-8293ae72e056 | | name | m1.tiny | | os-flavor-access:is_public | True | | properties | baremetal='false', flavor-type='small' | | ram | 512 | | rxtx_factor | 1.0 | | swap | | | vcpus | 1 | +----------------------------+----------------------------------------+ - Create the mapping. The following command creates a mapping that rates the
flavor_idfield with the valuem1.tinyat 0.01, for every machine in any project:$ openstack rating hashmap mapping create 0.01 \ --field-id 18aa50b6-6da8-4c47-8a1f-43236b971625 \ --value 93195dd4-bbf3-4b13-929d-8293ae72e056 \ -g 9a2ff37d-be86-4642-8b7d-567bace61f06 \ -t flat +--------------------------------------+--------------------------------------+---------------------+---------------------+------+------+-------------+---------+----------------------------------+------------+------------+------------+------+--------------------------------------+------------+--------------------------------------+------------+ | Mapping ID | Value | Created At | Start | End | Name | Description | Deleted | Created By | Updated By | Deleted By | Cost | Type | Field ID | Service ID | Group ID | Project ID | +--------------------------------------+--------------------------------------+---------------------+---------------------+------+------+-------------+---------+----------------------------------+------------+------------+------------+------+--------------------------------------+------------+--------------------------------------+------------+ | 9c2418dc-99d3-44b6-8fdf-e9fa02f3ceb5 | 93195dd4-bbf3-4b13-929d-8293ae72e056 | 2023-01-01T10:00:00 | 2023-01-01T10:00:00 | None | None | None | None | 7977999e2e2511e6a8b2df30b233ffcb | None | None | 0.01000000 | flat | 18aa50b6-6da8-4c47-8a1f-43236b971625 | None | 9a2ff37d-be86-4642-8b7d-567bace61f06 | None | +--------------------------------------+--------------------------------------+---------------------+---------------------+------+------+-------------+---------+----------------------------------+------------+------------+------------+------+--------------------------------------+------------+--------------------------------------+------------+
- Retrieve the
Example: Volume pricing with usage thresholds Copy linkLink copied!
This example creates tiered rating rules that apply volume discounts based on GiB usage thresholds, including a project-specific discount rate.
- Up to 50GiB: every volume is rated 0.001 per GiB
- 50GiB - 200GiB: a 2% discount is applied, or 3% for a specific project
- >200GiB: a 5% discount (0.95) is applied
- Access the remote shell for the
openstackclientpod from your workstation:$ oc rsh -n openstack openstackclient - Create the group to which you want to apply the
volume_thresholdsrating rule:$ openstack rating hashmap group create volume_thresholds +-------------------+--------------------------------------+ | Name | Group ID | +-------------------+--------------------------------------+ | volume_thresholds | 9736bbc0-8888-4700-96fc-58db5fded493 | +-------------------+--------------------------------------+ - Confirm that the group is created:
$ openstack rating hashmap group list +-------------------+--------------------------------------+ | Name | Group ID | +-------------------+--------------------------------------+ | volume_thresholds | 9736bbc0-8888-4700-96fc-58db5fded493 | +-------------------+--------------------------------------+ - Create a service to map the matching rule to the metric type you want to rate:
$ openstack rating hashmap service create volume.size +-------------+--------------------------------------+ | Name | Service ID | +-------------+--------------------------------------+ | volume.size | 74ad7e4e-9cae-45a8-884b-368a92803afe | +-------------+--------------------------------------+ - Create a mapping that sets the basic price for each gigabyte used of the "volume.size" service:
$ openstack rating hashmap mapping create 0.001 \ -s 74ad7e4e-9cae-45a8-884b-368a92803afe \ -t flat -g 9736bbc0-8888-4700-96fc-58db5fded493 +--------------------------------------+-------+---------------------+---------------------+------+------+-------------+---------+----------------------------------+------------+------------+------------+------+----------+--------------------------------------+--------------------------------------+------------+ | Mapping ID | Value | Created At | Start | End | Name | Description | Deleted | Created By | Updated By | Deleted By | Cost | Type | Field ID | Service ID | Group ID | Project ID | +--------------------------------------+-------+---------------------+---------------------+------+------+-------------+---------+----------------------------------+------------+------------+------------+------+----------+--------------------------------------+--------------------------------------+------------+ | 09e36b13-ce89-4bd0-bbf1-1b80577031e8 | None | 2023-01-01T10:00:00 | 2023-01-01T10:00:00 | None | None | None | None | 7977999e2e2511e6a8b2df30b233ffcb | None | None | 0.00100000 | flat | None | 74ad7e4e-9cae-45a8-884b-368a92803afe | 9736bbc0-8888-4700-96fc-58db5fded493 | None | +--------------------------------------+-------+---------------------+---------------------+------+------+-------------+---------+----------------------------------+------------+------------+------------+------+----------+--------------------------------------+--------------------------------------+------------+ - Create a threshold rating rule in the group "volume_thresholds" that applies a discount on huge data volumes by mapping different volume quantities to costs.
- The following command sets a threshold that applies a 2% discount (0.98) for volumes larger than 50GiB:
$ openstack rating hashmap threshold create 50 0.98 \ -s 74ad7e4e-9cae-45a8-884b-368a92803afe \ -t rate -g 9736bbc0-8888-4700-96fc-58db5fded493 +--------------------------------------+-------------+------------+------+----------+--------------------------------------+--------------------------------------+------------+ | Threshold ID | Level | Cost | Type | Field ID | Service ID | Group ID | Project ID | +--------------------------------------+-------------+------------+------+----------+--------------------------------------+--------------------------------------+------------+ | ae02175d-beff-4b01-bb3a-00907b05fe66 | 50.00000000 | 0.98000000 | rate | None | 74ad7e4e-9cae-45a8-884b-368a92803afe | 9736bbc0-8888-4700-96fc-58db5fded493 | None | +--------------------------------------+-------------+------------+------+----------+--------------------------------------+--------------------------------------+------------+ - The following command applies a higher discount of 3% discount (0.97) for a specific project,
2d5b39657dc542d4b2a14b685335304e:$ openstack rating hashmap threshold create 50 0.97 \ -s 74ad7e4e-9cae-45a8-884b-368a92803afe \ -t rate -g 9736bbc0-8888-4700-96fc-58db5fded493 \ -p 2d5b39657dc542d4b2a14b685335304e +--------------------------------------+-------------+------------+------+----------+--------------------------------------+--------------------------------------+----------------------------------+ | Threshold ID | Level | Cost | Type | Field ID | Service ID | Group ID | Project ID | +--------------------------------------+-------------+------------+------+----------+--------------------------------------+--------------------------------------+----------------------------------+ | b20504bf-da34-434c-909d-46c2168c6166 | 50.00000000 | 0.97000000 | rate | None | 74ad7e4e-9cae-45a8-884b-368a92803afe | 9736bbc0-8888-4700-96fc-58db5fded493 | 2d5b39657dc542d4b2a14b685335304e | +--------------------------------------+-------------+------------+------+----------+--------------------------------------+--------------------------------------+----------------------------------+ - The following command sets a threshold that applies a 5% discount (0.95) for volumes larger than 200GiB:
$ openstack rating hashmap threshold create 200 0.95 \ -s 74ad7e4e-9cae-45a8-884b-368a92803afe \ -t rate -g 9736bbc0-8888-4700-96fc-58db5fded493 +--------------------------------------+--------------+------------+------+----------+--------------------------------------+--------------------------------------+------------+ | Threshold ID | Level | Cost | Type | Field ID | Service ID | Group ID | Project ID | +--------------------------------------+--------------+------------+------+----------+--------------------------------------+--------------------------------------+------------+ | ed9fd297-37d4-4d9c-8f65-9919d554617b | 200.00000000 | 0.95000000 | rate | None | 74ad7e4e-9cae-45a8-884b-368a92803afe | 9736bbc0-8888-4700-96fc-58db5fded493 | None | +--------------------------------------+--------------+------------+------+----------+--------------------------------------+--------------------------------------+------------+
- The following command sets a threshold that applies a 2% discount (0.98) for volumes larger than 50GiB:
- Access the remote shell for the