Scott Seago wrote: Replying to my reply here as I forgot to delete a couple bits in the response:
- def create
- #TODO Should be in Transaction
- @parent = get_parent_object(params)
- @parent_type = params[:parent_type]
- if !Quota.exists?(@parent.quota_id)
require_privilege(Privilege::QUOTA_MODIFY, @parent)
@quota = Quota.new(params[:quota])
# Populate Current Pool totals to Quota
So if I'm understanding correctly, the updated model stores the defined quota as well as caching the current usage towards the quota in the same row. Although not part of this patch, we've got to resolve how we're going to keep this in sync, as it needs update every time an instance changes state.
Ignore this comment, as this is handled in the InstanceObserver
@parent.instances.each do |instance|
hwp = HardwareProfile.find(instance.hardware_profile_id)
if instance.state == Instance::STATE_RUNNING
@quota.running_instances += 1
@quota.running_memory += hwp.memory
#TODO Add CPUs
end
if InstanceObserver::ACTIVE_STATES.include?(instance.state)
Wherever we are aggregating current resource usage (which I don't think will be this form), ACTIVE_STATES should apply towards the running_* quota parameters, and _all_ instances, regardless of state should apply to the total_* parameters
Also ignore this, as I misunderstood what states you were calling ACTIVE_STATES. I think this is fine as-is
Scott