Custom CFME reports: use VIEW
Hello everybody! Today we will create custom CFME reports using database view. It is interesting and not difficult thing.
Why
It's necessary to know all statistics about our enterprise. And now we have new stuff -
Tenant. All in all, we use it to separate enterprise into departments. But standard reports can't give us possibilities to create statistics about every part of enterprise. So, our example - report about CPU, Memory and size on disks, which are belong to Tenant. How
1. Create read-only model
InfoTenant:---
class InfoTenant < ActiveRecord::Base
# Prevent creation of new records and modification to existing records
def readonly?
return true
end
# Prevent objects from being destroyed
def before_destroy
raise ActiveRecord::ReadOnlyRecord
end
end
2. Create rails migration
AddInfoTenants:--- rails g migration AddInfoTenants
3. Change migration:
---
class AddInfoTenants < ActiveRecord::Migration
def up
execute '
CREATE VIEW info_tenants AS
SELECT i.name AS name, SUM(t.cpu_total_cores) AS CPU, SUM((t.memory_mb/1024)) AS Memory_in_GB,
SUM((q.size/1048576)) AS Size_on_dusk_GB
FROM tenants AS i
LEFT JOIN vms AS c ON i.id = c.tenant_id
LEFT JOIN hardwares AS t ON c.id = t.vm_or_template_id
LEFT JOIN disks AS q ON t.id = q.hardware_id
GROUP BY i.name
'
end
def down
execute 'DROP VIEW info_tenants '
end
end
4. Add new model into enumerator
Result:
@@base_tables of MiqExpression---
@@base_tables = %w{
Network
AuditEvent
AvailabilityZone
BottleneckEvent
Chargeback
CloudResourceQuota
CloudTenant
Compliance
ConfiguredSystemForeman
ConfigurationManager
EmsCloud
EmsCluster
EmsClusterPerformance
EmsEvent
EmsInfra
ExtManagementSystem
Flavor
Host
Vm
...
InfoTenant
Result:
Good! Actually, you can use other tables of database and other combinations.
Sources:
https://habrahabr.ru/post/138949/
about CFME reports-1
Sources:
https://habrahabr.ru/post/138949/
about CFME reports-1
.png)

0 comments: