CFME Reports: scheme and extensions

14:20 0 Comments

About scheme of Reports


It's necessary to say in this topic about model MiqExpression, which is stored information about tables, which are used for Reports. This model have four enumerators related with Reports:

1. Enumerator @@base_tables(not fully):
---
@@base_tables = %w{
    Network
    AuditEvent
    AvailabilityZone
    BottleneckEvent
    Chargeback
    CloudResourceQuota
    CloudTenant
    Compliance
    ConfiguredSystemForeman
    ConfigurationManager
    EmsCloud
    EmsCluster
    EmsClusterPerformance
    EmsEvent
    EmsInfra
    ExtManagementSystem
    Flavor
    Host
    Vm
    ...

This enumerator includes names of models, on which reports are built. We can see at snapshot:

2. Enumerator @@include_tables (not fully too):
---
@@include_tables = %w{
    advanced_settings
    audit_events
    availability_zones
    cloud_networks
    cloud_resource_quotas
    cloud_tenants
    compliances
    compliance_details
    configuration_profiles
    configuration_managers
    configured_systems
    customization_scripts
    customization_script_media
    customization_script_ptables
    disks
    networks
    hardware
    ...

This enumerator includes tables, which are not base for reports, but we can see and use these tables, because they are part of @@base_tables. For example, table networks belongs to table hardware, and this table belongs to table of model Vm. So, networks and hardware are included in @@include_tables, and we can see them in available tables for reports. See on snapshot:

 3. Enumerator EXCLUDE_COLUMNS (not fully too):
---
EXCLUDE_COLUMNS = %w{
    ^.*_id$
    ^id$
    ^min_derived_storage.*$
    ^max_derived_storage.*$
    assoc_ids
    capture_interval
    filters
    icon

    intervals_in_rollup

    max_cpu_ready_delta_summation
    max_cpu_system_delta_summation
    max_cpu_used_delta_summation
    max_cpu_wait_delta_summation
    max_derived_cpu_available
    max_derived_cpu_reserved
    max_derived_memory_available
    max_derived_memory_reserved

    memory_usage
    ...

This enumerator includes fields, which should not be displayed in reports. For example, we can't see field password in report, which is based on model EVM User,but  password stores in table of this model.

4. Enumerator EXCLUDE_EXCEPTIONS:
---
EXCLUDE_EXCEPTIONS = %w{
    capacity_profile_1_memory_per_vm_with_min_max
    capacity_profile_1_vcpu_per_vm_with_min_max
    capacity_profile_2_memory_per_vm_with_min_max
    capacity_profile_2_vcpu_per_vm_with_min_max
    chain_id
    guid
  }
 
This enumerator includes fields, which should not be displayed in reports too.

Our extension for Reports


Now, we know scheme of Reports and we can add custom extension.For example:
Our task: We can click on VM in report, which includes VM Name and IP adress, and we can go to this VM. Finally, IP adress should be displayed in base model for reports Perfomance - VMs.
Our actions:

---
class VmPerformance < MetricRollup
  default_scope { where "resource_type = 'VmOrTemplate' and resource_id IS NOT NULL" }

  belongs_to :host,        :foreign_key => :parent_host_id
  belongs_to :ems_cluster, :foreign_key => :parent_ems_cluster_id
  belongs_to :storage,     :foreign_key => :parent_storage_id
  belongs_to :vm,          :foreign_key => :resource_id, :class_name => 'VmOrTemplate'

  virtual_column :ipaddresses,    :type => :string_set

  def ipaddresses
    return self.vm.hardware.ipaddresses
  end

end
- new virtual column ipaddresses with type string_set;
 - definition of ipaddresses (we use vm - model VmPerformance belongs to model of this table).

 Results:

Unknown

IBA Group, Minsk

0 comments: