-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from slemrmartin/inventory-collection-builder
Persister: InventoryCollection building through add_collection()
- Loading branch information
Showing
12 changed files
with
389 additions
and
749 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 25 additions & 22 deletions
47
app/models/manageiq/providers/openstack/inventory/persister/cinder_manager.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
class ManageIQ::Providers::Openstack::Inventory::Persister::CinderManager < ManageIQ::Providers::Openstack::Inventory::Persister | ||
include ManageIQ::Providers::Openstack::Inventory::Persister::Definitions::CloudCollections | ||
include ManageIQ::Providers::Openstack::Inventory::Persister::Definitions::NetworkCollections | ||
include ManageIQ::Providers::Openstack::Inventory::Persister::Definitions::StorageCollections | ||
|
||
def initialize_inventory_collections | ||
add_inventory_collections(storage, | ||
%i( | ||
cloud_volumes | ||
cloud_volume_snapshots | ||
cloud_volume_backups | ||
), | ||
:builder_params => {:ext_management_system => manager}) | ||
initialize_storage_inventory_collections | ||
|
||
initialize_cloud_inventory_collections | ||
end | ||
|
||
def initialize_cloud_inventory_collections | ||
%i(vms | ||
availability_zones | ||
hardwares | ||
cloud_tenants | ||
disks).each do |name| | ||
|
||
add_collection(cloud, name, shared_cloud_properties) do |builder| | ||
builder.add_properties(:strategy => :local_db_cache_all) unless name == :disks | ||
builder.add_properties(:complete => false) if name == :disks | ||
end | ||
end | ||
end | ||
|
||
add_inventory_collections(cloud, | ||
%i( | ||
vms | ||
availability_zones | ||
hardwares | ||
cloud_tenants | ||
), | ||
:parent => manager.parent_manager, | ||
:strategy => :local_db_cache_all) | ||
private | ||
|
||
add_inventory_collections(cloud, | ||
%i( | ||
disks | ||
), | ||
:parent => manager.parent_manager, | ||
:complete => false) | ||
def shared_cloud_properties | ||
{ :parent => manager.parent_manager } | ||
end | ||
end |
57 changes: 3 additions & 54 deletions
57
app/models/manageiq/providers/openstack/inventory/persister/cloud_manager.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,7 @@ | ||
class ManageIQ::Providers::Openstack::Inventory::Persister::CloudManager < ManageIQ::Providers::Openstack::Inventory::Persister | ||
def initialize_inventory_collections | ||
add_inventory_collections( | ||
cloud, | ||
%i( | ||
availability_zones | ||
cloud_resource_quotas | ||
cloud_services | ||
cloud_tenants | ||
flavors | ||
host_aggregates | ||
miq_templates | ||
orchestration_stacks | ||
vms | ||
), | ||
:builder_params => {:ext_management_system => manager} | ||
) | ||
|
||
add_inventory_collections( | ||
cloud, | ||
%i( | ||
key_pairs | ||
), | ||
:builder_params => {:resource => manager} | ||
) | ||
|
||
add_inventory_collections( | ||
cloud, | ||
%i( | ||
hardwares | ||
operating_systems | ||
disks | ||
networks | ||
orchestration_templates | ||
orchestration_stacks_resources | ||
orchestration_stacks_outputs | ||
orchestration_stacks_parameters | ||
) | ||
) | ||
include ManageIQ::Providers::Openstack::Inventory::Persister::Definitions::CloudCollections | ||
|
||
add_inventory_collection( | ||
cloud.vm_and_miq_template_ancestry( | ||
:dependency_attributes => { | ||
:vms => [collections[:vms]], | ||
:miq_templates => [collections[:miq_templates]] | ||
} | ||
) | ||
) | ||
|
||
add_inventory_collection( | ||
cloud.orchestration_stack_ancestry( | ||
:dependency_attributes => { | ||
:orchestration_stacks => [collections[:orchestration_stacks]], | ||
} | ||
) | ||
) | ||
def initialize_inventory_collections | ||
initialize_cloud_inventory_collections | ||
end | ||
end |
166 changes: 166 additions & 0 deletions
166
app/models/manageiq/providers/openstack/inventory/persister/definitions/cloud_collections.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
module ManageIQ::Providers::Openstack::Inventory::Persister::Definitions::CloudCollections | ||
extend ActiveSupport::Concern | ||
|
||
include ManageIQ::Providers::Openstack::Inventory::Persister::Definitions::Utils | ||
|
||
# used also in ovirt, so automatic model_classes are not possible in many cases | ||
def initialize_cloud_inventory_collections | ||
add_vms | ||
|
||
add_miq_templates | ||
|
||
add_availability_zones | ||
|
||
add_cloud_tenants | ||
|
||
add_flavors | ||
|
||
add_key_pairs | ||
|
||
unless targeted? | ||
add_cloud_resource_quotas | ||
|
||
add_cloud_services | ||
|
||
add_host_aggregates | ||
end | ||
|
||
add_orchestration_stacks_with_ems_param | ||
|
||
%i(hardwares | ||
operating_systems | ||
disks | ||
networks | ||
orchestration_stacks_resources | ||
orchestration_stacks_outputs | ||
orchestration_stacks_parameters).each do |name| | ||
|
||
add_collection(cloud, name) | ||
end | ||
|
||
add_orchestration_templates | ||
|
||
add_vm_and_miq_template_ancestry | ||
|
||
add_orchestration_stack_ancestry | ||
end | ||
|
||
# ------ IC provider specific definitions ------------------------- | ||
|
||
# model_class defined due to ovirt dependency | ||
def add_vms | ||
add_collection_with_ems_param(cloud, :vms) do |builder| | ||
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::CloudManager::Vm) | ||
end | ||
end | ||
|
||
def add_miq_templates | ||
add_collection(cloud, :miq_templates) do |builder| | ||
builder.add_properties(:model_class => ::MiqTemplate) | ||
|
||
builder.add_builder_params(:ext_management_system => manager) | ||
|
||
# Extra added to automatic attributes | ||
builder.add_inventory_attributes(%i(cloud_tenant cloud_tenants)) | ||
end | ||
end | ||
|
||
# model_class defined due to ovirt dependency | ||
def add_availability_zones | ||
add_collection_with_ems_param(cloud, :availability_zones) do |builder| | ||
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::CloudManager::AvailabilityZone) | ||
end | ||
end | ||
|
||
# model_class defined due to ovirt dependency | ||
def add_cloud_tenants | ||
add_collection_with_ems_param(cloud, :cloud_tenants) do |builder| | ||
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::CloudManager::CloudTenant) | ||
end | ||
end | ||
|
||
# model_class defined due to ovirt dependency | ||
def add_flavors | ||
add_collection_with_ems_param(cloud, :flavors) do |builder| | ||
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::CloudManager::Flavor) | ||
end | ||
end | ||
|
||
# model_class defined due to ovirt dependency | ||
def add_cloud_resource_quotas | ||
add_collection_with_ems_param(cloud, :cloud_resource_quotas) do |builder| | ||
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::CloudManager::CloudResourceQuota) | ||
end | ||
end | ||
|
||
def add_cloud_services | ||
add_collection_with_ems_param(cloud, :cloud_services) | ||
end | ||
|
||
# model_class defined due to ovirt dependency | ||
def add_host_aggregates | ||
add_collection_with_ems_param(cloud, :host_aggregates) do |builder| | ||
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::CloudManager::HostAggregate) | ||
end | ||
end | ||
|
||
def add_orchestration_stacks(extra_properties = {}) | ||
add_collection(cloud, :orchestration_stacks, extra_properties) do |builder| | ||
builder.add_properties(:model_class => ManageIQ::Providers::CloudManager::OrchestrationStack) | ||
|
||
yield builder if block_given? | ||
end | ||
end | ||
|
||
def add_orchestration_templates | ||
add_collection(cloud, :orchestration_templates) do |builder| | ||
builder.add_properties(:model_class => ::OrchestrationTemplate) | ||
end | ||
end | ||
|
||
# TODO: mslemr - parent model class used anywhere? | ||
def add_key_pairs(extra_properties = {}) | ||
add_collection(cloud, :key_pairs, extra_properties) do |builder| | ||
builder.add_properties( | ||
:model_class => ManageIQ::Providers::Openstack::CloudManager::AuthKeyPair, | ||
) | ||
|
||
builder.add_builder_params(:resource => manager) unless targeted? | ||
end | ||
end | ||
|
||
# TODO: mslemr - same as amazon! | ||
def add_vm_and_miq_template_ancestry | ||
add_collection(cloud, :vm_and_miq_template_ancestry, {}, {:auto_inventory_attributes => false, :auto_model_class => false, :without_model_class => true}) do |builder| | ||
builder.add_dependency_attributes( | ||
:vms => [collections[:vms]], | ||
:miq_templates => [collections[:miq_templates]] | ||
) | ||
end | ||
end | ||
|
||
# TODO: mslemr - almost same as amazon! | ||
# Needed remove_dependency_attributes for core basic definition | ||
def add_orchestration_stack_ancestry | ||
add_collection(cloud, :orchestration_stack_ancestry, {}, {:auto_inventory_attributes => false, :auto_model_class => false, :without_model_class => true}) do |builder| | ||
builder.add_dependency_attributes( | ||
:orchestration_stacks => [collections[:orchestration_stacks]] | ||
) | ||
|
||
if targeted? | ||
builder.add_dependency_attributes( | ||
:orchestration_stacks_resources => [collections[:orchestration_stacks_resources]] | ||
) | ||
end | ||
end | ||
end | ||
|
||
protected | ||
|
||
# Shortcut for better code readability | ||
def add_orchestration_stacks_with_ems_param | ||
add_orchestration_stacks do |builder| | ||
builder.add_builder_params(:ext_management_system => manager) | ||
end | ||
end | ||
end |
Oops, something went wrong.