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

Catalog Item type list is dependent on installed providers #16559

Merged
merged 3 commits into from
Dec 11, 2017

Conversation

mkanoor
Copy link
Contributor

@mkanoor mkanoor commented Nov 29, 2017

https://bugzilla.redhat.com/show_bug.cgi?id=1515371

Currently we display all catalog item types irrespective of what
providers are installed in the appliance. This PR links the catalog
items to different providers and sets the display attribute based
on the presence of specific provider(s). This would be used by the
UI to list the valid catalog item types

Amazon Provider Changes are in PR
ManageIQ/manageiq-providers-amazon#377

VMware Provider changes in PR
ManageIQ/manageiq-providers-vmware#151

Openshift Provider changes in
ManageIQ/manageiq-providers-openshift#74

SCVMM Provider changes in PR
ManageIQ/manageiq-providers-scvmm#54

Openstack Provider PR
ManageIQ/manageiq-providers-openstack#177

Azure Provider PR
ManageIQ/manageiq-providers-azure#185

External Ansible Tower PR
ManageIQ/manageiq-providers-ansible_tower#42

Redhat Provider PR
ManageIQ/manageiq-providers-ovirt#174

Google Provider PR
ManageIQ/manageiq-providers-google#35

@mkanoor mkanoor added the bug label Nov 29, 2017
@mkanoor mkanoor requested review from Fryguy and bzwei November 29, 2017 21:07
@mkanoor
Copy link
Contributor Author

mkanoor commented Nov 29, 2017

@Fryguy @bzwei @h-kataria
Please review

end

def self.generic_ansible_playbook_provider_present?
ExtManagementSystem.where(:type => "ManageIQ::Providers::EmbeddedAnsible::AutomationManager").any?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should check whether it is enabled.

ORCHESTRATION_PROVIDER_TYPES = %w(
ManageIQ::Providers::Amazon::CloudManager
ManageIQ::Providers::Azure::CloudManager
ManageIQ::Providers::Google::CloudManager
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no google, but we have ManageIQ::Providers::VMWare::CloudManager

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bzwei Is there a way to dynamically build this list?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmcculloug Yes we can. Working with Madhu now.

ManageIQ::Providers::Azure::CloudManager
ManageIQ::Providers::Google::CloudManager
ManageIQ::Providers::Openstack::CloudManager
ManageIQ::Providers::Openstack::InfraManager
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no InfraManager

@@ -69,6 +69,70 @@ class ServiceTemplate < ApplicationRecord
scope :with_existent_service_template_catalog_id, -> { where.not(:service_template_catalog_id => nil) }
scope :displayed, -> { where(:display => true) }

def self.catalog_item_types
CATALOG_ITEM_TYPES.each.with_object({}) do |(key, description), hash|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the UI use it - gray out non-displayable item from the dropdown? Or should we simply remove non-qualified types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bzwei @h-kataria mentioned that there is some bootstrap magic that does that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bzwei yes UI will show those items as grayed/disabled in the drop down, see screenshot in ManageIQ/manageiq-ui-classic#2908

ManageIQ::Providers::Openstack::InfraManager
).freeze

def self.generic_orchestration_provider_present?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not solve the case where providers are added but there is no orchestration template. The same question for OpenShift template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bzwei so what is the call to check if there is an orchestration template?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For each orderable orchestration template, find its eligible_managers

h-kataria added a commit to h-kataria/manageiq-ui-classic that referenced this pull request Dec 1, 2017
This PR uses changes from backend in ManageIQ/manageiq#16559 to determine whether options in the drop down should be available or disabled based upon results returned in hash by backend method.

https://bugzilla.redhat.com/show_bug.cgi?id=1515371

