[Ovirt-devel] [PATCH] console plugin integration, first pass.
Hugh O. Brock
hbrock at redhat.com
Thu Jun 12 19:37:59 UTC 2008
On Thu, Jun 12, 2008 at 01:14:10PM -0400, Scott Seago wrote:
> I added a new attribute to vms, vnc_port that needs to be filled in by taskomatic when starting/resuming VMs. If vnc_port (and host) are set for a VM, an 'open console' link appears in the VM details pane which brings up a (currently 800x600) popup window for the VM console (using the x-gtk-vnc plugin).
>
> For this to actually work, we need the following:
> 1) taskomatic changes to fill in vnc_port on start (and null it out when setting state to stopped, etc)
> 2) x-gtk-vnc firefox plugin needs to be installed on whatever box you're using to browse
>
> EDIT: also make sure VM is running before producing console link.
> EDIT 2: pull out "has console" test into model so that the controller can also verify in the console handler
>
> Signed-off-by: Scott Seago <sseago at redhat.com>
> ---
> wui/src/app/controllers/vm_controller.rb | 8 +++++++-
> wui/src/app/models/vm.rb | 4 ++++
> wui/src/app/views/vm/show.rhtml | 10 ++++++++++
> wui/src/db/migrate/006_create_vms.rb | 1 +
> wui/src/public/stylesheets/layout.css | 8 +++++++-
> 5 files changed, 29 insertions(+), 2 deletions(-)
>
> diff --git a/wui/src/app/controllers/vm_controller.rb b/wui/src/app/controllers/vm_controller.rb
> index 1179196..c12686a 100644
> --- a/wui/src/app/controllers/vm_controller.rb
> +++ b/wui/src/app/controllers/vm_controller.rb
> @@ -22,7 +22,7 @@ class VmController < ApplicationController
> verify :method => :post, :only => [ :destroy, :create, :update ],
> :redirect_to => { :controller => 'dashboard' }
>
> - before_filter :pre_vm_action, :only => [:vm_action, :cancel_queued_tasks]
> + before_filter :pre_vm_action, :only => [:vm_action, :cancel_queued_tasks, :console]
>
> def show
> set_perms(@perm_obj)
> @@ -171,6 +171,12 @@ class VmController < ApplicationController
> end
> end
>
> +
> + def console
> + @show_vnc_error = "Console is unavailable for VM #{@vm.description}" unless @vm.has_console
> + render :layout => false
> + end
> +
> protected
> def pre_new
> # if no vm_resource_pool is passed in, find (or auto-create) it based on hardware_pool_id
> diff --git a/wui/src/app/models/vm.rb b/wui/src/app/models/vm.rb
> index 3e12d55..ae4e8ff 100644
> --- a/wui/src/app/models/vm.rb
> +++ b/wui/src/app/models/vm.rb
> @@ -180,6 +180,10 @@ class Vm < ActiveRecord::Base
> return true
> end
>
> + def has_console
> + (state == Vm::STATE_RUNNING ) and host and vnc_port
> + end
> +
> protected
> def validate
> resources = vm_resource_pool.max_resources_for_vm(self)
> diff --git a/wui/src/app/views/vm/show.rhtml b/wui/src/app/views/vm/show.rhtml
> index 457e11a..d185dbd 100644
> --- a/wui/src/app/views/vm/show.rhtml
> +++ b/wui/src/app/views/vm/show.rhtml
> @@ -3,6 +3,16 @@
> <%- end -%>
>
> <%- content_for :action_links do -%>
> + <%if @can_control_vms and @vm.has_console -%>
> + <%= link_to image_tag("icon_x.png") + " Open Console",
> + {:controller => 'vm', :action => 'console', :id => @vm},
> + :id=>"vnc_console_link" %>
> + <script type="text/javascript">
> + $('#vnc_console_link').bind('click', function(){
> + window.open($(this).attr('href'),'child','toolbar=no,height=600,width=800, resizable=yes,status=no');
> + return false;})
> + </script>
> + <% end -%>
> <%if @can_modify -%>
> <%= link_to image_tag("icon_edit.png") + " Edit",
> {:controller => 'vm', :action => 'edit', :id => @vm},
> diff --git a/wui/src/db/migrate/006_create_vms.rb b/wui/src/db/migrate/006_create_vms.rb
> index 7035a3c..74794b6 100644
> --- a/wui/src/db/migrate/006_create_vms.rb
> +++ b/wui/src/db/migrate/006_create_vms.rb
> @@ -32,6 +32,7 @@ class CreateVms < ActiveRecord::Migration
> t.integer :vm_resource_pool_id
> t.integer :needs_restart
> t.string :boot_device, :null => false
> + t.integer :vnc_port
> t.integer :lock_version, :default => 0
> end
> execute "alter table vms add constraint fk_vms_hosts
> diff --git a/wui/src/public/stylesheets/layout.css b/wui/src/public/stylesheets/layout.css
> index ab01b5f..52151eb 100644
> --- a/wui/src/public/stylesheets/layout.css
> +++ b/wui/src/public/stylesheets/layout.css
> @@ -376,7 +376,13 @@ a { color:#000000; text-decoration: none;}
> }
>
> .dialog_body {
> - overflow: scroll;
> + overflow: auto;
> + height: 350px;
> +}
> +
> +.popup_body {
> + background: #FFFFFF;
> + overflow: auto;
> height: 350px;
> }
ACK
although this is not fully testable until the taskomatic patch is in,
it will not break anything as it is.
--Hugh
More information about the ovirt-devel
mailing list