Skip to content

UI: allow memory setting in flex compute offering in GiB with unit selector (#14082) - #14413

Open
saurabhkushwaha438 wants to merge 1 commit into
apache:mainfrom
saurabhkushwaha438:issue-14082-flex-memory-gib
Open

saurabhkushwaha438 wants to merge 1 commit into
apache:mainfrom
saurabhkushwaha438:issue-14082-flex-memory-gib

Conversation

@saurabhkushwaha438

Copy link
Copy Markdown
Contributor

Description

Fixes #14082

1. Conversion from MiB to GiB (Display & Rounding)

  • Binary conversion is used (1 GiB = 1024 MiB).
  • When offerings with predefined constraints or initial values are loaded in MiB, or when switching from MiB to GiB:
    $$\text{displayValue} = \text{parseFloat}\left(\left(\frac{\text{rawMemory}}{1024}\right)\text{.toFixed(2)}\right)$$
  • The display value is rounded to 2 decimal places to keep the UI clean, readable, and intuitive for users.
  • Slider step dynamically adjusts:
    • In GiB mode: step is set to 0.01 (or smaller for sub-GiB offerings) with precision 2.
    • In MiB mode: step is set to 1 with integer precision 0.

2. Conversion from GiB to MiB (Backend Value Emission)

  • CloudStack APIs and backend services expect memory allocations in integer MiB.
  • When the user selects or inputs memory in GiB:
    $$\text{memoryInMiB} = \text{Math.round}(\text{displayValue} \times 1024)$$
  • Exact Boundary Protection: If a compute offering has minimum/maximum memory constraints (minMemory / maxMemory), selecting the exact minimum or maximum bound in GiB directly maps to the exact integer minMemory or maxMemory in MiB to eliminate any potential off-by-one rounding discrepancies.

💬 Feedback Needed: Fractional GiB to Integer MiB Rounding

  • Observation: Converting decimal GiB values to MiB often produces fractional values (e.g., 1.51 GiB × 1024 = 1546.24 MiB).
  • Current Behavior: The UI rounds this to the nearest integer (1546 MiB), which is then emitted in the API payload and consumed by backend hypervisor managers.
  • Reviewer Input: Looking for maintainer feedback on whether standard nearest-integer rounding (Math.round) is acceptable, or if we should apply ceiling (Math.ceil) to guarantee the VM always receives at least the requested GiB amount.
bandicam.2026-10-16.10-21-12-210.mp4

this.updateComputeCpuNumber(this.preFillContent.cpunumber || this.cpuNumberInputValue)
this.updateComputeCpuSpeed(this.preFillContent.cpuspeed || this.cpuSpeedInputValue)
this.updateComputeMemory(this.preFillContent.memory || this.memoryInputValue)
this.updateComputeMemory(this.memoryDisplayValue)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens when the memory isnt a round GiB value? an imported vm with 1500 MB shows as 1.46 GiB and gets sent back as 1495 without the user touching it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch , now i am confuse and would be great to get suggestion from you and others

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np. maybe, we can open it in MiB when the value isnt a whole number of GiB? then 1500 stays 1500. on load and on a unit switch, send the saved MiB value as is and only convert when the user changes the number.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another option could be use GIB for display only because MIB is only state and single source of truth so in backend we will use actual MIB value

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that only works if the saved MiB is what gets sent.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make sure 1500 goes back as 1500 unless the user changes the number?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI: Please change memory setting in flex compute offering from MiB to GiB

2 participants