def self.generic_orchestration_provider_present?
orchestration_providers = OrchestrationTemplate.distinct.pluck(:type).collect do |otype|
otype.constantize.eligible_managers.collect(&:type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#eligible_managers has Rbac (https://github.com/ManageIQ/manageiq/blob/master/app/models/orchestration_template.rb#L127). Should we check the same for other provider_present? in Ln 104, 108 etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bzwei

Rbac::Filterer.filtered(ExtManagementSystem, :named_scope => [[:with_eligible_manager_types, eligible_manager_types]])

Does not accept a User object so its most probably relying on the User.current_user being set in the UI controller based on the currently logged in user so it should do the right thing here. We dont have to pass the user object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bzwei I checked with @kbrock and his suggestion was the RBAC calls might slow this down a bit. So for the first round can we just use the ActiveModel queries and then we can make the RBAC changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. you can pass in :user into the filtered() call
  2. Rbac slows everything down. It is faster to just have no security.
  3. The goal is to use rbac in your query along with other sql filtering (e.g. with_eligible_manager_types)

Does this work just calling the scope directly?

Rbac::Filterer.filtered(ExtManagementSystem.with_eligible_manager_types(eligible_manager_types))

end

def self.openstack_provider_present?
ExtManagementSystem.where(:type => "ManageIQ::Providers::Openstack::InfraManager").any?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have both CloudManager and InfraManager for OpenStack.


def self.azure_provider_present?
ExtManagementSystem.where(:type => "ManageIQ::Providers::Azure::CloudManager").any?
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👎 for provider specifics in the manageiq repo...there has to be a way to do this more generically / pluggable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, the fact that this needs to be defined for every provider should send off warning bells.

Fryguy
Fryguy previously requested changes Dec 4, 2017
Copy link
Member

@Fryguy Fryguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the hardcoding of providers in here as it's just one more impossible-to-detangle place.

Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make too many queries to the db.
Would be best to bring back catalog items and the corresponding type (from there, the ui should be able to provide a filter)

Having said that, we want to avoid asking the ui to hard code the class names in their checks.


def self.generic_orchestration_provider_present?
orchestration_providers = OrchestrationTemplate.distinct.pluck(:type).collect do |otype|
otype.constantize.eligible_managers.collect(&:type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. you can pass in :user into the filtered() call
  2. Rbac slows everything down. It is faster to just have no security.
  3. The goal is to use rbac in your query along with other sql filtering (e.g. with_eligible_manager_types)

Does this work just calling the scope directly?

Rbac::Filterer.filtered(ExtManagementSystem.with_eligible_manager_types(eligible_manager_types))


def self.azure_provider_present?
ExtManagementSystem.where(:type => "ManageIQ::Providers::Azure::CloudManager").any?
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, the fact that this needs to be defined for every provider should send off warning bells.

https://bugzilla.redhat.com/show_bug.cgi?id=1515371

Currently we display all catalog item types irrespective of what
providers are installed in the appliance. This PR links the catalog
items to different providers and sets the display attribute based
on the presence of specific provider(s). This would be used by the
UI to list the valid catalog item types
@mkanoor
Copy link
Contributor Author

mkanoor commented Dec 8, 2017

@Fryguy @agrare
Please review

def self.catalog_item_types
ci_types = Rbac.filtered(ExtManagementSystem.all).flat_map(&:supported_catalog_types).uniq
ci_types << 'generic_orchestration' if Rbac.filtered(OrchestrationTemplate).exists?
ci_types << 'generic'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are building this up as an index for lookup purposes (with uniqueness), you would be better off using a Set object (and not manually calling unique, but letting Set do that for you).

Copy link
Member

@Fryguy Fryguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much better than previously 👍

@Fryguy Fryguy dismissed their stale review December 9, 2017 01:53

@agrare I'll leave this one up to you.

@miq-bot
Copy link
Member

miq-bot commented Dec 11, 2017

Checked commits mkanoor/manageiq@aca00ba~...32eef9e with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0
5 files checked, 0 offenses detected
Everything looks fine. 👍

@agrare
Copy link
Member

agrare commented Dec 11, 2017

All dependent provider PRs merged

Copy link
Member

@agrare agrare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me @mkanoor 👍

@agrare agrare merged commit 0bedb65 into ManageIQ:master Dec 11, 2017
@agrare agrare added this to the Sprint 75 Ending Dec 11, 2017 milestone Dec 11, 2017
simaishi pushed a commit that referenced this pull request Dec 11, 2017
Catalog Item type list is dependent on installed providers
(cherry picked from commit 0bedb65)

https://bugzilla.redhat.com/show_bug.cgi?id=1520613
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 1c20502be8c4fed237bc49612a62722d7d1851c6
Author: Adam Grare <[email protected]>
Date:   Mon Dec 11 13:06:28 2017 -0500

    Merge pull request #16559 from mkanoor/catalog_item_types
    
    Catalog Item type list is dependent on installed providers
    (cherry picked from commit 0bedb65ae134f00b2f15511ce5270208aa5b6ac3)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1520613

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants