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

create configuration script sources #14006

Merged
merged 5 commits into from
Mar 16, 2017
Merged

create configuration script sources #14006

merged 5 commits into from
Mar 16, 2017

Conversation

jntullo
Copy link

@jntullo jntullo commented Feb 21, 2017

Create configuration script sources

cc: @h-kataria @ZitaNemeckova
@miq-bot add_label enhancement, api, wip
@miq-bot assign @abellotti

Depends on #14173

config/api.yml Outdated
@@ -537,12 +537,15 @@
:description: Configuration Script Source
:options:
- :collection
:verbs: *g
:verbs: *gp
Copy link
Contributor

Choose a reason for hiding this comment

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

should probably be *gpppd so that you can also update and delete..

Copy link
Author

Choose a reason for hiding this comment

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

@himdel will be added when we work on update and delete

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks, no pressure :) (except that UI work is waiting for this... :D)

@jntullo jntullo changed the title [WIP] create configuration script sources create configuration script sources Mar 13, 2017
@jntullo
Copy link
Author

jntullo commented Mar 13, 2017

@miq-bot remove_label wip

@miq-bot miq-bot removed the wip label Mar 13, 2017
@jntullo jntullo closed this Mar 13, 2017
@jntullo jntullo reopened this Mar 13, 2017
@@ -4,4 +4,10 @@ class ConfigurationScriptSource < ApplicationRecord
belongs_to :manager, :class_name => "ExtManagementSystem"

virtual_total :total_payloads, :configuration_script_payloads

def self.class_from_request_data(data)
manager = ExtManagementSystem.find(data['manager_resource'])
Copy link
Member

Choose a reason for hiding this comment

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

data['manager_resource'] is API payload dependent. Let's send in the object instead, i.e. class_for_manager(manager)

parse_href(data['manager_resource']['href']).last
elsif data['manager_resource'].key?('id')
data['manager_resource']['id']
end
Copy link
Member

Choose a reason for hiding this comment

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

if think this can simply be:

def validate_attrs(data)
  raise 'must supply a manager resource' unless data['manager_resource']
end

def create_resource(_type, _id, data)
attrs = validate_attrs(data)
type = ConfigurationScriptSource.class_from_request_data(attrs)
raise 'type not currently supported' unless type.respond_to?(:create_in_provider_queue)
Copy link
Member

Choose a reason for hiding this comment

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

with the change below, above can be something like:

   validate_attrs(data)
   manager_id = parse_id(data['manager_resource'], :providers)
   manager = resource_search(manager_id, :providers, collection_class(:providers))
   type = ConfigurationScriptSource.class_for_manager(manager)
   ...

Copy link
Member

Choose a reason for hiding this comment

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

once the model supports other than ExtManagementSystem, we can provide an different variant of parse_id that supports a list of collections, where it returns the collection and id. This way we know for sure what href we are parsing (and the correct collection accessed in the following resource_search).

Copy link
Member

Choose a reason for hiding this comment

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

as for the message, maybe something like "ConfigurationScriptSources cannot be added to #{manager_ident(manager)}"

@miq-bot
Copy link
Member

miq-bot commented Mar 16, 2017

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

@@ -18,10 +18,30 @@ def delete_resource(type, id, _data = {})
action_result(false, err.to_s)
end

def create_resource(_type, _id, data)
validate_attrs(data)
manager_id = parse_id(data['manager_resource'], :providers)
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a check here before we do a resource_search,

raise "Must specify a valid manager_resource href or id" unless manager_id

and add a test for that bad_request, maybe passing in a bogus /api/users/10 href. Thanks.

@miq-bot
Copy link
Member

miq-bot commented Mar 16, 2017

Checked commits jntullo/manageiq@4f30275~...f2e1e79 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
4 files checked, 0 offenses detected
Everything looks good. ⭐

@abellotti
Copy link
Member

Thanks @jntullo for this last update.

LGTM!! 👍

@abellotti abellotti merged commit e3e4ac4 into ManageIQ:master Mar 16, 2017
@abellotti abellotti added this to the Sprint 57 Ending Mar 27, 2017 milestone Mar 16, 2017
@jntullo jntullo deleted the enhancement/repository_create branch November 28, 2017 19:41
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.

4 participants