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

Order Ansible Playbook from a Custom Button using a Method #113

Merged
merged 4 commits into from
May 12, 2017

Conversation

mkanoor
Copy link
Contributor

@mkanoor mkanoor commented May 10, 2017

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

Allows for using a single dialog that is shared between the Custom Button and the Service Template Ordering.

The Request instance is called Order_Ansible_Playbook

The button needs 2 parameters along with the tie up to the Service Dialog
screen shot 2017-05-18 at 11 23 42 am

  • service_template_name
  • hosts localhost|vmdb_object|ip1,ip2,ip3

vmdb_object refers to the context of the current object being selected from the button it could be a host or vm. The method would figure out the object to use at runtime.
screen shot 2017-05-11 at 12 03 44 pm

@mkanoor
Copy link
Contributor Author

mkanoor commented May 10, 2017

@gmcculloug @tinaafitz
Please review

Copy link
Member

@tinaafitz tinaafitz left a comment

Choose a reason for hiding this comment

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

@mkanoor Looks good.

@gmcculloug
Copy link
Member

@mkanoor I can see this quickly expanding to support other resources like hosts and containers. Instead of overloading the hosts property would it make more sense to use a different key name.

We also have the attribute vmdb_object_type: vm or vmdb_object_type: host that could be used to dynamically determine what object the custom button is running for.

Would it make sense to use the vmdb_object_type as the default value if hosts is not provided? Then the hosts property would no longer be required from the custom button setup or from the dialog.

@mkanoor
Copy link
Contributor Author

mkanoor commented May 10, 2017

@gmcculloug
We won't know what hosts parameter is needed for the playbook, is it localhost, vm or something else. The vm basically says that use the passed in vm. So if we key our logic off of vmdb_object_type we will set the host to be always the vm which might not work for all playbooks.

@gmcculloug
Copy link
Member

I was thinking if someone passed a hosts value from the key/value pair of the dialog we would use that. Otherwise we use the object specified by vmdb_object_type.

My point was this method could be used for a custom_button on a vm, host, container or even multi-object in the near future. And the vmdb_object_type already tells us the target object type to go after in the root object. I think this method could be re-usable for different objects types and require less configuration.

vmdb_object.try(:ipaddresses).try(:first).tap do |ip|
if ip.nil?
@handle.log(:error, "IP address not specified for vmdb_object")
raise "IP address not specified for vmdb_object"
Copy link
Member

Choose a reason for hiding this comment

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

@mkanoor Is there a reason to log and raise on every error? Since the message is the same is raise not informative enough? If both are needed I would suggest creating a method so we do not have to dup every error string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gmcculloug
Yes I think the raise would be good enough since it would show in the Automate log

@miq-bot
Copy link
Member

miq-bot commented May 12, 2017

Checked commits mkanoor/manageiq-content@00f4a46~...552927d with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks fine. 🍪

@gmcculloug gmcculloug merged commit 3220db0 into ManageIQ:master May 12, 2017
simaishi pushed a commit that referenced this pull request May 12, 2017
Order Ansible Playbook from a Custom Button using a Method
(cherry picked from commit 3220db0)

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

Fine backport details:

$ git log -1
commit bace533c620591b3206fe11f8a6be5bdbd7df080
Author: Greg McCullough <gmccullo@redhat.com>
Date:   Fri May 12 13:10:10 2017 -0400

    Merge pull request #113 from mkanoor/bz_1449361
    
    Order Ansible Playbook from a Custom Button using a Method
    (cherry picked from commit 3220db060e4f35e7908dbc66a1352a38dd0ffb4c)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1450485

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