[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 19:48:21 UTC 2008
Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
ovirt-host-creator/common-post.ks | 16 +++---
ovirt-host-creator/identify.py | 102 ++++++++++++++++++++++++++++++++++
wui/src/host-browser/host-browser.rb | 17 +++--
3 files changed, 120 insertions(+), 15 deletions(-)
create mode 100755 ovirt-host-creator/identify.py
diff --git a/ovirt-host-creator/identify.py b/ovirt-host-creator/identify.py
new file mode 100755
index 0000000..664ed2d
--- /dev/null
+++ b/ovirt-host-creator/identify.py
@@ -0,0 +1,102 @@
+#!/usr/bin/python -Wall
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce at redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+import socket
+import libvirt
+import sys
+import os
+
+class IdentifyNode:
+ """This class allows the managed node to connect to the WUI host
+ and notify it that the node is awake and ready to participate."""
+
+ def __init__(self, server_name, server_port):
+ 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()
+ }
+
+ print(self.host_info)
+
+ self.server_name = server_name
+ self.server_port = int(server_port)
+
+ self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.socket.connect((self.server_name,self.server_port))
+ self.input = self.socket.makefile('rb', 0)
+ self.output = self.socket.makefile('wb', 0)
+
+ def start_conversation(self):
+ print("Connecting to server")
+
+ response = self.input.readline().strip()
+ if response == 'HELLO?':
+ self.output.write("HELLO!\n")
+ else:
+ raise TypeError, "Received invalid conversation starter: %s" % response
+
+ def send_host_info(self):
+ print("Starting information exchange...")
+
+ response = self.input.readline().strip()
+ if response == 'INFO?':
+ for name in self.host_info.keys():
+ self.send_host_info_element(name,self.host_info[name])
+ else:
+ raise TypeError, "Received invalid info marker: %s" % response
+
+ print("Ending information exchange...")
+ self.output.write("ENDINFO\n")
+ response = self.input.readline().strip()
+
+ if response[0:4] == 'KVNO':
+ self.keytab = response[:5]
+ else:
+ raise TypeError, "Did not receive a keytab response: '%s'" % response
+
+ def send_host_info_element(self,key,value):
+ print("Sending: " + key + "=" + value)
+ self.output.write(key + "=" + value + "\n")
+ response = self.input.readline().strip()
+
+ if response != "ACK " + key:
+ raise TypeError, "Received bad acknolwedgement for field: %s" % key
+
+ def get_keytab(self):
+ print("Retrieving keytab information: %s" % self.keytab)
+
+ def end_conversation(self):
+ print("Disconnecting from server")
+
+
+if __name__ == '__main__':
+
+ identifier = IdentifyNode(sys.argv[1], sys.argv[2])
+
+ identifier.start_conversation()
+ identifier.send_host_info()
+ identifier.get_keytab()
+ identifier.end_conversation()
diff --git a/wui/src/host-browser/host-browser.rb b/wui/src/host-browser/host-browser.rb
index 2aa74b4..9519e7b 100755
--- a/wui/src/host-browser/host-browser.rb
+++ b/wui/src/host-browser/host-browser.rb
@@ -131,7 +131,6 @@ class HostBrowser
raise Exception.new("ERROR! Malformed response : expected ACK, got #{response}") unless response == "ACK"
@session.write("BYE\n");
- @session.shutdown(2)
end
# Creates a keytab if one is needed, returning the filename.
@@ -174,13 +173,17 @@ end
def entry_point(server)
while(session = server.accept)
child = fork do
- puts "Connected to #{session.peeraddr[3]}"
-
- database_connect
-
+ remote = session.peeraddr[3]
+
+ puts "Connected to #{remote}"
+
begin
browser = HostBrowser.new(session)
+ # redirect output to the logsg
+ STDOUT.reopen browser.logfile, 'a'
+ STDERR.reopen STDOUT
+
browser.begin_conversation
host_info = browser.get_remote_info
browser.write_host_info(host_info)
@@ -191,9 +194,9 @@ def entry_point(server)
puts "ERROR #{error.message}"
end
- session.shutdown(2) unless session.closed?
+ # session.shutdown(2) unless session.closed?
- puts "Disconnected from #{session.peeraddr[3]}"
+ puts "Disconnected from #{remote}"
end
Process.detach(child)
--
1.5.5.1
More information about the ovirt-devel
mailing list