[Ovirt-devel] [PATCH server] integrate anyterm into ovirt web interface
Jason Guiditta
jguiditt at redhat.com
Tue May 12 19:27:44 UTC 2009
ACK, one minor fix inline.
On Tue, 2009-05-12 at 15:05 -0400, Mohammed Morsi wrote:
> 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 | 6 ++++++
> ovirt-server.spec.in | 2 ++
> scripts/ovirt-vm2node | 26 ++++++++++++++++++++++++++
> src/app/controllers/vm_controller.rb | 9 +++++++++
> src/app/views/vm/show.rhtml | 27 ++++++++++++++++++++-------
> src/public/images/icon_machine_11px.png | Bin 0 -> 354 bytes
> src/public/javascripts/ovirt.js | 15 ++++++++++++++-
> 7 files changed, 77 insertions(+), 8 deletions(-)
> create mode 100755 scripts/ovirt-vm2node
> create mode 100644 src/public/images/icon_machine_11px.png
>
> diff --git a/conf/ovirt-server.conf b/conf/ovirt-server.conf
> index bab6f1a..36564ed 100644
> --- a/conf/ovirt-server.conf
> +++ b/conf/ovirt-server.conf
> @@ -21,6 +21,12 @@ NameVirtualHost AdminNetIpAddress:80
> TransferLog /etc/httpd/logs/access_log
> LogLevel warn
>
> + RewriteEngine On
> + RewriteMap vmnodes prg:/usr/bin/ovirt-vm2node
> + RewriteRule ^/terminal/(.*\.(js|css|gif)|proxy/anyterm-module)$ http://${vmnodes:anyterm}:81/$1 [P]
> + RewriteRule ^/terminal/(.*)$ http://${vmnodes:$1}:81/anyterm.html?param=$1 [P,NE]
> +
> +
> ProxyPass /ovirt http://AdminNodeFQDN/ovirt
> ProxyPassReverse /ovirt http://AdminNodeFQDN/ovirt
>
> diff --git a/ovirt-server.spec.in b/ovirt-server.spec.in
> index 6da7297..b4f7454 100644
> --- a/ovirt-server.spec.in
> +++ b/ovirt-server.spec.in
> @@ -130,6 +130,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
> @@ -199,6 +200,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..1d6104c
> --- /dev/null
> +++ b/scripts/ovirt-vm2node
> @@ -0,0 +1,26 @@
> +#!/usr/bin/ruby
> +
> +$: << '/usr/share/ovirt-server'
> +$: << '/usr/share/ovirt-server/dutils'
> +
> +require 'dutils'
> +
> +########################## retreive host from vm w/ specified name
> +$stdin.each{ |vmname| # get vm name from stdin
> + begin
> + 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, :conditions => "state = 'available'").hostname
> + else
> + puts Vm.find(:first, :conditions => ['description = ?', vmname]).host.hostname
> + end
> + rescue Exception => e
> + puts
> + end
> +
> + $stdout.flush
> +}
> diff --git a/src/app/controllers/vm_controller.rb b/src/app/controllers/vm_controller.rb
> index a40fc5c..e918ae7 100644
> --- a/src/app/controllers/vm_controller.rb
> +++ b/src/app/controllers/vm_controller.rb
> @@ -37,6 +37,15 @@ class VmController < ApplicationController
> end
> end
>
> + def terminal
> + # optionally add rows and columns params to url here
> + # eg ?param=vmname&rows=30&columns=100
> + @vm = Vm.find(params[:id])
> + redirect_to "https://" + params[:host] +
> + "/terminal/" + @vm.description +
> + "?param=" + @vm.description
> + end
> +
> def show
> svc_show(params[:id])
> @actions = @vm.get_action_hash(@user)
> diff --git a/src/app/views/vm/show.rhtml b/src/app/views/vm/show.rhtml
> index 0da81d0..c933281 100644
> --- a/src/app/views/vm/show.rhtml
> +++ b/src/app/views/vm/show.rhtml
> @@ -3,16 +3,29 @@
> <%- end -%>
>
> <%- content_for :action_links do -%>
> - <%if @can_control_vms and @vm.has_console -%>
> - <%= link_to image_tag("icon_x_11px.png") + " Open Console",
> - {:controller => 'vm', :action => 'console', :id => @vm},
> - :id=>"vnc_console_link" %>
> + <%if @can_control_vms -%>
> + <%if @vm.has_console -%>
> + <%= link_to image_tag("icon_machine_11px.png") + " Remote Desktop",
> + {: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'),'console','toolbar=no,height=300,width=400,resizable=no,status=no,scrollbars=no,menubar=no,location=no');
> + return false;})
> + </script>
> + <% end -%>
> +
> + <%= link_to image_tag("icon_machine_11px.png") + " Open Terminal",
This icon should be icon_terminal instead of _machine
> + {:controller => 'vm', :action => 'terminal', :id => @vm},
> + :id=> "vm_terminal_link"%>
> <script type="text/javascript">
> - $('#vnc_console_link').bind('click', function(){
> - window.open($(this).attr('href'),'console','toolbar=no,height=300,width=400,resizable=no,status=no,scrollbars=no,menubar=no,location=no');
> - return false;})
> + $('#vm_terminal_link').attr("href", $('#vm_terminal_link').attr("href") + "?host=" + get_server_from_url());
> + $('#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_modify -%>
> <%= link_to image_tag("icon_edit_11px.png") + " Edit",
> {:controller => 'vm', :action => 'edit', :id => @vm},
> diff --git a/src/public/images/icon_machine_11px.png b/src/public/images/icon_machine_11px.png
> new file mode 100644
> index 0000000000000000000000000000000000000000..bd4b6d3446ece6c856eadf4f15dfc503cd7693d6
> GIT binary patch
> literal 354
> zcmV-o0iFJdP)<h;3K|Lk000e1NJLTq000XB000XJ1^@s6sjPP<0000PbVXQnQ*UN;
> zcVTj606}DLVr3vnZDD6+Qe|Oed2z{QJOBUz1W80eRCwBqkv&cWF%X5{qRH-Fh>D6U
> zK(W*mk#YeVP5^8Uz^>@o0xm;C!xe%O|Ezyw#txJbu{0iQ=F^*JyGkkH)J6Sz{mglJ
> z9LZu;J`8y3`xN)_-^d)r5MZ4}cYAkKdwO|9V2+%3&`Ou$<;6MVJVQ!_9fuGaJ0US^
> z4euPtS_`EVVvN`d!H{N1La>08Gg8_^az9TeYZzt~&to><+k+y5O3yIHp<WR8B{ElF
> z&115skI%1i at AUf$XS{nKOW&{qGAy61JlwC)G))O2V#vd>&)l>2kckV!IF8E`{$!~B
> zez5Cq-a_zKZQG)*>!NCm;VFyvX?nfR%#Q#A01nsI^~{BAx&QzG07*qoM6N<$f=XzY
> A-v9sr
>
> literal 0
> HcmV?d00001
>
> diff --git a/src/public/javascripts/ovirt.js b/src/public/javascripts/ovirt.js
> index c24df16..2754817 100644
> --- a/src/public/javascripts/ovirt.js
> +++ b/src/public/javascripts/ovirt.js
> @@ -380,4 +380,17 @@ var VmCreator = {
> VmCreator.recreateTree(storedOptions);
> VmCreator.clickCheckboxes();
> }
> -}
> \ No newline at end of file
> +}
> +
> +function get_server_from_url()
> +{
> + var regexS = "https.*"
> + var regex = new RegExp(regexS);
> + var results = regex.exec( window.location.href );
> + var start = 8;
> + if(results == null){
> + start = 7;
> + }
> + var end = window.location.href.indexOf('/', 8) - start;
> + return window.location.href.substr(start, end);
> +}
More information about the ovirt-devel
mailing list