[Ovirt-devel] [PATCH] The server was rewritten in Ruby. The managed node side was rewritten in Python.
Darryl L. Pierce
dpierce at redhat.com
Tue Jun 3 21:37:55 UTC 2008
Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
ovirt-host-creator/identify.py | 21 ++++-----
wui/src/host-browser/host-browser.rb | 66 ++++++++++++++---------------
wui/src/host-browser/test-host-browser.rb | 32 ++++----------
3 files changed, 50 insertions(+), 69 deletions(-)
diff --git a/ovirt-host-creator/identify.py b/ovirt-host-creator/identify.py
index 664ed2d..d20b607 100755
--- a/ovirt-host-creator/identify.py
+++ b/ovirt-host-creator/identify.py
@@ -1,5 +1,5 @@
#!/usr/bin/python -Wall
-#
+#
# Copyright (C) 2008 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce at redhat.com>
#
@@ -31,16 +31,15 @@ class IdentifyNode:
conn = libvirt.openReadOnly(None)
info = conn.getInfo()
self.host_info = {
- "UUID" : "foo",
- "ARCH" : info[0],
- "MEMSIZE" : "%d" % info[1],
- "NUMCPUS" : "%d" % info[2],
- "CPUSPEED" : "%d" % info[3],
- "HOSTNAME" : conn.getHostname()
+ "UUID" : "bar",
+ "ARCH" : info[0],
+ "MEMSIZE" : "%d" % info[1],
+ "NUMCPUS" : "%d" % info[2],
+ "CPUSPEED" : "%d" % info[3],
+ "HOSTNAME" : conn.getHostname(),
+ "HYPERVISOR_TYPE" : conn.getType()
}
- print(self.host_info)
-
self.server_name = server_name
self.server_port = int(server_port)
@@ -92,8 +91,8 @@ class IdentifyNode:
print("Disconnecting from server")
-if __name__ == '__main__':
-
+if __name__ == '__main__':
+
identifier = IdentifyNode(sys.argv[1], sys.argv[2])
identifier.start_conversation()
diff --git a/wui/src/host-browser/host-browser.rb b/wui/src/host-browser/host-browser.rb
index 9519e7b..6eef6f4 100755
--- a/wui/src/host-browser/host-browser.rb
+++ b/wui/src/host-browser/host-browser.rb
@@ -1,5 +1,5 @@
#!/usr/bin/ruby -Wall
-#
+#
# Copyright (C) 2008 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce at redhat.com>
#
@@ -41,7 +41,7 @@ class HostBrowser
attr_accessor :logfile
attr_accessor :keytab_dir
attr_accessor :keytab_filename
-
+
def initialize(session)
@session = session
@log_prefix = "[#{session.peeraddr[3]}] "
@@ -78,7 +78,7 @@ class HostBrowser
puts "#{@log_prefix} ::Received - #{key}:#{value}"
result[key] = value
-
+
@session.write("ACK #{key}\n")
end
@@ -101,21 +101,29 @@ class HostBrowser
if host == nil
begin
puts "Creating a new record for #{host_info['HOSTNAME']}..."
-
+
Host.new(
- "uuid" => host_info['UUID'],
- "hostname" => host_info['HOSTNAME'],
- "num_cpus" => host_info['NUMCPUS'],
- "cpu_speed" => host_info['CPUSPEED'],
- "arch" => host_info['ARCH'],
- "memory" => host_info['MEMSIZE'],
- "is_disabled" => 0,
- "hardware_pool" => HardwarePool.get_default_pool).save
+ "uuid" => host_info['UUID'],
+ "hostname" => host_info['HOSTNAME'],
+ "hypervisor_type" => host_info['HYPERVISOR_TYPE'],
+ "num_cpus" => host_info['NUMCPUS'],
+ "cpu_speed" => host_info['CPUSPEED'],
+ "arch" => host_info['ARCH'],
+ "memory" => host_info['MEMSIZE'],
+ "is_disabled" => 0,
+ "hardware_pool" => HardwarePool.get_default_pool).save
rescue Exception => error
puts "Error while creating record: #{error.message}"
end
+ else
+ host.uuid = host_info['UUID']
+ host.hostname = host_info['HOSTNAME']
+ host.num_cpus = host_info['NUMCPUS']
+ host.cpu_speed = host_info['CPUSPEED']
+ host.arch = host_info['ARCH']
+ host.memory = host_info['MEMSIZE']
end
-
+
return host
end
@@ -132,12 +140,12 @@ class HostBrowser
@session.write("BYE\n");
end
-
+
# Creates a keytab if one is needed, returning the filename.
#
def create_keytab(host_info, krb5_arg = nil)
krb5 = krb5_arg || Krb5.new
-
+
default_realm = krb5.get_default_realm
libvirt_princ = 'libvirt/' + host_info['HOSTNAME'] + '@' + default_realm
outfile = host_info['IPADDR'] + '-libvirt.tab'
@@ -174,9 +182,11 @@ def entry_point(server)
while(session = server.accept)
child = fork do
remote = session.peeraddr[3]
-
+
puts "Connected to #{remote}"
-
+
+ database_connect
+
begin
browser = HostBrowser.new(session)
@@ -193,28 +203,16 @@ def entry_point(server)
session.write("ERROR #{error.message}\n")
puts "ERROR #{error.message}"
end
-
- # session.shutdown(2) unless session.closed?
puts "Disconnected from #{remote}"
end
-
- Process.detach(child)
- end
+
+ Process.detach(child)
+ end
end
unless defined?(TESTING)
server = TCPServer.new("",12120)
-
- # The main entry point.
- #
- unless ARGV[0] == "-n"
- daemonize
- STDOUT.reopen browser.logfile, 'a'
- STDERR.reopen STDOUT
-
- entry_point(server)
- else
- entry_point(server)
- end
+
+ entry_point(server)
end
diff --git a/wui/src/host-browser/test-host-browser.rb b/wui/src/host-browser/test-host-browser.rb
index 2a05181..b5a616d 100755
--- a/wui/src/host-browser/test-host-browser.rb
+++ b/wui/src/host-browser/test-host-browser.rb
@@ -1,5 +1,5 @@
#!/usr/bin/ruby -Wall
-#
+#
# Copyright (C) 2008 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce at redhat.com>
#
@@ -26,7 +26,7 @@ TESTING=true
require 'host-browser'
-class TestHostBrowser < Test::Unit::TestCase
+class TestHostBrowser < Test::Unit::TestCase
def setup
@session = flexmock('session')
@@ -50,7 +50,7 @@ class TestHostBrowser < Test::Unit::TestCase
@host_info['DISABLED'] = '0'
end
- # Ensures that the server raises an exception when it receives an
+ # Ensures that the server raises an exception when it receives an
# improper handshake response.
#
def test_begin_conversation_with_improper_response_to_greeting
@@ -87,7 +87,7 @@ class TestHostBrowser < Test::Unit::TestCase
def test_get_info_with_missing_key
@session.should_receive(:write).with("INFO?\n").once().returns { |request| request.length }
@session.should_receive(:readline).once().returns { "=value1\n" }
-
+
assert_raise(Exception) { @browser.get_remote_info }
end
@@ -129,7 +129,7 @@ class TestHostBrowser < Test::Unit::TestCase
assert info.include?("IPADDR")
assert info.include?("key1")
assert info.include?("key2")
- end
+ end
# Ensures the host browser generates a keytab as expected.
#
@@ -154,7 +154,7 @@ class TestHostBrowser < Test::Unit::TestCase
#
def test_write_host_info_with_missing_hostname
@host_info['HOSTNAME'] = nil
-
+
assert_raise(Exception) { @browser.write_host_info(@host_info) }
end
@@ -190,31 +190,15 @@ class TestHostBrowser < Test::Unit::TestCase
assert_raise(Exception) { @browser.write_host_info(@host_info) }
end
- # Ensures that the host information is properly moved to a persisted object
- # and saved.
- #
- def test_write_host_info
- result = @browser.write_host_info(@host_info)
-
- assert result, "No persisted object returned"
- assert_match @host_info['UUID'], result.uuid, "UUID was not persisted"
- assert_match @host_info['HOSTNAME'], result.hostname, "Hostname was not persisted"
- assert_match @host_info['NUMCPUS'], "#{result.num_cpus}", "Number of CPUs was not persisted"
- assert_match @host_info['CPUSPEED'], "#{result.cpu_speed}", "CPU speed was not persisted"
- assert_match @host_info['ARCH'], "#{result.arch}", "Architecture was not persisted"
- assert_match @host_info['MEMSIZE'], "#{result.memory}", "Memory size was not persisted"
- end
-
- # Ensures that, if a keytab is present and a key version number available,
+ # Ensures that, if a keytab is present and a key version number available,
# the server ends the conversation by returning the key version number.
#
def test_end_conversation
@session.should_receive(:write).with("KVNO 12345\n").once().returns { |request| request.length }
@session.should_receive(:readline).once().returns { "ACK\n" }
@session.should_receive(:write).with("BYE\n").once().returns { |request| request.length }
- @session.should_receive(:shutdown).with(2).once()
assert_nothing_raised(Exception) { @browser.end_conversation(12345) }
end
-end
+end
--
1.5.5.1
More information about the ovirt-devel
mailing list