Mohammed Morsi
2009-May-12 17:25 UTC
[Ovirt-devel] [PATCH server] integration anyterm into ovirt web interface
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 | 8 ++++++++
src/app/views/vm/show.rhtml | 28 ++++++++++++++++++++--------
src/public/javascripts/ovirt.js | 15 ++++++++++++++-
6 files changed, 76 insertions(+), 9 deletions(-)
create mode 100755 scripts/ovirt-vm2node
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..10d841a 100644
--- a/src/app/controllers/vm_controller.rb
+++ b/src/app/controllers/vm_controller.rb
@@ -37,6 +37,14 @@ class VmController < ApplicationController
end
end
+ def terminal
+ # optionally add rows and columns params to url here
+ # eg ?param=vmname&rows=30&columns=100
+ 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..52961c5 100644
--- a/src/app/views/vm/show.rhtml
+++ b/src/app/views/vm/show.rhtml
@@ -2,17 +2,29 @@
<%=h @vm.description %>
<%- 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_x_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_x_11px.png") + " Open
Terminal",
+ {: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/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);
+}
--
1.6.0.6
Mohammed Morsi
2009-May-12 17:25 UTC
[Ovirt-devel] [PATCH node] add anyterm to node requirements and setup on startup
adds anyterm rpm dependency to ovirt node spec and sets up
anyterm on node instantation by setting the service to
start by default and making the necessary anyterm
sysconfig changes
---
ovirt-node.spec.in | 1 +
scripts/ovirt-functions | 12 ++++++++++++
scripts/ovirt-install-node-stateful | 2 ++
scripts/ovirt-install-node-stateless | 2 ++
4 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in
index 1a73066..1b847c5 100644
--- a/ovirt-node.spec.in
+++ b/ovirt-node.spec.in
@@ -42,6 +42,7 @@ Requires: qemu-img
Requires: nc
Requires: grub
Requires: /usr/sbin/crond
+Requires: anyterm
ExclusiveArch: %{ix86} x86_64
%define app_root %{_datadir}/%{name}
diff --git a/scripts/ovirt-functions b/scripts/ovirt-functions
index e89898d..4d81193 100755
--- a/scripts/ovirt-functions
+++ b/scripts/ovirt-functions
@@ -201,6 +201,18 @@ ovirt_setup_libvirtd() {
fi
}
+ovirt_setup_anyterm() {
+ # configure anyterm
+ sed -i -e 's/^#
ANYTERM_CMD=\/usr\/bin\/anyterm-cmd/ANYTERM_CMD="sudo \/usr\/bin\/virsh
console %p"/' \
+ /etc/sysconfig/anyterm
+
+ sed -i -e 's/^# ANYTERM_LOCAL_ONLY=true/ANYTERM_LOCAL_ONLY=false/' \
+ /etc/sysconfig/anyterm
+
+ # permit it to run the virsh console
+ echo "anyterm ALL=NOPASSWD: /usr/bin/virsh console *" >>
/etc/sudoers
+}
+
md5() {
md5sum $1 2>/dev/null | (read MD5 filename; echo $MD5)
}
diff --git a/scripts/ovirt-install-node-stateful
b/scripts/ovirt-install-node-stateful
index 3ec1c29..9426c81 100755
--- a/scripts/ovirt-install-node-stateful
+++ b/scripts/ovirt-install-node-stateful
@@ -75,6 +75,7 @@ chkconfig libvirt-qpid on
chkconfig iptables on
chkconfig ntpdate on
chkconfig ntpd on
+chkconfig anyterm on
backup_file /etc/sysconfig/libvirtd
backup_file /etc/libvirt/qemu.conf
@@ -82,6 +83,7 @@ backup_file /etc/libvirt/libvirtd.conf
backup_file /etc/sasl2/libvirt.conf
backup_file /etc/krb5.conf
ovirt_setup_libvirtd
+ovirt_setup_anyterm
backup_file /etc/sysconfig/iptables
# We open up anything coming from ovirtbr0 to this node, since it
diff --git a/scripts/ovirt-install-node-stateless
b/scripts/ovirt-install-node-stateless
index 705c491..cceb048 100755
--- a/scripts/ovirt-install-node-stateless
+++ b/scripts/ovirt-install-node-stateless
@@ -20,8 +20,10 @@ chkconfig --level 3 ovirt-early on
chkconfig --level 3 ovirt on
chkconfig --level 3 ovirt-post on
chkconfig --level 3 collectd on
+chkconfig --level 3 anyterm on
ovirt_setup_libvirtd
+ovirt_setup_anyterm
# make sure we don't autostart virbr0 on libvirtd startup
rm -f /etc/libvirt/qemu/networks/autostart/default.xml
--
1.6.0.6