Title: Quota: custom tariffs · Issue #5891 · apache/cloudstack · GitHub
Open Graph Title: Quota: custom tariffs · Issue #5891 · apache/cloudstack
X Title: Quota: custom tariffs · Issue #5891 · apache/cloudstack
Description: ISSUE TYPE Enhancement Request COMPONENT NAME Quota, billing CLOUDSTACK VERSION 4.16/main SUMMARY This spec changes the Cloudstack's Quota Plugin to allow operators to customize tariffs based on characteristics of the billed resources. T...
Open Graph Description: ISSUE TYPE Enhancement Request COMPONENT NAME Quota, billing CLOUDSTACK VERSION 4.16/main SUMMARY This spec changes the Cloudstack's Quota Plugin to allow operators to customize tariffs based on ch...
X Description: ISSUE TYPE Enhancement Request COMPONENT NAME Quota, billing CLOUDSTACK VERSION 4.16/main SUMMARY This spec changes the Cloudstack's Quota Plugin to allow operators to customize tariffs based o...
Opengraph URL: https://github.com/apache/cloudstack/issues/5891
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Quota: custom tariffs","articleBody":"##### ISSUE TYPE\r\n * Enhancement Request\r\n\r\n##### COMPONENT NAME\r\n~~~\r\nQuota, billing\r\n~~~\r\n\r\n##### CLOUDSTACK VERSION\r\n4.16/main\r\n\r\n##### SUMMARY\r\n\r\nThis spec changes the Cloudstack's Quota Plugin to allow operators to customize tariffs based on characteristics of the billed resources.\r\n\r\n---\r\n\r\n# Table of Contents\r\n- [Problem description](#problem-description)\r\n - [Current workflows](#problem-description--current-workflows)\r\n - [Calculate usage](#problem-description--current-workflows--calculate-usage)\r\n - [List tariff](#problem-description--current-workflows--list-tariff)\r\n - [Update tariff](#problem-description--current-workflows--update-tariff)\r\n- [Proposed changes](#proposed-changes)\r\n - [Proposed workflows](#proposed-changes--proposed-workflows)\r\n - [Calculate usage](#proposed-changes--proposed-workflows--calculate-usage)\r\n - [List tariff](#proposed-changes--proposed-workflows--list-tariff)\r\n - [Update tariff](#proposed-changes--proposed-workflows--update-tariff)\r\n - [Create tariff](#proposed-changes--proposed-workflows--create-tariff)\r\n - [Delete tariff](#proposed-changes--proposed-workflows--delete-tariff)\r\n - [Rules processing and variables](#proposed-changes--rules-processing-and-variables)\r\n - [Default](#proposed-changes--rules-processing-and-variables--default)\r\n - [RUNNING_VM](#proposed-changes--rules-processing-and-variables--running-vm)\r\n - [ALLOCATED_VM](#proposed-changes--rules-processing-and-variables--allocated-vm)\r\n - [VOLUME](#proposed-changes--rules-processing-and-variables--volume)\r\n - [TEMPLATE/ISO](#proposed-changes--rules-processing-and-variables--template-iso)\r\n - [SNAPSHOT](#proposed-changes--rules-processing-and-variables--snapshot)\r\n - [NETWORK_OFFERING](#proposed-changes--rules-processing-and-variables--network-offering)\r\n - [VM_SNAPSHOT](#proposed-changes--rules-processing-and-variables--vm-snapshot)\r\n - [Others resources](#proposed-changes--rules-processing-and-variables--other-resources)\r\n - [Script samples](#proposed-changes--script-samples)\r\n - [Billing example](#proposed-changes--billing-example)\r\n- [Work items](#work-items)\r\n- [Future works](#future-works)\r\n\r\n---\r\n\r\n\u003ca name=\"problem-description\"/\u003e\r\n\r\nProblem description\r\n===============\r\n\r\nCurrently, ACS's **Quota Plugin** accounts for different resources:\r\n\r\n```sh\r\nRUNNING_VM\r\nALLOCATED_VM\r\nIP_ADDRESS\r\nNETWORK_BYTES_SENT\r\nNETWORK_BYTES_RECEIVED\r\nVOLUME\r\nTEMPLATE\r\nISO\r\nSNAPSHOT\r\nSECURITY_GROUP\r\nLOAD_BALANCER_POLICY\r\nPORT_FORWARDING_RULE\r\nNETWORK_OFFERING\r\nVPN_USERS\r\nCPU_SPEED\r\nvCPU\r\nMEMORY\r\nVM_DISK_IO_READ\r\nVM_DISK_IO_WRITE\r\nVM_DISK_BYTES_READ\r\nVM_DISK_BYTES_WRITE\r\nVM_SNAPSHOT\r\n```\r\n\r\nEach element assumes only one tariff/price, turning it into an one to one relationship:\r\n\r\n\r\n\r\nTherefore, for example, for every **RUNNING_VM**, we must apply the same tariff/price, as well as every **ALLOCATED_VM**. However, there are situations where one resource needs to have different tariffs/prices. These situations can be related to characteristics of the business, such as Windows (or other O.S.) licensing, performance of the primary storage where volumes are allocated, and who is the owner of the resource. Examples of mapped cases till now:\r\n\r\n| **Characteristic** | **Example** |\r\n| ------ | ------ |\r\n| owner (account/domain/project) | Owner **X** has a special contract and will pay a different price per resource. |\r\n| volume of allocated resource for the owner | If owner **X** has less than 10 VMs, the owner will pay **Y**, otherwise, **Z**. |\r\n| O.S. | VMs with Windows (or other built-in licensing) costs more. |\r\n| storage tags | Volumes with tag **SSD NVME** costs more. |\r\n| host tags | VMs with tag **CPU platinum** costs more. |\r\n\r\n\r\nAlso, there are three (3) running VM resources in separated tariffs:\r\n- **CPU_SPEED** (**CPU_CLOCK_RATE** in ACS's enum);\r\n- **vCPU** (**CPU_NUMBER** in ACS's enum);\r\n- **MEMORY** (**MEMORY** in ACS's enum);\r\n\r\nThey are accounted together with **RUNNING_VM**, however, only to fixed service offerings.\r\n\r\n---\r\n\u003ca name=\"problem-description--current-workflows\"/\u003e\r\n\r\n## Current workflows\r\n\r\nCurrent **calculate usage**, **list tariff** and **update tariff** workflows are:\r\n\r\n---\r\n\r\n\u003ca name=\"problem-description--current-workflows--calculate-usage\"/\u003e\r\n\r\n- Calculate usage:\r\n\r\n\u003cimg src=\"https://user-images.githubusercontent.com/38945620/150794770-8ff87aca-9953-4808-b7e6-211e07db33c0.png\" alt=\"calculate-usage\" width=\"400\"/\u003e\r\n\r\n---\r\n\r\n\u003ca name=\"problem-description--current-workflows--list-tariff\"/\u003e\r\n\r\n- List tariff:\r\n\u003cimg src=\"https://user-images.githubusercontent.com/38945620/150794788-1ce8a577-e28f-4fc1-ba5f-c7c9606ea3a9.png\" alt=\"list-tariff\" width=\"400\"/\u003e\r\n\r\n---\r\n\r\n\u003ca name=\"problem-description--current-workflows--update-tariff\"/\u003e\r\n\r\n- Update tariff:\r\n\u003cimg src=\"https://user-images.githubusercontent.com/38945620/150794809-0cbdcdb7-8495-4ec8-8ce7-b8dedd595498.png\" alt=\"update-tariff\" width=\"400\"/\u003e\r\n\r\n---\r\n\r\n\u003ca name=\"proposed-changes\"/\u003e\r\n\r\nProposed changes\r\n==============\r\n\r\nThis proposal intends to change the paradigm of the feature by allowing tariff customization and making the relationship between resource and tariff **one to zero or many**: \r\n\r\n\r\n\r\nFor each one of the resources (listed in the section **Problem description**), operators will be able to create many tariffs as needed and define (or not) the activation rules for each tariff and its duration (the start date will always be required). Activation rules will be used to define if a tariff should be applied to a resource being rated; if no activation rule is provided, we assume that it is applied to all resources of the given type. When updating the tariff, the previous one will be removed and a new one will be created. However, to ensure traceability of the record, a common identifier will be kept.\r\n\r\nAs in this proposal the tariffs will be custom, instead of having one tariff type for each VM resource, the values will be injected as preset variables into the **RUNNING_VM** resource, allowing operators to charge them. The current **vCPU**, **CPU_SPEED** and **MEMORY** tariffs will be converted to **RUNNING_VM** tariffs with respective activation rules and their types will be removed from ACS.\r\n\r\n---\r\n\r\n\u003ca name=\"proposed-changes--proposed-workflows\"/\u003e\r\n\r\n## Proposed workflows\r\n\r\nProposed **calculate usage**, **list tariff** and **update tariff** workflows are:\r\n\r\n---\r\n\r\n\u003ca name=\"proposed-changes--proposed-workflows--calculate-usage\"/\u003e\r\n\r\n- Calculate usage:\r\n\r\n\u003cimg src=\"https://user-images.githubusercontent.com/38945620/150795343-7004aa1d-3845-41e6-9366-9dcf6302441c.png\" alt=\"calculate-usage\" width=\"800\"/\u003e\r\n\r\n---\r\n\r\n\u003ca name=\"proposed-changes--proposed-workflows--list-tariff\"/\u003e\r\n\r\n- List tariff:\r\n\r\n\u003cimg src=\"https://user-images.githubusercontent.com/38945620/150795395-d2633557-cb76-4e58-87e6-c3c47c08f23f.png\" alt=\"list-tariff\" width=\"400\"/\u003e\r\n\r\n This API will receive three (3) new parameters:\r\n\r\n| **Parameters** | **Description** | **Required** | **Value** |\r\n| ------ | ------ | ------ | ------ |\r\n| name | To retrieve tariff by its name. | No | The name of the tariff. |\r\n| enddate | To retrieve tariffs with end date less or equal to the parameter. | No | Any date (format yyyy-MM-dd). |\r\n| listall | To retrieve even removed tariffs. | No | **true** or **false**. |\r\n\r\n---\r\n\r\n\u003ca name=\"proposed-changes--proposed-workflows--update-tariff\"/\u003e\r\n\r\n- Update tariff:\r\n\r\n\u003cimg src=\"https://user-images.githubusercontent.com/38945620/150795819-e28eccef-6714-48ce-baf1-18118e09ce55.png\" alt=\"update-tariff\" width=\"400\"/\u003e\r\n\r\n| **Parameters** | **Description** | **Required** | **Value** |\r\n| ------ | ------ | ------ | ------ |\r\n| id | UUID of the tariff to update. | Yes | The UUID of the tariff. |\r\n| description | Description of the tariff. | No | Any string (max 65535 characters). |\r\n| value | The price of the tariff. | No | Any float value. |\r\n| activationrule | The rule to apply the tariff. Null means that it will always by applied. | No | Any JavaScript code (max 65535 characters). |\r\n| enddate | Date when the tariff will stop to be applied. | No | Any date (format yyyy-MM-dd) from the current date and after or equal **startdate**. |\r\n\r\nThe parameter **usagetype** will be kept, however it will not be used and a warning message is going to show that it is ignored for the request. Moreover, it will be removed in future releases.\r\n\r\n---\r\n\r\nAlso, will be necessary to create two (2) new APIs:\r\n\r\n\r\n---\r\n\r\n\u003ca name=\"proposed-changes--proposed-workflows--create-tariff\"/\u003e\r\n\r\n- Create tariff: this API will allow operators to create new tariffs for the listed resources;\r\n\r\n\u003cimg src=\"https://user-images.githubusercontent.com/38945620/150801454-02d64eb9-88d1-44a1-986b-667a150324b0.png\" alt=\"create-tariff\" width=\"400\"/\u003e\r\n\r\n| **Parameters** | **Description** | **Required** | **Value** |\r\n| ------ | ------ | ------ | ------ |\r\n| name | An unique name for the tariff. | Yes | Any string (max 65535 characters). |\r\n| description | Description of the tariff. | No | Any string (max 65535 characters). |\r\n| usagetype | Resource type of the tariff. | Yes | Any of the resource types (listed in the section **Problem description**). |\r\n| value | The price of the tariff. | Yes | Any float value. |\r\n| activationrule | The rule to apply the tariff. Null means that it will always by applied. | No | Any JavaScript code (max 65535 characters). |\r\n| startdate | Date when the tariff will start to be applied. | No | Any date from the current date. If this parameter is not informed, the default value will be D+1. |\r\n| enddate | Date when the tariff will stop to be applied. | No | Any date from the current date and after or equal **startdate**. |\r\n\r\n---\r\n\r\n\u003ca name=\"proposed-changes--proposed-workflows--delete-tariff\"/\u003e\r\n\r\n- Delete tariff: this API will mark the tariff as removed;\r\n\r\n\u003cimg src=\"https://user-images.githubusercontent.com/38945620/150802258-e1845088-3373-45c9-90ae-95e84b800e9c.png\" alt=\"delete-tariff\" width=\"400\"/\u003e\r\n\r\n| **Parameters** | **Description** | **Required** | **Value** |\r\n| ------ | ------ | ------ | ------ |\r\n| id | The UUID of the tariff. | Yes | The UUID of the tariff. |\r\n\r\n---\r\n\r\n\u003ca name=\"proposed-changes--rules-processing-and-variables\"/\u003e\r\n\r\n## Rules processing and variables\r\n\r\nTo process the activation rules, it will be used the library [J2V8](https://github.com/eclipsesource/J2V8) which \"...is a set of Java bindings for V8. J2V8 focuses on performance and tight integration with V8...\". It has a considerable relevance, good performance and is easy to implement. Therefore, the activation rule expressions must be written in **JavaScript code**[^1] and return a boolean or number value[^2]. If there is no expression to be evaluated or the expression is empty, the tariff will always be applied.\r\n\r\nSome variables will be pre-created into the code's context to give more flexibility to operators. Each resource type will have a series of\r\nvariables corresponding to their characteristics:\r\n\r\n--- \r\n\r\n\u003ca name=\"proposed-changes--rules-processing-and-variables--default\"/\u003e\r\n\r\n### Default\r\n\r\n| **Variable** | **Description** |\r\n| ------ | ------ |\r\n| account.id | UUID of the account owner of the resource.|\r\n| account.name | Name of the account owner of the resource.|\r\n| account.role.id | UUID of the role of the account owner of the resource (if exists).|\r\n| account.role.name | Name of the role of the account owner of the resource (if exists).|\r\n| account.role.type | Type of the role of the account owner of the resource (if exists).|\r\n| domain.id | UUID of the domain owner of the resource.|\r\n| domain.name | Name of the domain owner of the resource.|\r\n| domain.path | Path of the domain owner of the resource.|\r\n| project.id | UUID of the project owner of the resource (if exists).|\r\n| project.name | Name of the project owner of the resource (if exists).|\r\n| resourceType | Type of the record.|\r\n| value.accountResources | List of resources of the account between the start and end date of the usage record being calculated (i.e.: **[{zoneId: ..., domainId:...}]**).|\r\n| zone.id | UUID of the zone owner of the resource.|\r\n| zone.name | Name of the zone owner of the resource.|\r\n\r\n--- \r\n\r\n\u003ca name=\"proposed-changes--rules-processing-and-variables--running-vm\"/\u003e\r\n\r\n### RUNNING_VM\r\n\r\n| **Variable** | **Description** |\r\n| ------ | ------ |\r\n| value.host.id | UUID of the host where the VM is running. |\r\n| value.host.name | Name of the host where the VM is running. |\r\n| value.host.tags | List of tags of the host where the VM is running (i.e.: **[\"a\", \"b\"]**). |\r\n| value.id | UUID of the VM. |\r\n| value.name | Name of the VM. |\r\n| value.osName | Name of the OS of the VM. |\r\n| value.computeOffering.customized | A boolean informing if the compute offering is customized or not. |\r\n| value.computeOffering.id | UUID of the compute offering with which VM was created. |\r\n| value.computeOffering.name | Name of the compute offering with which VM was created. |\r\n| value.computingResources.cpuNumber | Current VM's vCPUs. |\r\n| value.computingResources.cpuSpeed | Current VM's CPU speed (in Mhz). |\r\n| value.computingResources.memory | Current VM's memory (in MiB). |\r\n| value.tags | List of tags of the VM in the format **key:value** (i.e.: **{\"a\":\"b\", \"c\":\"d\"}**). |\r\n| value.template.id | UUID of the template with which VM was created. |\r\n| value.template.name | Name of the template with which VM was created. |\r\n\r\n--- \r\n\r\n\u003ca name=\"proposed-changes--rules-processing-and-variables--allocated-vm\"/\u003e\r\n\r\n### ALLOCATED_VM\r\n\r\n| **Variable** | **Description** |\r\n| ------ | ------ |\r\n| value.id | UUID of the VM. |\r\n| value.name | Name of the VM. |\r\n| value.osName | Name of the OS of the VM. |\r\n| value.computeOffering.customized | A boolean informing if the compute offering is customized or not. |\r\n| value.computeOffering.id | UUID of the compute offering with which VM was created. |\r\n| value.computeOffering.name | Name of the compute offering with which VM was created. |\r\n| value.tags | List of tags of the VM in the format **key:value** (i.e.: **{\"a\":\"b\", \"c\":\"d\"}**). |\r\n| value.template.id | UUID of the template with which VM was created. |\r\n| value.template.name | Name of the template with which VM was created. |\r\n\r\n--- \r\n\r\n\u003ca name=\"proposed-changes--rules-processing-and-variables--volume\"/\u003e\r\n\r\n### VOLUME\r\n\r\n| **Variable** | **Description** |\r\n| ------ | ------ |\r\n| value.diskOffering.id | UUID of the disk offering with which volume was created. |\r\n| value.diskOffering.name | Name of the disk offering with which volume was created. |\r\n| value.id | UUID of the volume. |\r\n| value.name | Name of the volume. |\r\n| value.provisioningType | Provisioning type of the resource. Values can be: **thin**, **sparse** or **fat**. |\r\n| value.storage.id | UUID of the storage where the volume is. |\r\n| value.storage.name | Name of the storage where the volume is. |\r\n| value.storage.scope | Scope of the storage where the volume is. Values can be: **ZONE** or **CLUSTER**. |\r\n| value.storage.tags | List of tags of the storage where the volume is (i.e.: **[\"a\", \"b\"]**). |\r\n| value.tags | List of tags of the volume in the format **key:value** (i.e.: **{\"a\":\"b\", \"c\":\"d\"}**). |\r\n| value.size | Size of the volume (in MiB). |\r\n\r\n--- \r\n\r\n\u003ca name=\"proposed-changes--rules-processing-and-variables--template-iso\"/\u003e\r\n\r\n### TEMPLATE / ISO\r\n\r\n| **Variable** | **Description** |\r\n| ------ | ------ |\r\n| value.id | UUID of the template/ISO. |\r\n| value.name | Name of the template/ISO. |\r\n| value.osName | Name of the OS of the template/ISO. |\r\n| value.tags | List of tags of the template/ISO in the format **key:value** (i.e.: **{\"a\":\"b\", \"c\":\"d\"}**). |\r\n| value.size | Size of the template/ISO (in MiB). |\r\n\r\n--- \r\n\r\n\u003ca name=\"proposed-changes--rules-processing-and-variables--snapshot\"/\u003e\r\n\r\n### SNAPSHOT\r\n\r\n| **Variable** | **Description** |\r\n| ------ | ------ |\r\n| value.id | UUID of the snapshot. |\r\n| value.name | Name of the snapshot. |\r\n| value.size | Size of the snapshot (in MiB). |\r\n| value.snapshotType | Type of the snapshot. Values can be: **MANUAL**, **HOURLY**, **DAILY**, **WEEKLY** and **MONTHLY**. |\r\n| value.storage.id | UUID of the storage where the snapshot is. The data will be from the primary storage if the global setting **snapshot.backup.to.secondary** is **false**, otherwise it will be from secondary storage. |\r\n| value.storage.name | Name of the storage where the snapshot is. The data will be from the primary storage if the global setting **snapshot.backup.to.secondary** is **false**, otherwise it will be from secondary storage. |\r\n| value.storage.scope | If the global setting **snapshot.backup.to.secondary** is **false**, the scope of the primary storage where the snapshot is (values can be: **ZONE** or **CLUSTER**), otherwise it will not exist. |\r\n| value.storage.tags | List of tags of the storage where the snapshot is (i.e.: **[\"a\", \"b\"]**). The data will be from the primary storage if the global setting **snapshot.backup.to.secondary** is **false**, otherwise it will not exist. |\r\n| value.tags | List of tags of the snapshot in the format **key:value** (i.e.: **{\"a\":\"b\", \"c\":\"d\"}**). |\r\n\r\n--- \r\n\r\n\u003ca name=\"proposed-changes--rules-processing-and-variables--network-offering\"/\u003e\r\n\r\n### NETWORK_OFFERING\r\n\r\n| **Variable** | **Description** |\r\n| ------ | ------ |\r\n| value.id | UUID of the network offering. |\r\n| value.name | Name of the network offering. |\r\n| value.tag | Tag of the network offering. |\r\n\r\n--- \r\n\r\n\u003ca name=\"proposed-changes--rules-processing-and-variables--vm-snapshot\"/\u003e\r\n\r\n### VM_SNAPSHOT\r\n\r\n| **Variable** | **Description** |\r\n| ------ | ------ |\r\n| value.id | UUID of the VM snapshot. |\r\n| value.name | Name of the VM snapshot. |\r\n| value.tags | List of tags of the VM snapshot in the format **key:value** (i.e.: **{\"a\":\"b\", \"c\":\"d\"}**). |\r\n| value.vmSnapshotType | Type of the VM snapshot. Values can be: **Disk** or **DiskAndMemory**. |\r\n\r\n--- \r\n\r\n\u003ca name=\"proposed-changes--rules-processing-and-variables--other-resources\"/\u003e\r\n\r\n### Others resources\r\n\r\nOthers resources will have only the **Default** preset variables.\r\n\r\nOthers resources:\r\n\r\n```sh\r\nIP_ADDRESS\r\nNETWORK_BYTES_SENT\r\nNETWORK_BYTES_RECEIVED\r\nSECURITY_GROUP\r\nLOAD_BALANCER_POLICY\r\nPORT_FORWARDING_RULE\r\nVPN_USERS\r\n```\r\n\r\n--- \r\n\r\n\u003ca name=\"proposed-changes--script-samples\"/\u003e\r\n\r\n## Script samples\r\n\r\n1. Owner (account/domain/project) of the resource (available to **ALL** resources):\r\n\r\n ```js\r\n if (account.id == 'b29e84da-ed2e-47dc-9785-49231de8ff07') {\r\n true\r\n } else {\r\n false\r\n }\r\n ```\r\n\r\n Or just:\r\n\r\n ```js\r\n account.id == 'b29e84da-ed2e-47dc-9785-49231de8ff07'\r\n ```\r\n\r\n2. Volume of allocated resource for the owner (available to **ALL** resources):\r\n\r\n ```js\r\n value.accountResources.filter(resource =\u003e \r\n resource.domainId == 'b5ea6ffb-fa80-455e-8b38-c9b7e3900cfd'\r\n ).length \u003e 20\r\n ```\r\n\r\n3. Volume of allocated resource for the owner, resulting in the value of the tariff (available to **ALL** resources)[^3]:\r\n\r\n ```js\r\n resourcesLength = value.accountResources.filter(resource =\u003e \r\n resource.domainId == 'b5ea6ffb-fa80-455e-8b38-c9b7e3900cfd'\r\n ).length\r\n\r\n if (resourcesLength \u003e 40) {\r\n 20\r\n } else if (resourcesLength \u003e 10) {\r\n 25\r\n } else {\r\n 30\r\n }\r\n ```\r\n\r\n4. Name of the O.S (available to resources **RUNNING_VM** and **ALLOCATED_VM**):\r\n\r\n ```js\r\n ['Windows 10 (32-bit)',\r\n 'Windows 10 (64-bit)',\r\n 'Windows 2000 Advanced Server'].includes(value.osName)\r\n ```\r\n\r\n5. Storage tags (available to resources **VOLUME** and **SNAPSHOT**):\r\n\r\n ```js\r\n value.storage.tags.includes('SSD') \r\n \u0026\u0026 value.storage.tags.includes('NVME')\r\n ```\r\n\r\n6. Host tags (available to resource **RUNNING_VM**):\r\n\r\n ```js\r\n value.host.tags.includes('CPU platinum')\r\n ```\r\n\r\n7. Billing the public IP[^4]. Therefore, if we want to provide one public IP free of charge to users, we can avoid billing **source\r\n NAT** IPs (available to resource **IP_ADDRESS**):\r\n\r\n ```js\r\n resourceType !== 'SourceNat'\r\n ```\r\n\r\nA setting will be created to define the timeout of the scripts. The default value will be two (2) seconds.\r\n\r\n---\r\n\r\n\u003ca name=\"proposed-changes--billing-example\"/\u003e\r\n\r\n## Billing exampe\r\n\r\nThe **RUNNING_VM** tariff costs 10 and there are 2 VMs.\r\n\r\nThe VM **A** belongs to **af7bfdef-2c8f-44a7-9a0e-eb817d6cf821** and has the name **promo-123-PersonalCloud**.\r\n\r\nThe VM **B** belongs to **1e4100b8-e28b-4e76-814b-d0d77b27d7a7**, has the name **CompanyCloud** and the host tag **Best Performance**.\r\n\r\nWith the current workflow, both VMs would be accounted with the same tariff/price. With the proposal, operators will be able to create\r\ndifferent tariffs, like:\r\n\r\n1. Price: **-1.5**\r\n Rule:\r\n\r\n ```js\r\n value.name.includes('promo-123-')\r\n ```\r\n\r\n2. Price: **-1.0**\r\n Rule:\r\n\r\n ```js\r\n account.id == '1e4100b8-e28b-4e76-814b-d0d77b27d7a7'\r\n ```\r\n\r\n3. Price: **5.0**\r\n Rule:\r\n\r\n ```js\r\n value.host.tags.includes('Best Performance')\r\n ```\r\n\r\nAt the end, both VMs will have different costs:\r\n\r\n- VM **A**: 10 (**base**) - 1.5 (**rule 1**) = 8.5\r\n\r\n- VM **B**: 10 (**base**) - 1.0 (**rule 2**) + 5.0 (**rule 3**) = 14.0\r\n\r\n---\r\n\r\n\u003ca name=\"work-items\"/\u003e\r\n\r\nWork items\r\n---------------\r\n\r\n- Create six (6) new columns in table **cloud_usage.quota_tariff**:\r\n\r\n| **Column** | **Nullable** | **Updatable** | **Description** |\r\n| ------ | ------ | ------ | ------ |\r\n| uuid | No | No | To identify the tariff. |\r\n| name | No | No | A name, defined by the user, to the tariff. This column will be used as common identifier along the tariff updates. |\r\n| description | Yes | Yes | To describe the tariff. |\r\n| activation_rule | Yes | Yes | To define when the tariff should be activated. Use **null** if the tariff is always activated. |\r\n| removed | Yes | Yes | To mark tariff as removed. |\r\n| end_date | Yes | Yes | To define the end of the tariff. |\r\n\r\n- Migrate tariffs to new paradigm:\r\n - Tariffs before of the current will be marked as **removed** and will have the **end_date** equal to the **effective_on** of its next;\r\n - Tariffs after of the current will have its value as the difference between current tariff and its original value;\r\n - **vCPU**, **CPU_SPEED** and **MEMORY** tariffs will be converted to **RUNNING_VM** tariffs with respective activation rules;\r\n- Change **QuotaTariffVO**;\r\n- Change API **quotaTariffList**:\r\n - Create parameter **name**, **enddate** and **listall**.\r\n - Change API behavior to, if parameter **listAll** is not informed, only retrieve not removed tariffs;\r\n- Change API **quotaTariffUpdate**:\r\n - Mark previous tariff as **removed**, create a new one and copy the identifier (column **name**) to it.\r\n- Create API **quotaTariffCreate**:\r\n - This API will create a new tariff.\r\n- Create API **quotaTariffDelete**:\r\n - This API will mark the tariff as **removed**.\r\n- Create global setting to define the scripts' timeout.\r\n- Change API **quotaUpdate**:\r\n - Validate resources against tariffs' rules, sum the total price and calculate the usage.\r\n\r\n---\r\n\r\n\u003ca name=\"future-works\"/\u003e\r\n\r\nFuture works\r\n-----------------\r\n\r\nThis proposal regards to backend and database, therefore, front-end will not be addressed. In the future, we must change the UI to be compatible with the APIs.\r\n\r\nOther proposals arising from this spec are:\r\n\r\n- Bill the Network resource in Quota.\r\n- Bill the VPC resource in Quota.\r\n- Change APIs [quotaCredits](https://cloudstack.apache.org/api/apidocs-4.16/apis/quotaCredits.html) and [quotaBalance](https://cloudstack.apache.org/api/apidocs-4.16/apis/quotaBalance.html) to allow operators to inform the credits' date and the payment's date or the processing's date. It is necessary due to how some payment methods work.\r\n- Change resource Tags behavior to indicate when it is an administrative Tag (created by the operator) or an user Tag.\r\n- Create account/domain setting to granular enabling of Quota.\r\n- Add VM details on **RUNNING_VM**. This item will need a special attention as we retrieve the values while processing the rating, meaning that users are able to bypass the tariff by changing the attributes that activate/deactivate a tariff right before the rating is executed.\r\n- Change the account balance calculation in the APIs **quotaSummary** and [quotaBalance](https://cloudstack.apache.org/api/apidocs-4.16/apis/quotaBalance.html), as the current calculations is incorrect and does not represent the balance.\r\n- Improve API [quotaStatement](https://cloudstack.apache.org/api/apidocs-4.16/apis/quotaStatement.html) to, when using the parameter **type**, retrieve detailed data of the type instead of listing the other types with value 0.\r\n\r\n[^1]: As the V8 object will be instantiated only once per cycle, operators must avoid declaring variables with the keywords\r\n **const**, **var** or **let**, otherwise it will throw the error `Identifier has already been declared` between the iterations. Instead of using `const a = 1;`, one must use `a = 1;`.\r\n\r\n[^2]: It will automatically infer the type of the result: If the result is a number, like **1**, **2.5**, **-3.0** and so on, it will consider the result as a **number** and will use it as the value of the tariff. Otherwise, it will try to convert the result to a boolean (**true** or **false**). If the result is **true**, it will use the tariffs value in the calculation. If the result is **false** or not a valid boolean, it will not add the tariff value to the calculation.\r\n\r\n[^3]: If the **else** value (in this example, 30) is not provided, the script's result will be `undefined` and the the tariff won't be applied.\r\n\r\n[^4]: Public IPs are bound to VPCs or isolated networks (not user VMs directly). Every first IP of a VPC or isolated network is a **source NAT**; additional, if added/allocated by the user, IPs have a null **resourceType**.\r\n","author":{"url":"https://github.com/GutoVeronezi","@type":"Person","name":"GutoVeronezi"},"datePublished":"2022-01-24T15:46:19.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/5891/cloudstack/issues/5891"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8c35080e-25d0-893c-7749-75c613da45c0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C486:28E279:97CF80B:9AC1F3B:6A506794 |
| html-safe-nonce | 51e4e462aa397dd3308cad92940ae8b3d9ad89368da7b811ca75bb879c592104 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDg2OjI4RTI3OTo5N0NGODBCOjlBQzFGM0I6NkE1MDY3OTQiLCJ2aXNpdG9yX2lkIjoiNTQ1MzU3NTA5ODU3MjIzNjY5MiIsInJlZ2lvbl9lZGdlIjoic2VhIiwicmVnaW9uX3JlbmRlciI6InNlYSJ9 |
| visitor-hmac | 9e35c3545d567ec8ea86fa9b286d43747c750b875ea00011e3d10ae61bdec9e1 |
| hovercard-subject-tag | issue:1112816213 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/apache/cloudstack/5891/issue_layout |
| twitter:image | https://opengraph.githubassets.com/36c0936b0e01d5d9049df7705b5a639eec34ce430fd666fb5145ab30ccb20ca6/apache/cloudstack/issues/5891 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/36c0936b0e01d5d9049df7705b5a639eec34ce430fd666fb5145ab30ccb20ca6/apache/cloudstack/issues/5891 |
| og:image:alt | ISSUE TYPE Enhancement Request COMPONENT NAME Quota, billing CLOUDSTACK VERSION 4.16/main SUMMARY This spec changes the Cloudstack's Quota Plugin to allow operators to customize tariffs based on ch... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | GutoVeronezi |
| hostname | github.com |
| expected-hostname | github.com |
| None | d6dc8294eb500fa36bbc57472d61fe87c522f9c3c1d64f70f4926f66a66a7efb |
| turbo-cache-control | no-preview |
| go-import | github.com/apache/cloudstack git https://github.com/apache/cloudstack.git |
| octolytics-dimension-user_id | 47359 |
| octolytics-dimension-user_login | apache |
| octolytics-dimension-repository_id | 9759448 |
| octolytics-dimension-repository_nwo | apache/cloudstack |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 9759448 |
| octolytics-dimension-repository_network_root_nwo | apache/cloudstack |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7ac0ad2f2c7e4b9056617355fd9e33e22b0c8df9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width