Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MORPHY] Add IBM PowerVC provider #21410

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ group :ibm_cloud, :manageiq_default do
manageiq_plugin "manageiq-providers-ibm_cloud"
end

group :ibm_power_vc, :manageiq_default do
manageiq_plugin "manageiq-providers-ibm_power_vc"
end

group :ibm_terraform, :manageiq_default do
manageiq_plugin "manageiq-providers-ibm_terraform"
end
Expand Down
12 changes: 12 additions & 0 deletions app/models/manageiq/providers/inventory/persister.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ def parent
manager.presence
end

def cloud_manager
manager.kind_of?(EmsCloud) ? manager : manager.parent_manager
end

def network_manager
manager.kind_of?(EmsNetwork) ? manager : manager.network_manager
end

def storage_manager
manager.kind_of?(EmsStorage) ? manager : manager.storage_manager
end

def assert_graph_integrity?
!Rails.env.production?
end
Expand Down
45 changes: 22 additions & 23 deletions app/models/manageiq/providers/inventory/persister/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def self.prepare_data(name, persister_class, options = {})
builder
end

attr_accessor :name, :persister_class, :properties, :inventory_object_attributes,
:default_values, :dependency_attributes, :options, :adv_settings, :shared_properties

# @see prepare_data()
def initialize(name, persister_class, options = self.class.default_options)
@name = name
Expand All @@ -61,6 +64,17 @@ def initialize(name, persister_class, options = self.class.default_options)
@shared_properties = options[:shared_properties] # From persister
end

def manager_class
@manager_class ||= begin
provider_module = persister_class.provider_module
manager_module = self.class.name.split('::').last

"#{provider_module}::#{manager_module}".safe_constantize
rescue ::ManageIQ::Providers::Inflector::ObjectNotNamespacedError
nil
end
end

# Builds data for InventoryCollection
# Calls method @name (if exists) with specific properties
# Yields for overwriting provider-specific properties
Expand Down Expand Up @@ -206,29 +220,14 @@ def merge_hashes(source, dest, mode)
#
# @return [Class | nil] when class doesn't exist, returns nil
def auto_model_class
model_class = begin
# a) Provider specific class
provider_module = @persister_class.provider_module
manager_module = self.class.name.split('::').last

class_name = "#{provider_module}::#{manager_module}::#{@name.to_s.classify}"

inferred_class = class_name.safe_constantize

# safe_constantize can return different similar class ( some Rails auto-magic :/ )
if inferred_class.to_s == class_name
inferred_class
end
rescue ::ManageIQ::Providers::Inflector::ObjectNotNamespacedError
nil
end

if model_class
model_class
else
# b) general class
"::#{@name.to_s.classify}".safe_constantize
end
class_name = "#{manager_class}::#{name.to_s.classify}"
provider_class = class_name.safe_constantize

# Check that safe_constantize returns our expected class_name, if not then
# return the base class.
#
# safe_constantize can return different similar class ( some Rails auto-magic :/ )
provider_class.to_s == class_name ? provider_class : "::#{name.to_s.classify}".safe_constantize
end

# Enables/disables auto_model_class and exception check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ def availability_zones
add_common_default_values
end

def cloud_tenants
add_common_default_values
end

def cloud_volumes
add_common_default_values
end

def flavors
add_common_default_values
end
Expand All @@ -17,8 +25,8 @@ def auth_key_pairs
:manager_ref => %i(name)
)
add_default_values(
:resource_id => ->(persister) { persister.manager.id },
:resource_type => ->(persister) { persister.manager.class.base_class }
:resource_id => shared_properties[:parent].id,
:resource_type => shared_properties[:parent].class.base_class
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,7 @@ def load_balancer_health_check_members
protected

def add_common_default_values
add_default_values(:ems_id => default_ems_id)
end

def default_ems_id
->(persister) { persister.manager.try(:network_manager).try(:id) || persister.manager.id }
add_default_values(:ext_management_system => ->(persister) { persister.network_manager })
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ def add_collection(builder_class, collection_name, extra_properties = {}, settin
collections[collection_name] = builder.to_inventory_collection
end

def add_cloud_collection(collection_name, extra_properties = {}, settings = {}, &block)
add_collection_for_manager("cloud", collection_name, extra_properties, settings, &block)
end

def add_network_collection(collection_name, extra_properties = {}, settings = {}, &block)
add_collection_for_manager("network", collection_name, extra_properties, settings, &block)
end

def add_storage_collection(collection_name, extra_properties = {}, settings = {}, &block)
add_collection_for_manager("storage", collection_name, extra_properties, settings, &block)
end

# builder_class for add_collection()
def cloud
::ManageIQ::Providers::Inventory::Persister::Builder::CloudManager
Expand Down Expand Up @@ -119,4 +131,14 @@ def references(collection)
def name_references(collection)
target.try(:manager_refs_by_association).try(:[], collection).try(:[], :name).try(:to_a) || []
end

private

def add_collection_for_manager(manager_type, collection_name, extra_properties = {}, settings = {}, &block)
parent_manager = send("#{manager_type}_manager")
settings.reverse_merge!(:shared_properties => {:parent => parent_manager})

builder_class = send(manager_type)
add_collection(builder_class, collection_name, extra_properties, settings, &block)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def miq_templates
add_default_values(
:template => true
)

template_class = "#{manager_class}::Template".safe_constantize
add_properties(:model_class => template_class) if template_class
end

def vm_template_shared
Expand All @@ -68,9 +71,7 @@ def vm_template_shared
:custom_reconnect_block => INVENTORY_RECONNECT_BLOCK
)

add_default_values(
:ems_id => ->(persister) { persister.manager.id }
)
add_common_default_values
end

def vm_and_template_labels
Expand Down Expand Up @@ -183,7 +184,8 @@ def orchestration_stacks
protected

def add_common_default_values
add_default_values(:ems_id => ->(persister) { persister.manager.id })
ems = shared_properties[:parent]&.id || ->(persister) { persister.manager.id }
add_default_values(:ems_id => ems)
end

def relationship_save_block(relationship_key:, relationship_type: :ems_metadata, parent_type: nil)
Expand Down