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

ServiceTemplate update_catalog_item #13811

Merged
merged 6 commits into from
Feb 24, 2017
Merged

ServiceTemplate update_catalog_item #13811

merged 6 commits into from
Feb 24, 2017

Conversation

jntullo
Copy link

@jntullo jntullo commented Feb 8, 2017

WIP PR for updating of a catalog item. Format for update will be the same as creating one, ie:

        {
          :name        => 'Updated Template Name',
          :prov_type   => 'amazon',
          :display     => 'false',
          :description => 'a description',
          :config_info => {
            :miq_request_dialog_name => request_dialog.name,
            :placement_auto          => [true, 1],
            :number_of_vms           => [1, '1'],
            :src_vm_id               => [new_vm.id, new_vm.name],
            :vm_name                 => new_vm.name,
            :schedule_type           => ['immediately', 'Immediately on Approval'],
            :instance_type           => [flavor.id, flavor.name],
            :src_ems_id              => [ems.id, ems.name],
            :provision               => {
              :fqname    => ra1.fqname,
              :dialog_id => nil
            },
            :reconfigure             => {
              :fqname    => ra3.fqname,
              :dialog_id => service_dialog.id
            }
          }
        }

@miq-bot add_label wip, enhancement, services

@@ -74,6 +74,25 @@ def self.create_catalog_item(options, auth_user)
end
end

def self.update_catalog_item(catalog_item, options, auth_user)
Copy link
Contributor

Choose a reason for hiding this comment

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

It should NOT be a class method.

@miq-bot
Copy link
Member

miq-bot commented Feb 9, 2017

This pull request is not mergeable. Please rebase and repush.

@jntullo
Copy link
Author

jntullo commented Feb 10, 2017

@miq-bot remove_label wip

@jntullo jntullo changed the title [WIP] ServiceTemplate update_catalog_item ServiceTemplate update_catalog_item Feb 10, 2017
@miq-bot miq-bot removed the wip label Feb 10, 2017
@miq-bot
Copy link
Member

miq-bot commented Feb 15, 2017

This pull request is not mergeable. Please rebase and repush.

@syncrou
Copy link
Contributor

syncrou commented Feb 21, 2017

ping

def update_resource_actions(ae_endpoints)
resource_action_options.each do |action|
# If the action exists in updated parameters
if ae_endpoints[action[:param_key]]
Copy link
Contributor

Choose a reason for hiding this comment

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

You only need to find the existing resource_action once before the if/else clause.

def self.create_from_options(options)
create(options.except(:config_info).merge(:options => { :config_info => options[:config_info] }))
def update_from_options(options)
update_attributes!(options.except(:config_info).merge!(:options => { :config_info => options[:config_info] }))
Copy link
Contributor

Choose a reason for hiding this comment

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

should not need ! for merge thought it may not matter here.

@@ -57,6 +57,29 @@ def self.validate_config_info(options)

private

def update_service_resources(config_info, _auth_user = nil)
if config_info[:template_id] && config_info[:template_id] != orchestration_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.

orchestration_template.try(:id), same for other similar cases.


def validate_update_config_info(options)
super
config_info = options[:config_info]
Copy link
Contributor

Choose a reason for hiding this comment

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

code reuse - self.class.validate_config_info(options), same for the other class.

it 'creates and returns an ansible tower catalog item' do
service_template = ServiceTemplateAnsibleTower.create_catalog_item(catalog_item_options)
service_template.reload
context '.create_catalog_item' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Although context and describe seem interchangeable, my understanding the typical use is
describe a method
context a condition

if ae_endpoints[action[:param_key]]
# And the resource action exists on the template already, update it
if resource_action
resource_actions.find_by(:action => action[:name]).update_attributes!(ae_endpoints[action[:param_key]])
Copy link
Contributor

Choose a reason for hiding this comment

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

resource_action.update_attributes!

Copy link
Contributor

Choose a reason for hiding this comment

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

we can extract ae_endpoints[action[:param_key]] into a local variable since it is used three times

options[:config_info]
end

def resource_action_options
Copy link
Contributor

Choose a reason for hiding this comment

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

We can start to use the constants defined in ResourceAction for Provision, Reconfigure, and Retirement.

Copy link
Contributor

Choose a reason for hiding this comment

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

We use the word options every where. Can we come up a better name for this method? Something like resource_action_list. Naming is hard :(

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 think naming is my least favorite part of writing code 😆 I like resource_action_list - will do!


private

def update_service_resources(config_info, _auth_user = nil)
if config_info[:configuration_script_id] && config_info[:configuration_script_id] != job_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.

job_template.try(:id)

if resource_params
# And the resource action exists on the template already, update it
if resource_action
resource_actions.find_by(:action => action[:name]).update_attributes!(resource_params)
Copy link
Contributor

Choose a reason for hiding this comment

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

resource_action.update_attributes!

if resource_params
# And the resource action exists on the template already, update it
if resource_action
resource_action.update_attributes!(resource_params)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should slice selective attributes known to ResourceAction just like how to create resource actions.

@miq-bot
Copy link
Member

miq-bot commented Feb 23, 2017

This pull request is not mergeable. Please rebase and repush.

@syncrou
Copy link
Contributor

syncrou commented Feb 23, 2017

👍 Looks good to me

@@ -416,4 +473,8 @@ def resource_actions_info
end
config_info
end

def resource_action_attrs
Copy link
Member

Choose a reason for hiding this comment

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

We need a better name here, this name is confusing/misleading. Also, I do not see why this is not just a constant instead of a method.

Maybe: RESOURCE_ACTION_UPDATE_ATTRS Open to other suggestions.

add .try(:destroy)

make resource action attrs into a constant
@miq-bot
Copy link
Member

miq-bot commented Feb 24, 2017

Checked commits jntullo/manageiq@797e93d~...4a3301a with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
6 files checked, 0 offenses detected
Everything looks good. 👍

@gmcculloug gmcculloug merged commit 036a2cf into ManageIQ:master Feb 24, 2017
@gmcculloug gmcculloug added this to the Sprint 55 Ending Feb 27, 2017 milestone Feb 24, 2017
@jntullo jntullo deleted the enhancement/update_service_template branch November 28, 2017 19:42
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