forked from ManageIQ/manageiq-providers-amazon
-
Notifications
You must be signed in to change notification settings - Fork 0
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 ManageIQ#438 from slemrmartin/inventory-collection…
…-builder Persister: InventoryCollection building through add_collection()
- Loading branch information
Showing
12 changed files
with
345 additions
and
835 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
28 changes: 3 additions & 25 deletions
28
app/models/manageiq/providers/amazon/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,31 +1,9 @@ | ||
class ManageIQ::Providers::Amazon::Inventory::Persister::CloudManager < ManageIQ::Providers::Amazon::Inventory::Persister | ||
include ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::CloudCollections | ||
|
||
def initialize_inventory_collections | ||
initialize_tag_mapper | ||
|
||
add_inventory_collections( | ||
cloud, | ||
%i(vms miq_templates hardwares operating_systems networks disks availability_zones | ||
vm_and_template_labels vm_and_template_taggings | ||
flavors key_pairs orchestration_stacks orchestration_stacks_resources | ||
orchestration_stacks_outputs orchestration_stacks_parameters orchestration_templates) | ||
) | ||
|
||
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]], | ||
:orchestration_stacks_resources => [collections[:orchestration_stacks_resources]] | ||
} | ||
) | ||
) | ||
initialize_cloud_inventory_collections | ||
end | ||
end |
122 changes: 122 additions & 0 deletions
122
app/models/manageiq/providers/amazon/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,122 @@ | ||
module ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::CloudCollections | ||
extend ActiveSupport::Concern | ||
|
||
def initialize_cloud_inventory_collections | ||
%i(vms | ||
hardwares | ||
operating_systems | ||
networks | ||
disks | ||
availability_zones).each do |name| | ||
|
||
add_collection(cloud, name) | ||
end | ||
|
||
add_miq_templates | ||
|
||
add_flavors | ||
|
||
add_key_pairs | ||
|
||
add_vm_and_template_labels | ||
|
||
add_vm_and_template_taggings | ||
|
||
add_orchestration_stacks | ||
|
||
%i(orchestration_stacks_resources | ||
orchestration_stacks_outputs | ||
orchestration_stacks_parameters | ||
orchestration_templates).each do |name| | ||
|
||
add_collection(cloud, name) | ||
end | ||
|
||
# Custom processing of Ancestry | ||
add_vm_and_miq_template_ancestry | ||
|
||
add_orchestration_stack_ancestry | ||
end | ||
|
||
# ------ IC provider specific definitions ------------------------- | ||
|
||
# TODO: Derive model class in core | ||
def add_miq_templates(extra_properties = {}) | ||
add_collection(cloud, :miq_templates, extra_properties) do |builder| | ||
builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::Template) | ||
builder.add_builder_params(:template => true) | ||
end | ||
end | ||
|
||
def add_flavors(extra_properties = {}) | ||
add_collection(cloud, :flavors, extra_properties) do |builder| | ||
# Model we take just from a DB, there is no flavors API | ||
builder.add_properties(:strategy => :local_db_find_references) if targeted? | ||
end | ||
end | ||
|
||
def add_vm_and_template_labels | ||
add_collection(cloud, :vm_and_template_labels) do |builder| | ||
builder.add_targeted_arel( | ||
lambda do |inventory_collection| | ||
manager_uuids = inventory_collection.parent_inventory_collections.collect(&:manager_uuids).map(&:to_a).flatten | ||
inventory_collection.parent.vm_and_template_labels.where( | ||
'vms' => {:ems_ref => manager_uuids} | ||
) | ||
end | ||
) | ||
end | ||
end | ||
|
||
def add_vm_and_template_taggings | ||
add_collection(cloud, :vm_and_template_taggings) do |builder| | ||
builder.add_properties( | ||
:model_class => Tagging, | ||
:manager_ref => %i(taggable tag), | ||
:parent_inventory_collections => %i(vms miq_templates) | ||
) | ||
|
||
builder.add_targeted_arel( | ||
lambda do |inventory_collection| | ||
manager_uuids = inventory_collection.parent_inventory_collections.collect(&:manager_uuids).map(&:to_a).flatten | ||
ems = inventory_collection.parent | ||
ems.vm_and_template_taggings.where( | ||
'taggable_id' => ems.vms_and_templates.where(:ems_ref => manager_uuids) | ||
) | ||
end | ||
) | ||
end | ||
end | ||
|
||
def add_key_pairs(extra_properties = {}) | ||
add_collection(cloud, :key_pairs, extra_properties) do |builder| | ||
builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::AuthKeyPair) | ||
builder.add_properties(:manager_uuids => name_references(:key_pairs)) if targeted? | ||
end | ||
end | ||
|
||
# TODO: mslemr - parent model_class used anywhere? If not, should be deleted | ||
def add_orchestration_stacks(extra_properties = {}) | ||
add_collection(cloud, :orchestration_stacks, extra_properties) do |builder| | ||
builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::OrchestrationStack) | ||
end | ||
end | ||
|
||
def add_vm_and_miq_template_ancestry | ||
add_collection(cloud, :vm_and_miq_template_ancestry, {}, {:auto_inventory_attributes => false, :without_model_class => true}) do |builder| | ||
builder.add_dependency_attributes( | ||
:vms => [collections[:vms]], | ||
:miq_templates => [collections[:miq_templates]] | ||
) | ||
end | ||
end | ||
|
||
def add_orchestration_stack_ancestry | ||
add_collection(cloud, :orchestration_stack_ancestry, {}, {:auto_inventory_attributes => false, :without_model_class => true}) do |builder| | ||
builder.add_dependency_attributes( | ||
:orchestration_stacks => [collections[:orchestration_stacks]], | ||
:orchestration_stacks_resources => [collections[:orchestration_stacks_resources]] | ||
) | ||
end | ||
end | ||
end |
64 changes: 64 additions & 0 deletions
64
app/models/manageiq/providers/amazon/inventory/persister/definitions/network_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,64 @@ | ||
module ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::NetworkCollections | ||
extend ActiveSupport::Concern | ||
|
||
def initialize_network_inventory_collections | ||
%i(cloud_networks | ||
cloud_subnets | ||
security_groups | ||
load_balancers | ||
load_balancer_pools | ||
load_balancer_pool_members | ||
load_balancer_pool_member_pools | ||
load_balancer_listeners | ||
load_balancer_listener_pools | ||
load_balancer_health_checks | ||
load_balancer_health_check_members).each do |name| | ||
|
||
add_collection(network, name) do |builder| | ||
builder.add_properties(:parent => manager.network_manager) if targeted? | ||
end | ||
end | ||
|
||
add_cloud_subnet_network_ports | ||
|
||
add_firewall_rules | ||
|
||
add_floating_ips | ||
|
||
add_network_ports | ||
end | ||
|
||
# ------ IC provider specific definitions ------------------------- | ||
|
||
def add_network_ports(extra_properties = {}) | ||
add_collection(network, :network_ports, extra_properties) do |builder| | ||
if targeted? | ||
builder.add_properties(:manager_uuids => references(:vms) + references(:network_ports) + references(:load_balancers)) | ||
builder.add_properties(:parent => manager.network_manager) | ||
end | ||
end | ||
end | ||
|
||
def add_floating_ips(extra_properties = {}) | ||
add_collection(network, :floating_ips, extra_properties) do |builder| | ||
if targeted? | ||
builder.add_properties(:manager_uuids => references(:floating_ips) + references(:load_balancers)) | ||
builder.add_properties(:parent => manager.network_manager) | ||
end | ||
end | ||
end | ||
|
||
def add_cloud_subnet_network_ports(extra_properties = {}) | ||
add_collection(network, :cloud_subnet_network_ports, extra_properties) do |builder| | ||
builder.add_properties(:manager_ref_allowed_nil => %i(cloud_subnet)) | ||
builder.add_properties(:parent => manager.network_manager) if targeted? | ||
end | ||
end | ||
|
||
def add_firewall_rules(extra_properties = {}) | ||
add_collection(network, :firewall_rules, extra_properties) do |builder| | ||
builder.add_properties(:manager_ref_allowed_nil => %i(source_security_group)) | ||
builder.add_properties(:parent => manager.network_manager) if targeted? | ||
end | ||
end | ||
end |
63 changes: 63 additions & 0 deletions
63
app/models/manageiq/providers/amazon/inventory/persister/definitions/storage_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,63 @@ | ||
module ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::StorageCollections | ||
extend ActiveSupport::Concern | ||
|
||
def initialize_storage_inventory_collections | ||
# should be defined by concrete persisters | ||
end | ||
|
||
# ------ IC provider specific definitions ------------------------- | ||
|
||
def add_cloud_volumes(extra_properties = {}) | ||
add_collection(storage, :cloud_volumes, extra_properties) do |builder| | ||
builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolume) | ||
builder.add_properties(:parent => manager.ebs_storage_manager) if targeted? | ||
|
||
builder.add_builder_params( | ||
:ems_id => block_storage_manager_id | ||
) | ||
end | ||
end | ||
|
||
def add_cloud_volume_snapshots(extra_properties = {}) | ||
add_collection(storage, :cloud_volume_snapshots, extra_properties) do |builder| | ||
builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolumeSnapshot) | ||
builder.add_properties(:parent => manager.ebs_storage_manager) if targeted? | ||
|
||
builder.add_builder_params( | ||
:ems_id => block_storage_manager_id | ||
) | ||
end | ||
end | ||
|
||
def add_cloud_object_store_containers(extra_properties = {}) | ||
add_collection(storage, :cloud_object_store_containers, extra_properties) do |builder| | ||
builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreContainer) | ||
builder.add_properties(:parent => manager.s3_storage_manager) if targeted? | ||
|
||
builder.add_builder_params( | ||
:ems_id => object_storage_manager_id | ||
) | ||
end | ||
end | ||
|
||
def add_cloud_object_store_objects(extra_properties = {}) | ||
add_collection(storage, :cloud_object_store_objects, extra_properties) do |builder| | ||
builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreObject) | ||
builder.add_properties(:parent => manager.s3_storage_manager) if targeted? | ||
|
||
builder.add_builder_params( | ||
:ems_id => object_storage_manager_id | ||
) | ||
end | ||
end | ||
|
||
protected | ||
|
||
def block_storage_manager_id | ||
manager.try(:ebs_storage_manager).try(:id) || manager.id | ||
end | ||
|
||
def object_storage_manager_id | ||
manager.try(:s3_storage_manager).try(:id) || manager.id | ||
end | ||
end |
40 changes: 29 additions & 11 deletions
40
app/models/manageiq/providers/amazon/inventory/persister/network_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,16 +1,34 @@ | ||
class ManageIQ::Providers::Amazon::Inventory::Persister::NetworkManager < ManageIQ::Providers::Amazon::Inventory::Persister | ||
include ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::CloudCollections | ||
include ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::NetworkCollections | ||
|
||
def initialize_inventory_collections | ||
add_inventory_collections( | ||
network, | ||
%i(cloud_subnet_network_ports network_ports floating_ips cloud_subnets cloud_networks security_groups | ||
firewall_rules load_balancers load_balancer_pools load_balancer_pool_members load_balancer_pool_member_pools | ||
load_balancer_listeners load_balancer_listener_pools load_balancer_health_checks | ||
load_balancer_health_check_members network_routers) | ||
) | ||
initialize_network_inventory_collections | ||
|
||
initialize_cloud_inventory_collections | ||
end | ||
|
||
def initialize_network_inventory_collections | ||
super | ||
|
||
add_inventory_collections(cloud, | ||
%i(vms orchestration_stacks availability_zones), | ||
:parent => manager.parent_manager, | ||
:strategy => :local_db_cache_all) | ||
add_collection(network, :network_routers) | ||
end | ||
|
||
def initialize_cloud_inventory_collections | ||
%i(vms | ||
availability_zones).each do |name| | ||
|
||
add_collection(cloud, name) do |builder| | ||
builder.add_properties( | ||
:parent => manager.parent_manager, | ||
:strategy => :local_db_cache_all | ||
) | ||
end | ||
end | ||
|
||
add_orchestration_stacks( | ||
:parent => manager.parent_manager, | ||
:strategy => :local_db_cache_all | ||
) | ||
end | ||
end |
Oops, something went wrong.