Skip to content

Instantly share code, notes, and snippets.

@hemna
Last active February 24, 2022 15:06
Show Gist options
  • Save hemna/7300859555e18a0be4a6c8a99eb167a1 to your computer and use it in GitHub Desktop.
Save hemna/7300859555e18a0be4a6c8a99eb167a1 to your computer and use it in GitHub Desktop.
def calculate_virtual_free_capacity(total_capacity,
free_capacity,
provisioned_capacity,
thin_provisioning_support,
max_over_subscription_ratio,
reserved_percentage,
thin):
"""Calculate the virtual free capacity based on thin provisioning support.
:param total_capacity: total_capacity_gb of a host_state or pool.
:param free_capacity: free_capacity_gb of a host_state or pool.
:param provisioned_capacity: provisioned_capacity_gb of a host_state
or pool.
:param thin_provisioning_support: thin_provisioning_support of
a host_state or a pool.
:param max_over_subscription_ratio: max_over_subscription_ratio of
a host_state or a pool
:param reserved_percentage: reserved_percentage of a host_state or
a pool.
:param thin: whether volume to be provisioned is thin
:returns: the calculated virtual free capacity.
"""
total = float(total_capacity)
reserved = float(reserved_percentage) / 100
total_avail = total - math.floor(total * reserved)
if thin and thin_provisioning_support:
# OLD WAY
#free = (total * max_over_subscription_ratio
# - provisioned_capacity
# - math.floor(total * reserved))
# NEW way using defined terms in original cinder doc
free = (total_avail * max_over_subscription_ratio
- provisioned_capacity)
else:
# Calculate how much free space is left after taking into
# account the reserved space.
free = free_capacity - math.floor(total * reserved)
return free
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment