* [PATCH 0/3] Add support for XML-RPC over SSH
@ 2006-06-10 19:35 Anthony Liguori
2006-06-10 19:37 ` [PATCH 1/3] Add an xm serve command Anthony Liguori
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Anthony Liguori @ 2006-06-10 19:35 UTC (permalink / raw)
To: xen-devel; +Cc: Ewan Mellor
The following set of patches add support to Xend and xm for XML-RPC over
SSH. These patches are small and pretty self-contained so they
shouldn't hinder the introduction of XML-RPC over HTTPS. There are a
number of good reasons to support XML-RPC over SSH. It requires no
additional open ports simplifying firewall configuration. There's no
additional server configuration (or certificate creation). It also is
rather easy to support from a client perspective.
I've tested this series with xm-test and there are no new unexpected
failures[1]. The xm-test runs were done with both the httpu protocol
and the ssh protocol.
This series assumes the application of the XML-RPC Keep-Alive patch I
previously posted.
[1] One of the non-root tests unexpectedly passed since the user I was
running authenticated over ssh as root.
Regards,
Anthony Liguori
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] Add an xm serve command
2006-06-10 19:35 [PATCH 0/3] Add support for XML-RPC over SSH Anthony Liguori
@ 2006-06-10 19:37 ` Anthony Liguori
2006-06-10 19:38 ` [PATCH 2/3] Add SSH over XML-RPC support to xmlrpclib2.ServerProxy Anthony Liguori
2006-06-10 19:39 ` [PATCH 3/3] Let xm user choose XML-RPC URI Anthony Liguori
2 siblings, 0 replies; 4+ messages in thread
From: Anthony Liguori @ 2006-06-10 19:37 UTC (permalink / raw)
To: xen-devel, Ewan Mellor
[-- Attachment #1: Type: text/plain, Size: 90 bytes --]
This is the server-side support required for XML-RPC over SSH.
Regards,
Anthony Liguori
[-- Attachment #2: xm-serve.diff --]
[-- Type: text/plain, Size: 2556 bytes --]
# HG changeset patch
# User anthony@rhesis.austin.ibm.com
# Node ID cf8e253723daf8b95b54b24f6988a8e74c6cc0aa
# Parent a0212dab2954807a979058d91b246564a7bf2cc2
Add an xm serve command.
This command proxies the Xend XML-RPC over stdio. This is similiar to
mercurial's hg serve --stdio command.
The most obvious use of this command is remote XML-RPC invocation over SSH.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
diff -r a0212dab2954 -r cf8e253723da tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py Sat Jun 10 19:07:26 2006
+++ b/tools/python/xen/xm/main.py Sat Jun 10 19:11:55 2006
@@ -41,6 +41,7 @@
import xen.xend.XendClient
from xen.xend.XendClient import server
from xen.util import security
+from select import select
# getopt.gnu_getopt is better, but only exists in Python 2.3+. Use
# getopt.getopt if gnu_getopt is not available. This will mean that options
@@ -124,6 +125,7 @@
loadpolicy_help = "loadpolicy <policy> Load binary policy into hypervisor"
makepolicy_help = "makepolicy <policy> Build policy and create .bin/.map files"
labels_help = "labels [policy] [type=DOM|..] List <type> labels for (active) policy."
+serve_help = "serve Proxy Xend XML-RPC over stdio"
short_command_list = [
"console",
@@ -171,7 +173,8 @@
host_commands = [
"dmesg",
"info",
- "log"
+ "log",
+ "serve",
]
scheduler_commands = [
@@ -833,6 +836,32 @@
arg_check(args, "log", 0)
print server.xend.node.log()
+
+def xm_serve(args):
+ arg_check(args, "serve", 0)
+
+ from fcntl import fcntl, F_SETFL
+
+ s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ s.connect(xen.xend.XendClient.XML_RPC_SOCKET)
+ fcntl(sys.stdin, F_SETFL, os.O_NONBLOCK)
+
+ while True:
+ iwtd, owtd, ewtd = select([sys.stdin, s], [], [])
+ if s in iwtd:
+ data = s.recv(4096)
+ if len(data) > 0:
+ sys.stdout.write(data)
+ sys.stdout.flush()
+ else:
+ break
+ if sys.stdin in iwtd:
+ data = sys.stdin.read(4096)
+ if len(data) > 0:
+ s.sendall(data)
+ else:
+ break
+ s.close()
def parse_dev_info(info):
def get_info(n, t, d):
@@ -1072,6 +1101,7 @@
"dmesg": xm_dmesg,
"info": xm_info,
"log": xm_log,
+ "serve": xm_serve,
# scheduler
"sched-bvt": xm_sched_bvt,
"sched-bvt-ctxallow": xm_sched_bvt_ctxallow,
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/3] Add SSH over XML-RPC support to xmlrpclib2.ServerProxy
2006-06-10 19:35 [PATCH 0/3] Add support for XML-RPC over SSH Anthony Liguori
2006-06-10 19:37 ` [PATCH 1/3] Add an xm serve command Anthony Liguori
@ 2006-06-10 19:38 ` Anthony Liguori
2006-06-10 19:39 ` [PATCH 3/3] Let xm user choose XML-RPC URI Anthony Liguori
2 siblings, 0 replies; 4+ messages in thread
From: Anthony Liguori @ 2006-06-10 19:38 UTC (permalink / raw)
To: xen-devel; +Cc: Ewan Mellor
[-- Attachment #1: Type: text/plain, Size: 81 bytes --]
This is the client-side support for SSH over XML-RPC.
Regards,
Anthony Liguori
[-- Attachment #2: sshtransport.diff --]
[-- Type: text/plain, Size: 4195 bytes --]
# HG changeset patch
# User anthony@rhesis.austin.ibm.com
# Node ID 03bbc156d3e8fb01eee2af990176bb64e012c4e1
# Parent cf8e253723daf8b95b54b24f6988a8e74c6cc0aa
Add support to our ServerProxy class for XML-RPC over SSH.
This adds a new XML-RPC transport (SSHTransport) and a new supported
protocol to the ServerProxy class. This protocol is accessed with a URI of
the following form:
ssh://[user@]hostname[/path]
While xm makes too many assumptions about being on a local system for all
commands to work when a remote URI is used, many of the commands do work.
This is mostly useful to people who are using xmlrpclib2 to write Xen
management tools. It may prove more useful in the future to support
authenticated migration though.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
diff -r cf8e253723da -r 03bbc156d3e8 tools/python/xen/util/xmlrpclib2.py
--- a/tools/python/xen/util/xmlrpclib2.py Sat Jun 10 19:11:55 2006
+++ b/tools/python/xen/util/xmlrpclib2.py Sat Jun 10 19:16:33 2006
@@ -24,13 +24,51 @@
import types
from httplib import HTTPConnection, HTTP
-from xmlrpclib import Transport
+from xmlrpclib import Transport, getparser, Fault
from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
-import xmlrpclib, socket, os, stat
+from subprocess import Popen, PIPE
+from getpass import getuser
+from fcntl import ioctl
+import xmlrpclib, socket, os, stat, termios
import SocketServer
-import xen.xend.XendClient
from xen.xend.XendLogging import log
+
+class SSHTransport(object):
+ def __init__(self, host, user, askpass=None):
+ if askpass:
+ f = open('/dev/tty', 'w')
+ os.environ['SSH_ASKPASS'] = askpass
+ ioctl(f.fileno(), termios.TIOCNOTTY)
+ f.close()
+
+ self.ssh = Popen(['ssh', '%s@%s' % (user, host), 'xm serve'],
+ bufsize=0, stdin=PIPE, stdout=PIPE)
+
+ def request(self, host, handler, request_body, verbose=0):
+ p, u = getparser()
+ self.ssh.stdin.write("""POST /%s HTTP/1.1
+User-Agent: Xen
+Host: %s
+Content-Type: text/xml
+Content-Length: %d
+
+%s""" % (handler, host, len(request_body), request_body))
+ self.ssh.stdin.flush()
+
+ content_length = 0
+ line = self.ssh.stdout.readline()
+ if line.split()[1] != '200':
+ raise Fault(0, 'Server returned %s' % (' '.join(line[1:])))
+
+ while line not in ['', '\r\n', '\n']:
+ if line.lower().startswith('content-length:'):
+ content_length = int(line[15:].strip())
+ line = self.ssh.stdout.readline()
+ content = self.ssh.stdout.read(content_length)
+ p.feed(content)
+ p.close()
+ return u.close()
# A new ServerProxy that also supports httpu urls. An http URL comes in the
@@ -100,9 +138,22 @@
if protocol == 'httpu':
uri = 'http:' + rest
transport = UnixTransport()
+ elif protocol == 'ssh':
+ if not rest.startswith('//'):
+ raise ValueError("Invalid ssh URL '%s'" % uri)
+ rest = rest[2:]
+ user = getuser()
+ path = 'RPC2'
+ if rest.find('@') != -1:
+ (user, rest) = rest.split('@', 1)
+ if rest.find('/') != -1:
+ (host, rest) = rest.split('/', 1)
+ if len(rest) > 0:
+ path = rest
+ transport = SSHTransport(host, user)
+ uri = 'http://%s/%s' % (host, path)
xmlrpclib.ServerProxy.__init__(self, uri, transport, encoding,
verbose, allow_none)
-
def __request(self, methodname, params):
response = xmlrpclib.ServerProxy.__request(self, methodname, params)
@@ -150,6 +201,7 @@
except xmlrpclib.Fault, fault:
response = xmlrpclib.dumps(fault)
except Exception, exn:
+ import xen.xend.XendClient
log.exception(exn)
response = xmlrpclib.dumps(
xmlrpclib.Fault(xen.xend.XendClient.ERROR_INTERNAL, str(exn)))
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/3] Let xm user choose XML-RPC URI
2006-06-10 19:35 [PATCH 0/3] Add support for XML-RPC over SSH Anthony Liguori
2006-06-10 19:37 ` [PATCH 1/3] Add an xm serve command Anthony Liguori
2006-06-10 19:38 ` [PATCH 2/3] Add SSH over XML-RPC support to xmlrpclib2.ServerProxy Anthony Liguori
@ 2006-06-10 19:39 ` Anthony Liguori
2 siblings, 0 replies; 4+ messages in thread
From: Anthony Liguori @ 2006-06-10 19:39 UTC (permalink / raw)
To: xen-devel; +Cc: Ewan Mellor
[-- Attachment #1: Type: text/plain, Size: 137 bytes --]
This patch let's a user (via the XM_SERVER environment variable) choose
which XML-RPC URI is used within xm.
Regards,
Anthony Liguori
[-- Attachment #2: xm_server.diff --]
[-- Type: text/plain, Size: 1181 bytes --]
# HG changeset patch
# User anthony@rhesis.austin.ibm.com
# Node ID f8fcaee58fc1f7e13ae8443336a80de4c4e50538
# Parent 03bbc156d3e8fb01eee2af990176bb64e012c4e1
Use an environmental variable (XM_SERVER) to determine XML-RPC URI.
This allows users to invoke xm against a remote server. This is much more
useful though for exercising XML-RPC transports with xm-test though since
xm-test will continue to (mostly) function if the URI is localhost.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
diff -r 03bbc156d3e8 -r f8fcaee58fc1 tools/python/xen/xend/XendClient.py
--- a/tools/python/xen/xend/XendClient.py Sat Jun 10 19:16:33 2006
+++ b/tools/python/xen/xend/XendClient.py Sat Jun 10 19:19:02 2006
@@ -18,6 +18,7 @@
#============================================================================
from xen.util.xmlrpclib2 import ServerProxy
+import os
XML_RPC_SOCKET = "/var/run/xend/xmlrpc.sock"
@@ -25,4 +26,8 @@
ERROR_GENERIC = 2
ERROR_INVALID_DOMAIN = 3
-server = ServerProxy('httpu:///var/run/xend/xmlrpc.sock')
+uri = 'httpu:///var/run/xend/xmlrpc.sock'
+if os.environ.has_key('XM_SERVER'):
+ uri = os.environ['XM_SERVER']
+
+server = ServerProxy(uri)
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-06-10 19:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-10 19:35 [PATCH 0/3] Add support for XML-RPC over SSH Anthony Liguori
2006-06-10 19:37 ` [PATCH 1/3] Add an xm serve command Anthony Liguori
2006-06-10 19:38 ` [PATCH 2/3] Add SSH over XML-RPC support to xmlrpclib2.ServerProxy Anthony Liguori
2006-06-10 19:39 ` [PATCH 3/3] Let xm user choose XML-RPC URI Anthony Liguori
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.