Skip to content

Commit

Permalink
Merge pull request #158 from rwsu/quota-calculation
Browse files Browse the repository at this point in the history
Fix missing quota calculations
(cherry picked from commit 531b627)

https://bugzilla.redhat.com/show_bug.cgi?id=1515486
  • Loading branch information
mansam authored and simaishi committed Nov 20, 2017
1 parent 476a0dd commit 67aa553
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Expand Up @@ -75,4 +75,46 @@ def network_quota_used
def subnet_quota_used
CloudSubnet.joins(:cloud_network).where("cloud_networks.cloud_tenant_id" => cloud_tenant_id).count
end

def port_quota_used
NetworkPort.where(:cloud_tenant_id => cloud_tenant_id).count
end

def volumes_quota_used
CloudVolume.where(:cloud_tenant_id => cloud_tenant_id).count
end

def gigabytes_quota_used
CloudVolume.where(:cloud_tenant_id => cloud_tenant_id)
.sum(:size) / 1_073_741_824
end

def backups_quota_used
CloudVolumeBackup.joins(:cloud_volume)
.where("cloud_volumes.cloud_tenant_id" => cloud_tenant_id).count
end

def backup_gigabytes_quota_used
CloudVolumeBackup.joins(:cloud_volume)
.where("cloud_volumes.cloud_tenant_id" => cloud_tenant_id)
.sum(:size) / 1_073_741_824
end

def snapshots_quota_used
CloudVolumeSnapshot.where(:cloud_tenant_id => cloud_tenant_id).count
end

def ems
CloudTenant.find(cloud_tenant_id).ext_management_system
end

def key_pairs_quota_used
Authentication.where(:resource_id => ems.id,
:resource_type => 'ExtManagementSystem',
:type => ManageIQ::Providers::Openstack::CloudManager::AuthKeyPair.name).count
end

def router_quota_used
NetworkRouter.where(:cloud_tenant_id => cloud_tenant_id).count
end
end
Expand Up @@ -245,7 +245,11 @@ def flatten_quota(quota)
# The array of hashes returned from this block is the same as what would
# be produced by parse_quota ... so, parse_quota just returns the same
# hash with a compound key.
quota.except("id", "tenant_id", "service_name").collect do |key, value|
# Metadata items, injected files, server groups, and rbac policies are not modeled.
# Skip them for now.
quota.except("id", "tenant_id", "service_name", "metadata_items", "injected_file_content_bytes",
"injected_files", "injected_file_path_bytes", "server_groups", "server_group_members",
"rbac_policy").collect do |key, value|
begin
value = value.to_i
rescue
Expand Down

0 comments on commit 67aa553

Please sign in to comment.