[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Add support for unix-domain sockets on xend.



ChangeSet 1.1327.2.9, 2005/04/27 15:04:44+01:00, mjw@xxxxxxxxxxxxxxxxxxx

        Add support for unix-domain sockets on xend.
        Remove some dead code.
        Signed-off-by: Mike Wray <mike.wray@xxxxxx>



 b/tools/python/xen/web/SrvBase.py              |    1 
 b/tools/python/xen/web/SrvDir.py               |    2 
 b/tools/python/xen/web/httpserver.py           |   37 ++-
 b/tools/python/xen/web/static.py               |    3 
 b/tools/python/xen/xend/XendClient.py          |  127 ++++---------
 b/tools/python/xen/xend/XendDomain.py          |   36 ---
 b/tools/python/xen/xend/XendProtocol.py        |   40 +++-
 b/tools/python/xen/xend/XendRoot.py            |   52 ++++-
 b/tools/python/xen/xend/server/SrvConsole.py   |    2 
 b/tools/python/xen/xend/server/SrvDaemon.py    |    4 
 b/tools/python/xen/xend/server/SrvDmesg.py     |    2 
 b/tools/python/xen/xend/server/SrvDomain.py    |   64 ++----
 b/tools/python/xen/xend/server/SrvDomainDir.py |    2 
 b/tools/python/xen/xend/server/SrvNode.py      |    2 
 b/tools/python/xen/xend/server/SrvRoot.py      |    3 
 b/tools/python/xen/xend/server/SrvServer.py    |   41 ++--
 b/tools/python/xen/xend/server/SrvVnetDir.py   |    2 
 b/tools/python/xen/xend/server/SrvXendLog.py   |    2 
 b/tools/python/xen/xend/server/blkif.py        |    4 
 b/tools/python/xen/xend/server/channel.py      |   50 +++--
 b/tools/python/xen/xend/server/console.py      |    4 
 b/tools/python/xen/xend/server/controller.py   |  138 +++++++-------
 b/tools/python/xen/xend/server/netif.py        |    4 
 b/tools/python/xen/xend/server/usbif.py        |    4 
 tools/python/xen/web/defer.py                  |    3 
 tools/python/xen/xend/XendAsynchProtocol.py    |   94 ---------
 tools/python/xen/xend/XendDomainConfig.py      |   44 ----
 tools/python/xen/xend/server/SrvBase.py        |    2 
 tools/python/xen/xend/server/SrvDir.py         |    3 
 tools/python/xen/xend/server/SrvEventDir.py    |   41 ----
 tools/python/xen/xend/server/SrvUsbif.py       |  239 -------------------------
 31 files changed, 337 insertions(+), 715 deletions(-)


diff -Nru a/tools/python/xen/web/SrvBase.py b/tools/python/xen/web/SrvBase.py
--- a/tools/python/xen/web/SrvBase.py   2005-05-13 16:04:21 -04:00
+++ b/tools/python/xen/web/SrvBase.py   2005-05-13 16:04:21 -04:00
@@ -12,7 +12,6 @@
 import resource
 import http
 import httpserver
-import defer
 
 def uri_pathlist(p):
     """Split a path into a list.
diff -Nru a/tools/python/xen/web/SrvDir.py b/tools/python/xen/web/SrvDir.py
--- a/tools/python/xen/web/SrvDir.py    2005-05-13 16:04:22 -04:00
+++ b/tools/python/xen/web/SrvDir.py    2005-05-13 16:04:22 -04:00
@@ -20,7 +20,7 @@
 
     def __init__(self, klass):
         """Create a constructor. It is assumed that the class
-        should be imported as 'import klass from klass'.
+        should be imported as 'from xen.xend.server.klass import klass'.
 
         klass  name of its class
         """
diff -Nru a/tools/python/xen/web/defer.py b/tools/python/xen/web/defer.py
--- a/tools/python/xen/web/defer.py     2005-05-13 16:04:22 -04:00
+++ /dev/null   Wed Dec 31 16:00:00 196900
@@ -1,3 +0,0 @@
-
-class Deferred:
-    pass
diff -Nru a/tools/python/xen/web/httpserver.py 
b/tools/python/xen/web/httpserver.py
--- a/tools/python/xen/web/httpserver.py        2005-05-13 16:04:21 -04:00
+++ b/tools/python/xen/web/httpserver.py        2005-05-13 16:04:21 -04:00
@@ -4,6 +4,8 @@
 import socket
 import types
 from urllib import quote, unquote
+import os
+import os.path
 
 from xen.xend import sxp
 from xen.xend.Args import ArgError
@@ -184,7 +186,9 @@
 
         @param val: the value
         """
-        if isinstance(val, ThreadRequest):
+        if val is None:
+            return val
+        elif isinstance(val, ThreadRequest):
             return val
         elif self.useSxp():
             self.setHeader("Content-Type", sxp.mime_type)
@@ -316,18 +320,23 @@
     def getResource(self, req):
         return self.root.getRequestResource(req)
 
+class UnixHttpServer(HttpServer):
 
-def main():
-    root = SrvDir()
-    a = root.add("a", SrvDir())
-    b = root.add("b", SrvDir())
-    server = HttpServer(root=root)
-    server.run()
-
-if __name__ == "__main__":
-    main()
-        
-        
+    def __init__(self, path=None, root=None):
+        HttpServer.__init__(self, interface='localhost', root=root)
+        self.path = path
         
-            
-
+    def bind(self):
+        pathdir = os.path.dirname(self.path)
+        if not os.path.exists(pathdir):
+            os.makedirs(pathdir)
+        else:
+            try:
+                os.unlink(self.path)
+            except SystemExit:
+                raise
+            except Exception, ex:
+                pass
+        self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+        #self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+        self.socket.bind(self.path)
diff -Nru a/tools/python/xen/web/static.py b/tools/python/xen/web/static.py
--- a/tools/python/xen/web/static.py    2005-05-13 16:04:21 -04:00
+++ b/tools/python/xen/web/static.py    2005-05-13 16:04:21 -04:00
@@ -24,7 +24,7 @@
         if self.type:
             req.setHeader('Content-Type', self.type)
         if self.encoding:
-            rew.setHeader('Content-Encoding', self.encoding)
+            req.setHeader('Content-Encoding', self.encoding)
         req.setHeader('Content-Length', self.getFileSize())
         try:
             io = file(self.filename, "r")
@@ -40,7 +40,6 @@
                 io.close()
         except:
             pass
-        return ''
         
 
         
diff -Nru a/tools/python/xen/xend/XendAsynchProtocol.py 
b/tools/python/xen/xend/XendAsynchProtocol.py
--- a/tools/python/xen/xend/XendAsynchProtocol.py       2005-05-13 16:04:22 
-04:00
+++ /dev/null   Wed Dec 31 16:00:00 196900
@@ -1,94 +0,0 @@
-# Copyright (C) 2004 Mike Wray <mike.wray@xxxxxx>
-
-from twisted.protocols import http
-from twisted.internet.protocol import ClientCreator
-from twisted.internet.defer import Deferred
-from twisted.internet import reactor
-
-from XendProtocol import XendClientProtocol, XendRequest
-
-class AsynchXendClient(http.HTTPClient):
-    """A subclass of twisted's HTTPClient to deal with a connection to xend.
-    Makes the request when connected, and delegates handling responses etc.
-    to its protocol (usually an AsynchXendClientProtocol instance).
-    """
-    def __init__(self, protocol, request):
-        self.protocol = protocol
-        self.request = request
-
-    def connectionMade(self):
-        request = self.request
-        url = self.request.url
-        self.sendCommand(request.method, url.fullpath())
-        self.sendHeader('Host', url.location())
-        for (k, v) in request.headers.items():
-            self.sendHeader(k, v)
-        if request.data:
-            self.sendHeader('Content-Length', len(request.data))
-        self.endHeaders()
-        if request.data:
-            self.transport.write(request.data)
-
-    def handleStatus(self, version, status, message):
-        return self.protocol.handleStatus(version, status, message)
-
-    def handleHeader(self, key, val):
-        return self.protocol.handleHeader(key, val)
-
-    def handleResponse(self, data):
-        return self.protocol.handleResponse(data)
-
-class AsynchXendClientProtocol(XendClientProtocol):
-    """An asynchronous xend client. Uses twisted to connect to xend
-    and make the request. It does not block waiting for the result,
-    but sets up a deferred that is called when the result becomes available.
-
-    Uses AsynchXendClient to manage the connection.
-    """
-    def __init__(self):
-        self.err = None
-        self.headers = {}
-
-    def xendRequest(self, url, method, args=None):
-        """Make a request to xend. The returned deferred is called when
-        the result is available.
-        
-        @param url:    xend request url
-        @param method: http method: POST or GET
-        @param args:   request arguments (dict)
-        @return: deferred
-        """
-        request = XendRequest(url, method, args)
-        self.deferred = Deferred()
-        clientCreator = ClientCreator(reactor, AsynchXendClient, self, request)
-        clientCreator.connectTCP(url.host, url.port)
-        return self.deferred
-
-    def callErrback(self, err):
-        if not self.deferred.called:
-            self.err = err
-            self.deferred.errback(err)
-        return err
-
-    def callCallback(self, val):
-        if not self.deferred.called:
-            self.deferred.callback(val)
-        return val
-
-    def handleException(self, err):
-        return self.callErrback(err)
-
-    def handleHeader(self, key, val):
-        self.headers[key.lower()] = val
-
-    def getHeader(self, key):
-        return self.headers.get(key.lower())
-
-    def handleResponse(self, data):
-        if self.err: return self.err
-        val = XendClientProtocol.handleResponse(self, data)
-        if isinstance(val, Exception):
-            self.callErrback(val)
-        else:
-            self.callCallback(val)
-        return val
diff -Nru a/tools/python/xen/xend/XendClient.py 
b/tools/python/xen/xend/XendClient.py
--- a/tools/python/xen/xend/XendClient.py       2005-05-13 16:04:21 -04:00
+++ b/tools/python/xen/xend/XendClient.py       2005-05-13 16:04:21 -04:00
@@ -2,7 +2,7 @@
 # Copyright (C) 2004 Mike Wray <mike.wray@xxxxxx>
 """Client API for the HTTP interface on xend.
 Callable as a script - see main().
-Supports synchronous or asynchronous connection to xend.
+Supports inet or unix connection to xend.
 
 This API is the 'control-plane' for xend.
 The 'data-plane' is done separately. For example, consoles
@@ -15,7 +15,9 @@
 
 import sxp
 import PrettyPrint
-from XendProtocol import XendClientProtocol, SynchXendClientProtocol, XendError
+from XendProtocol import HttpXendClientProtocol, \
+                         UnixXendClientProtocol, \
+                         XendError
 
 DEBUG = 0
 
@@ -32,15 +34,6 @@
         return val
     raise XendError('cannot convert value')
 
-# todo: need to sort of what urls/paths are using for objects.
-# e.g. for domains at the moment return '0'.
-# should probably return abs path w.r.t. server, e.g. /xend/domain/0.
-# As an arg, assume abs path is obj uri, otherwise just id.
-
-# Function to convert to full url: Xend.uri(path), e.g.
-# maps /xend/domain/0 to http://wray-m-3.hpl.hp.com:8000/xend/domain/0
-# And should accept urls for ids?
-
 class URL:
     """A URL.
     """
@@ -115,7 +108,7 @@
         @param root:    xend root path on the server
         """

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.