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

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

  1. Access the remote shell for the openstackclient pod from your workstation:
    $ oc rsh -n openstack openstackclient
  2. Create the group to which you want to apply the rating rule:
    $ openstack rating hashmap group create <group_name>

    where:

    <group_name>
    Specifies a name that represents a resource usage to which you want to apply rating rules. For example, "instance_uptime" or "block_storage_volume".
  3. Retrieve the names for the available metrics that you can configure:
    $ openstack rating info config get

    This command retrieves the metrics that are collected for your cloud environment. For more information on how to understand the output returned by this command, see Rating metrics definition and collection options.

  4. Create a service to map the matching rule to the metric type you want to rate:
    $ openstack rating hashmap service create <metric_name>

    where:

    <metric_name>
    Specifies the name of the metric or an alias, for example, "instance".
  5. Confirm that the service was created:
    $ openstack rating hashmap service list
    +-----------------------+--------------------------------------+
    | Name                  | Service ID                           |
    +-----------------------+--------------------------------------+
    | ceilometer_image_size | 2dd538dd-dca3-4f3d-957c-aa2d94454331 |
    | instance              | b19d801d-e7d4-46f9-970b-3e6d60fc07b5 |
    +-----------------------+--------------------------------------+
  6. Optional: Create a field matching rule:
    $ openstack rating hashmap field create <service_id> <field_name>

    where:

    <service_id>
    Specifies the ID of the service you created to map the matching rule to the metric type.
    <field_name>
    Specifies the name of the resource field on which to apply the rating. You can use any of the groupby and metadata attributes specified in the metric configuration as a field, for example, "flavor_id".
  7. Create a mapping in the group that maps a type of service to a cost:
    $ openstack rating hashmap mapping create <cost> \
     [--field-id <field_id> --value <service_type_id> \ ]
     -s <service_id> \
     -g <group_id>\
     -t <map_type>

    where:

    <cost>
    Specifies the actual cost for the rating period. The cost field has a precision of 12 digits for the integer and 28 digits for the decimal.
    --field-id and --value
    Specify optional options to define the field value for the cost mapping. Replace <field_id> with the ID of the field and replace <service_type_id> with the ID of the resource of the field. Use the following command to retrieve the field ID: $ openstack rating hashmap field list <service_id>
    <service_id>
    Specifies the ID of the service.
    <group_id>
    Specifies the ID of the group.
    <map_type>

    Specifies one of the following valid values:

    • flat: Add the cost to the total for a given item. If several flat mappings of the same group match, only the most expensive one is applied.
    • rate: Multiplies the total cost by the rate.
    <start_date>
    Specifies the date from which the rating applies.
    <end_date>
    Specifies the date the rating no longer applies.
  8. Optional: Create thresholds for mapping different costs based on usage or project:
    $ openstack rating hashmap threshold create <threshold_level> <rate> \
     -s <service_id> \
     -t rate -g <group_id> \
     -p <project_id>

    where:

    <threshold_level>
    Specifies the level at which to apply the rating rules.
  9. Verify that the metrics data is being collected and rated correctly against the rating rules:
    $ openstack rating dataframes get

    Example output:

    | 2026-03-01T01:40:00 | 2026-03-01T01:45:00 | 64dabd72a70946c9b11dc6681a43aea9 | [{'rating': '0.0', 'service': 'ceilometer_image_size', 'desc': {'container_format': '', 'disk_format': '', 'project': '64dabd72a70946c9b11dc6681a43aea9', 'id': '', 'user_id': '', 'week_of_the_year': '09', 'day_of_the_year': '60', 'month': '3', 'year': '2026'}, 'volume': |
    | | | | '15.5874023', 'rate_value': '0.0000'}] |
    | 2026-03-01T01:45:00 | 2026-03-01T01:50:00 | 64dabd72a70946c9b11dc6681a43aea9 | [{'rating': '0.0', 'service': 'ceilometer_image_size', 'desc': {'container_format': '', 'disk_format': '', 'project': '64dabd72a70946c9b11dc6681a43aea9', 'id': '', 'user_id': '', 'week_of_the_year': '09', 'day_of_the_year': '60', 'month': '3', 'year': '2026'}, 'volume': |
    | | | | '15.5874023', 'rate_value': '0.0000'}] |
    ...
  10. Exit the openstackclient pod:
    $ exit

Example: Rate instance uptime by flavor

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.

  1. Access the remote shell for the openstackclient pod from your workstation:
    $ oc rsh -n openstack openstackclient
  2. Create the group to which you want to apply the instance_uptime_flavor_id rating rule:
    $ openstack rating hashmap group create instance_uptime_flavor_id
    +---------------------------+--------------------------------------+
    | Name                      | Group ID                             |
    +---------------------------+--------------------------------------+
    | instance_uptime_flavor_id | 9a2ff37d-be86-4642-8b7d-567bace61f06 |
    +---------------------------+--------------------------------------+
  3. Confirm that the group is created:
    $ openstack rating hashmap group list
    +---------------------------+--------------------------------------+
    | Name                      | Group ID                             |
    +---------------------------+--------------------------------------+
    | instance_uptime_flavor_id | 9a2ff37d-be86-4642-8b7d-567bace61f06 |
    +---------------------------+--------------------------------------+
  4. 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 |
    +----------+--------------------------------------+
  5. 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 |
    +-----------+--------------------------------------+--------------------------------------+
  6. Create a mapping in the "instance_uptime_flavor" group that maps the m1.tiny instance to a cost of 0.01:
    1. Retrieve the flavor_id value:
      $ 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                                      |
      +----------------------------+----------------------------------------+
    2. Create the mapping. The following command creates a mapping that rates the flavor_id field with the value m1.tiny at 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       |
      +--------------------------------------+--------------------------------------+---------------------+---------------------+------+------+-------------+---------+----------------------------------+------------+------------+------------+------+--------------------------------------+------------+--------------------------------------+------------+

Example: Volume pricing with usage thresholds

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
    1. Access the remote shell for the openstackclient pod from your workstation:
      $ oc rsh -n openstack openstackclient
    2. Create the group to which you want to apply the volume_thresholds rating rule:
      $ openstack rating hashmap group create volume_thresholds
      +-------------------+--------------------------------------+
      | Name              | Group ID                             |
      +-------------------+--------------------------------------+
      | volume_thresholds | 9736bbc0-8888-4700-96fc-58db5fded493 |
      +-------------------+--------------------------------------+
    3. Confirm that the group is created:
      $ openstack rating hashmap group list
      +-------------------+--------------------------------------+
      | Name              | Group ID                             |
      +-------------------+--------------------------------------+
      | volume_thresholds | 9736bbc0-8888-4700-96fc-58db5fded493 |
      +-------------------+--------------------------------------+
    4. 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 |
      +-------------+--------------------------------------+
    5. 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       |
      +--------------------------------------+-------+---------------------+---------------------+------+------+-------------+---------+----------------------------------+------------+------------+------------+------+----------+--------------------------------------+--------------------------------------+------------+
    6. 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.
      1. 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       |
        +--------------------------------------+-------------+------------+------+----------+--------------------------------------+--------------------------------------+------------+
      2. 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 |
        +--------------------------------------+-------------+------------+------+----------+--------------------------------------+--------------------------------------+----------------------------------+
      3. 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       |
        +--------------------------------------+--------------+------------+------+----------+--------------------------------------+--------------------------------------+------------+