[Ovirt-devel] [PATCH server] integration anyterm into ovirt web interface

Mohammed Morsi mmorsi at redhat.com
Fri Mar 20 16:55:38 UTC 2009


this patch adds the necessary components to forward
vm web terminal requests from the local apache server to the
node which the vm is running on (httpd configuration and
vm2node lookup scripts) as well as changes to the wui to
allow users to access this functionality
---
 conf/ovirt-server.conf               |   11 ++++++++++
 ovirt-server.spec.in                 |    2 +
 scripts/ovirt-vm2node                |   35 ++++++++++++++++++++++++++++++++++
 src/app/controllers/vm_controller.rb |   10 ++++++++-
 src/app/views/vm/show.rhtml          |   11 ++++++++++
 5 files changed, 68 insertions(+), 1 deletions(-)
 create mode 100755 scripts/ovirt-vm2node

diff --git a/conf/ovirt-server.conf b/conf/ovirt-server.conf
index bab6f1a..57e4841 100644
--- a/conf/ovirt-server.conf
+++ b/conf/ovirt-server.conf
@@ -4,6 +4,17 @@ NameVirtualHost GuestNetIpAddress:80
     RewriteEngine on
     RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
   </Location>
+
+  # FIXME add to secure section
+  #  (currently doing so causes problems as the
+  #   secure request is forwarded to anyterm)
+  #  (supposidly anyterm can handle ssl but needs
+  #   to be configured to do so)
+  RewriteEngine On
+  RewriteMap vmnodes prg:/usr/bin/ovirt-vm2node
+  RewriteRule ^/terminal/(.*\.(js|css|gif)|anyterm-module)$ http://${vmnodes:anyterm}:8080/$1 [P]
+  RewriteRule ^/terminal/(.*)$ http://${vmnodes:$1}:8080/anyterm.html?param=$1 [P,NE]
+
 </VirtualHost>
 
 NameVirtualHost GuestNetIpAddress:443
diff --git a/ovirt-server.spec.in b/ovirt-server.spec.in
index eeefd65..7e4aa21 100644
--- a/ovirt-server.spec.in
+++ b/ovirt-server.spec.in
@@ -128,6 +128,7 @@ touch %{buildroot}%{_localstatedir}/log/%{name}/db-omatic.log
 %{__rm} -f %{buildroot}%{app_root}/task-omatic/.gitignore
 
 %{__cp} -a %{pbuild}/scripts/ovirt-add-host %{buildroot}%{_bindir}
+%{__cp} -a %{pbuild}/scripts/ovirt-vm2node %{buildroot}%{_bindir}
 %{__cp} -a %{pbuild}/scripts/ovirt-reindex-search %{buildroot}%{_sbindir}
 %{__cp} -a %{pbuild}/scripts/ovirt-update-search %{buildroot}%{_sbindir}
 %{__rm} -rf %{buildroot}%{app_root}/tmp
@@ -197,6 +198,7 @@ fi
 %{_sbindir}/ovirt-reindex-search
 %{_sbindir}/ovirt-update-search
 %{_bindir}/ovirt-add-host
+%{_bindir}/ovirt-vm2node
 %{_initrddir}/ovirt-host-browser
 %{_initrddir}/ovirt-db-omatic
 %{_initrddir}/ovirt-host-collect
diff --git a/scripts/ovirt-vm2node b/scripts/ovirt-vm2node
new file mode 100755
index 0000000..04c2872
--- /dev/null
+++ b/scripts/ovirt-vm2node
@@ -0,0 +1,35 @@
+#!/usr/bin/ruby
+
+############################ Initialize active record
+require 'rubygems'
+require 'active_record'
+require 'yaml'
+
+dbconfig = YAML::load(File.open('/usr/share/ovirt-server/config/database.yml'))
+ActiveRecord::Base.establish_connection(dbconfig['production'])
+
+
+########################### Initlialize vm / host classes
+class Host < ActiveRecord::Base
+  has_many :vms
+end
+
+class Vm < ActiveRecord::Base
+  belongs_to :host
+end
+
+########################## retreive host from vm w/ specified name
+$stdin.each{ |vmname| # get vm name from stdin
+  vmname.chomp!  # remove the newline
+
+  # specially handle 'anyterm' to just return
+  # first host (for css/js/etc which aren't
+  # vm dependent)
+  if vmname == 'anyterm'
+    puts Host.find(:first).hostname
+  else
+    puts Vm.find(:first, :conditions => ['description = ?', vmname]).host.hostname
+  end
+
+  $stdout.flush
+}
diff --git a/src/app/controllers/vm_controller.rb b/src/app/controllers/vm_controller.rb
index aa575c6..076033a 100644
--- a/src/app/controllers/vm_controller.rb
+++ b/src/app/controllers/vm_controller.rb
@@ -23,7 +23,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, :console]
+  before_filter :pre_vm_action, :only => [:vm_action, :cancel_queued_tasks, :console, :terminal]
 
   def index
       roles = "('" +
@@ -249,6 +249,14 @@ class VmController < ApplicationController
     render :layout => false
   end
 
+  def terminal
+    # optionally add rows and columns params to url here
+    # eg ?param=vmname&rows=30&columns=100
+    redirect_to "http://" + request.host +
+                "/terminal/" + @vm.description +
+                "?param=" + @vm.description
+  end
+
   protected
   def _setup_provisioning_options
     @provisioning_options = [[Vm::PXE_OPTION_LABEL, Vm::PXE_OPTION_VALUE],
diff --git a/src/app/views/vm/show.rhtml b/src/app/views/vm/show.rhtml
index add29b4..07698ab 100644
--- a/src/app/views/vm/show.rhtml
+++ b/src/app/views/vm/show.rhtml
@@ -3,6 +3,17 @@
 <%- end -%>
 
 <%- content_for :action_links do -%>
+  <%if @can_control_vms -%>
+    <%= link_to image_tag("icon_x.png") + " Open Terminal",
+                         {:controller => 'vm', :action => 'terminal', :id => @vm},
+                         :id=> "vm_terminal_link"%>
+    <script type="text/javascript">
+     $('#vm_terminal_link').bind('click', function(){
+        window.open($(this).attr('href'),'console','toolbar=no,height=450,width=600,resizable=no,status=no,scrollbars=no,menubar=no,location=no');
+        return false;})
+    </script>
+  <% end -%>
+
   <%if @can_control_vms and @vm.has_console -%>
     <%= link_to image_tag("icon_x.png") + " Open Console",
                           {:controller => 'vm', :action => 'console', :id => @vm},
-- 
1.6.0.6




More information about the ovirt-devel mailing list