-
Notifications
You must be signed in to change notification settings - Fork 900
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
Launch an URL returned by an automate button #10118
Conversation
We do something like this for the Dynamic dialog fields in automate. We run an automate resolution and get a workspace back app/models/dynamic_dialog_field_value_processor.rb#L8. Then pass the root attributes app/models/dynamic_dialog_field_value_processor.rb#L14 to be processed here app/models/dialog_field_text_box.rb#L61. Does that help? |
@gmcculloug : If I read it correctly, then that is sync. I need to do it async through the MiqTask (and wait_for_task on the UI side). Things like setting up a tunnel might take some time and the UI should not hang while waiting for the automate. Also the setup of a tunnel to a VNC endpoint on a hypevisor node would be done by a different appliance. The UI appliance probably won't be able to reach the hypervisor nodes directly at a service provider deployment. Does that make sense? |
@martinpovolny I think what you really want to do here is pass something to the automate method that it can update instead of trying to pull back data from the automate method. For example you could pass the ID of the resource you are running against and if that supports custom_attributes the automate script could set the required data there. Otherwise, we could do something like expose the MiqTask object to the automate service model and allow the automate method to set values into the Task. |
0595035
to
2cbfb4a
Compare
@@ -1,4 +1,6 @@ | |||
module MiqAeMethodService | |||
class MiqAeServiceVmInfra < MiqAeServiceVm | |||
expose :set_remote_console_url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the active record model method this belongs in miq_ae_service_vm.rb. (Should be removed from miq_ae_service_vm_infra.rb
and miq_ae_service_vm_or_template.rb
.
fb6c3f3
to
1f54960
Compare
d468d52
to
a68a360
Compare
79996a9
to
f966f96
Compare
@@ -250,6 +251,17 @@ def applies_to_class_model(applies_to_class) | |||
applies_to_class == "ServiceTemplate" ? Service : applies_to_class.constantize | |||
end | |||
|
|||
def custom_button_done | |||
url = SystemConsole.where(:vm => params[:id]).first.try(:url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martinpovolny @gmcculloug
Is this meant only for VM's or can it be used with other objects like storage, network, host etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only VMs at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martinpovolny
Will we have a 'ur'l as a custom attribute available for vm objects which the Automate Method would set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkanoor : that sounds good. How do I do that? @gmcculloug suggested that I should pass an ID of some resource and work with that. Can you show me how I would do what you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to: url = SystemConsole.find_by(:vm => params[:id]).try(:url)
You are currently setting the url
when calling set_remote_console_url
from automate. Do you need to store the url
somewhere else since it already resides in the SystemConsole instance associated to the VM?
If so automate supports custom_get
and custom_set
methods. lib/miq_automation_engine/service_models/miq_ae_service_vm_or_template.rb#L140
Note: These custom attributes are visible in the VM summary screen. Here is an example of what it would look like to set a custom attribute named url
:
@martinpovolny I'm getting this error in the
|
f966f96
to
36fc0fd
Compare
@skateman : can you, please, check again? |
@martinpovolny looks good, aren't we planning to add a spinner while we wait for the task? |
Would be good to get some feedback from the automate people. I think that the functionality is a good one but I am not so sure about how I actually did it. It works but if feels hacky. The question by @mkanoor if it's only valid for VMs suggests it might make sense for more entities. But the |
@@ -1,5 +1,9 @@ | |||
module MiqAeMethodService | |||
class MiqAeServiceVm < MiqAeServiceVmOrTemplate | |||
def set_remote_console_url(url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the rubocop warning this method should be named remote_console_url=
def remote_console_url=(url)
Would also need to update the method in the VM model which would need to take two parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -91,4 +91,16 @@ def running_processes | |||
end | |||
pl | |||
end | |||
|
|||
def set_remote_console_url(url, user_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be renamed:
def remote_console_url=(url, user_id)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really? how would I call such method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I did. I don't know what magic happens here, a method with =
with more that one arg sounds strange, but w/o the names matching I was getting errors
45da3f4
to
8207958
Compare
8207958
to
c02e8ea
Compare
<github_pr_commenter_batch />Some comments on commits martinpovolny/manageiq@c9de5ff~...c02e8ea spec/controllers/application_controller/buttons_spec.rb
|
Checked commits martinpovolny/manageiq@c9de5ff~...c02e8ea with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1 |
Look goos, thanks. |
Euwe backport conflict:
$ git diff
diff --cc app/controllers/application_controller/buttons.rb
index cf250b6,54095da..0000000
--- a/app/controllers/application_controller/buttons.rb
+++ b/app/controllers/application_controller/buttons.rb
@@@ -264,12 -276,15 +276,19 @@@ module ApplicationController::Button
options[:target_id] = obj.id
options[:target_kls] = obj.class.name
dialog_initialize(button.resource_action, options)
+ elsif button.options && button.options.key?(:open_url) && button.options[:open_url]
+ task_id = button.invoke_async(obj)
+ initiate_wait_for_task(:task_id => task_id, :action => :custom_button_done)
else
begin
++<<<<<<< HEAD
+ button.invoke(obj) # Run the task
++=======
+ button.invoke(obj)
++>>>>>>> 6502d59... Merge pull request #10118 from martinpovolny/button_launch_url
rescue StandardError => bang
add_flash(_("Error executing: \"%{task_description}\" %{error_message}") %
- {:task_description => params[:desc], :error_message => bang.message}, :error) # Push msg and error flag
+ {:task_description => params[:desc], :error_message => bang.message}, :error)
else
add_flash(_("\"%{task_description}\" was executed") % {:task_description => params[:desc]})
end
|
@martinpovolny Please resolve conflict and make Euwe-specific PR (referencing this one) or suggest other PRs to backport. |
Backported to Euwe via #13449 |
https://bugzilla.redhat.com/show_bug.cgi?id=1399368
Purpose or Intent
Extension to custom buttons where:
SystemConsole
model).or even open a HTML5 VNC client to a provided websocket URL (not in this PR).A simple usecase is opening a custom web page that is not available immediately, but needs to be made ready by the automate script.
The greater idea is than an automate script would somehow build a chain of proxy servers for VNC connection and the ManageIQ UI would open a HTML5 VNC client that would connect through that tunnel.
Example usage from automate:
press the button.
FIXME (for a follow up PR?)
SystemConsole
we might need to do some cleanups (websocket proxy) or 2nd level proxy (Console proxy level 2 #11273). However it makes no sense to use the proxies together with this on a single VM so this is not a big issue.set_remote_console_url
method exposed to automate.