winterhazel opened a new pull request, #8138:
URL: https://github.com/apache/cloudstack/pull/8138
### Description
This PR adds two new preset variables into the Quota activation rules:
hypervisor type and volume format. This allows operators to customize tariffs
based on these two properties.
The respective preset variable will be injected into tariffs with the
following usage types:
- RUNNING_VM: `value.hypervisorType`;
- ALLOCATED_VM: `value.hypervisorType`;
- VM_SNAPSHOT: `value.hypervisorType`;
- SNAPSHOT: `value.hypervisorType`;
- VOLUME: `value.volumeFormat`;
- VOLUME_SECONDARY: `value.volumeFormat`.
Example of an activation rule using `value.hypervisorType`:
```js
if (value.hypervisorType=='KVM') {
1
} else {
2
}
```
Example of an activation rule using `value.volumeFormat`:
```js
if (value.volumeFormat=='QCOW2') {
3
} else {
4
}
```
Furthermore, this PR also fixes the preset variable `resourceType` being
injected into the JavaScript interpreter without quotes, which prevented the
activation rules from executing.
```
2023-10-05 16:43:08,886 ERROR [o.a.c.q.QuotaManagerImpl]
(qtp1955920234-22:ctx-d90594cb ctx-6d904941) (logid:5f086162) Failed to
calculate the quota usage for account
[{"accountName":"fabricio","domainId":1,"id":21,"uuid":"ae254524-854a-4049-9d1b-721cfaffdd71"}]
due to [Unable to execute script [ account =
{"role":{"type":"User","id":"64b4ca77-26de-11ec-8dcf-5254005dcdac","name":"User"},"id":"ae254524-854a-4049-9d1b-721cfaffdd71","name":"fabricio"};
domain =
{"path":"\/","id":"52d83793-26de-11ec-8dcf-5254005dcdac","name":"ROOT"};
resourceType = KVM; value =
{"accountResources":[{"domainId":"52d83793-26de-11ec-8dcf-5254005dcdac","zoneId":"8b2ceb16-a2f2-40ea-8968-9e08984bdb17"},{"domainId":"52d83793-26de-11ec-8dcf-5254005dcdac","zoneId":"8b2ceb16-a2f2-40ea-8968-9e08984bdb17"},{"domainId":"52d83793-26de-11ec-8dcf-5254005dcdac","zoneId":"8b2ceb16-a2f2-40ea-8968-9e08984bdb17"}],"computeOffering":{"customized":false,"id":"ab647165-7a0a-4984-8452-7bfceb036528","name":"Small
Instance"},"c
omputingResources":{"cpuNumber":1,"cpuSpeed":500,"memory":512},"host":{"tags":[],"id":"3d7d8532-d0cf-476c-a36e-1b936d780abb","name":"cloudstack-lab-host-2"},"hypervisorType":"KVM","osName":"Ubuntu
18.04
LTS","tags":{},"template":{"id":"bb4b7b6f-5249-4c18-a5f6-dd886683b702","name":"Ubuntu
Bionic"},"id":"a83ece0c-58e7-4bc5-8564-f70fe8e34fc0","name":"t2"}; zone =
{"id":"8b2ceb16-a2f2-40ea-8968-9e08984bdb17","name":"sc-floripa-01"}; if
(value.hypervisorType=='KVM') { 1 } else { 2 }] due to
[javax.script.ScriptException: ReferenceError: "KVM" is not defined in <eval>
at line number 1]].
```
### Types of changes
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [X] Enhancement (improves an existing feature and functionality)
- [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
### Feature/Enhancement Scale or Bug Severity
#### Feature/Enhancement Scale
- [ ] Major
- [X] Minor
#### Bug Severity
- [ ] BLOCKER
- [ ] Critical
- [ ] Major
- [X] Minor
- [ ] Trivial
### Screenshots (if appropriate):
### How Has This Been Tested?
I created two tariffs through CloudMonkey:
```
(admin) 🐱 > quota tariffcreate activationrule="if
(value.hypervisorType=='KVM') { 1 } else { 2 }" usagetype=1 value=0
name="hypervisor" description="hypervisor"
{
"quotatariff": {
"activationRule": "if (value.hypervisorType=='KVM') { 1 } else { 2 }",
"currency": "$",
"description": "hypervisor",
"effectiveDate": "2023-10-04T21:46:19+0000",
"name": "hypervisor",
"tariffValue": 0,
"usageDiscriminator": "None",
"usageName": "RUNNING_VM",
"usageType": 1,
"usageTypeDescription": "Running Vm Usage",
"usageUnit": "Compute*Month",
"uuid": "85941d4b-cc6e-4e18-ba85-7708ea3a41eb"
}
}
(admin) 🐱 > quota tariffcreate activationrule="if
(value.volumeFormat=='QCOW2') { 3 } else { 4 }" usagetype=6 value=0
name="volume format" description="volume format"
{
"quotatariff": {
"activationRule": "if (value.volumeFormat=='QCOW2') { 3 } else { 4 }",
"currency": "$",
"description": "volume format",
"effectiveDate": "2023-10-04T21:48:42+0000",
"name": "volume format",
"tariffValue": 0,
"usageDiscriminator": "None",
"usageName": "VOLUME",
"usageType": 6,
"usageTypeDescription": "Volume Usage",
"usageUnit": "GB*Month",
"uuid": "7b6c9eae-b369-40b7-adc3-0add4abf27bd"
}
}
```
Then, I deployed a virtual machine using KVM, called `quotaUpdate` and
verified through the logs that that the calculated value was 1 for the first
tariff and 3 for the second.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]