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

add create_catalog_item to ServiceTemplateOrchestration #13628

Merged
merged 2 commits into from
Jan 27, 2017
Merged

add create_catalog_item to ServiceTemplateOrchestration #13628

merged 2 commits into from
Jan 27, 2017

Conversation

jntullo
Copy link

@jntullo jntullo commented Jan 23, 2017

This adds class method create_catalog_item to ServiceTemplateOrchestration and takes in the following:

{
        :name         => 'Orchestration Template',
        :service_type => 'atomic',
        :prov_type    => 'generic_orchestration',
        :display      => 'false',
        :description  => 'a description',
        :config_info  => {
          :template_id => template.id,
          :manager_id  => manager.id,
          :provision   => {
            :fqname            => ra1.fqname,
            :dialog_id => service_dialog.id
          },
          :retirement  => {
            :fqname            => ra2.fqname,
            :dialog_id => service_dialog.id
          }
        }
      }

@miq-bot enhancement, euwe/no, services, wip
@miq-bot assign @bzwei

create(options.except(:config_info)).tap do |service_template|
config_info = options[:config_info]

service_template.orchestration_template = if config_info[:template_id]
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to validate both template and manager must exist? If this is the only call we should unless users can call update method to set them later. This make me think of the need for update method and delete method as a complete solution.

Copy link
Author

Choose a reason for hiding this comment

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

@bzwei yeah, good point. if both are required for a valid orchestration template, we should check that both exist, as well as make an update / delete method.


def self.validate_config_info(options)
config_info = options[:config_info]
if (config_info[:template_id] && !config_info[:manager_id]) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

You allow a case that neither exists. Let's make it simpler by requiring both must exist.

Copy link
Author

Choose a reason for hiding this comment

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

@bzwei oh gotcha. was thinking it was either one or the other

create(options.except(:config_info)).tap do |service_template|
config_info = validate_config_info(options)

if config_info[:template_id] && config_info[:manager_id]
Copy link
Contributor

Choose a reason for hiding this comment

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

So here there is no need for the if statement

:manager_id => manager.id,
:provision => {
:fqname => ra1.fqname,
:service_dialog_id => service_dialog.id
Copy link
Contributor

Choose a reason for hiding this comment

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

@jntullo Let's change :service_dialog_id to :dialog_id. This is inline with the column name for ResourceAction You need to change in the base method too. Thanks.

create(options.except(:config_info)).tap do |service_template|
config_info = validate_config_info(options)

service_template.orchestration_template = OrchestrationTemplate.find(config_info[:template_id])
Copy link
Contributor

Choose a reason for hiding this comment

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

We want to accept :template_id or :template. The later points to an object that can be directly assigned. Same to manager. Need to update the validate method too.


def self.validate_config_info(options)
config_info = options[:config_info]
unless (config_info[:template_id] && config_info[:manager_id]) || (config_info[:template] && config_info[:manager])
Copy link
Author

Choose a reason for hiding this comment

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

@bzwei should I check for combinations of ids / objects?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally we should allow the combination. What you have here is likely real. I am ok with it.

@miq-bot
Copy link
Member

miq-bot commented Jan 26, 2017

Checked commits jntullo/manageiq@ce9b22b~...911d7fd with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks good. 👍

@jntullo jntullo changed the title [WIP] add create_catalog_item to ServiceTemplateOrchestration add create_catalog_item to ServiceTemplateOrchestration Jan 26, 2017
@jntullo
Copy link
Author

jntullo commented Jan 26, 2017

@miq-bot remove_label wip

@miq-bot miq-bot removed the wip label Jan 26, 2017
create(options.except(:config_info)).tap do |service_template|
config_info = validate_config_info(options)

service_template.orchestration_template = if config_info[:template_id]
Copy link
Contributor

Choose a reason for hiding this comment

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

We may simply put config_info[:template] || OrchestrationTemplate.find(config_info[:template_id]) since we already validate either one must exist.

Copy link
Author

Choose a reason for hiding this comment

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

@bzwei I wanted to, but the line was too long so rubocop wasn't happy, and this was more readable than breaking that up onto two lines imo

@bzwei
Copy link
Contributor

bzwei commented Jan 26, 2017

@miq-bot assign @gmcculloug

@miq-bot miq-bot assigned gmcculloug and unassigned bzwei Jan 26, 2017

def self.validate_config_info(options)
config_info = options[:config_info]
unless (config_info[:template_id] && config_info[:manager_id]) || (config_info[:template] && config_info[:manager])
Copy link
Member

Choose a reason for hiding this comment

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

@jntullo I would suggest allowing for the different combinations since that would better align with the logic in the create_catalog_item method. This can be done in a followup PR.

@gmcculloug gmcculloug merged commit a9343f4 into ManageIQ:master Jan 27, 2017
@gmcculloug gmcculloug added this to the Sprint 53 Ending Jan 30, 2017 milestone Jan 27, 2017
@jntullo jntullo deleted the enhancement/create_service_template_orchestration branch November 28, 2017 19:43
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.

5 participants