Blame SOURCES/cobbler-ipv6-xmlrpc.patch

1070a0
--- ./cobbler/cobblerd.py   2010-07-28 17:48:48.000000000 +0200
1070a0
+++ ./cobbler/cobblerd.py   2012-01-26 11:26:05.000000000 +0100
1070a0
@@ -25,6 +25,7 @@ import socket
1070a0
 import time
1070a0
 import os
1070a0
 import SimpleXMLRPCServer
1070a0
+import SocketServer
1070a0
 import glob
1070a0
 from utils import _
1070a0
 import xmlrpclib
1070a0
@@ -104,7 +105,27 @@ def log(logger,msg):
1070a0
 def do_xmlrpc_rw(bootapi,settings,port):
1070a0
 
1070a0
     xinterface = remote.ProxiedXMLRPCInterface(bootapi,remote.CobblerXMLRPCInterface)
1070a0
-    server = remote.CobblerXMLRPCServer(('127.0.0.1', port))
1070a0
+
1070a0
+    bound = False
1070a0
+    for res in socket.getaddrinfo('localhost', port, socket.AF_UNSPEC,
1070a0
+        socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
1070a0
+        (af, sa) = (res[0], res[4])
1070a0
+        try:
1070a0
+            SocketServer.TCPServer.address_family = af
1070a0
+            server = remote.CobblerXMLRPCServer((sa[0], sa[1]))
1070a0
+        except Exception, msg:
1070a0
+            if af == socket.AF_INET:
1070a0
+                message = "Could not bind to %s:%s: %s" % (sa[0], sa[1], msg)
1070a0
+            elif af == socket.AF_INET6:
1070a0
+                message = "Could not bind to [%s]:%s: %s" % (sa[0], sa[1], msg)
1070a0
+            xinterface.logger.debug(message)
1070a0
+        else:
1070a0
+            bound = True
1070a0
+            break
1070a0
+
1070a0
+    if not bound:
1070a0
+        raise socket.error("Could not bind to localhost")
1070a0
+
1070a0
     server.logRequests = 0  # don't print stuff
1070a0
     xinterface.logger.debug("XMLRPC running on %s" % port)
1070a0
     server.register_instance(xinterface)
1070a0
--- ./cobbler/modules/authn_spacewalk.py    2010-07-28 17:48:48.000000000 +0200
1070a0
+++ ./cobbler/modules/authn_spacewalk.py    2012-01-26 11:26:05.000000000 +0100
1070a0
@@ -77,7 +77,7 @@ def authenticate(api_handle,username,pas
1070a0
     if server == "xmlrpc.rhn.redhat.com":
1070a0
         return False # emergency fail, don't bother RHN!
1070a0
 
1070a0
-    spacewalk_url = "https://%s/rpc/api" % server
1070a0
+    spacewalk_url = "http://%s/rpc/api" % server
1070a0
 
1070a0
     client = xmlrpclib.Server(spacewalk_url, verbose=0)
1070a0
 
1070a0
--- ./cobbler/utils.py  2012-01-26 11:26:05.000000000 +0100
1070a0
+++ ./cobbler/utils.py  2012-01-26 11:28:22.000000000 +0100
1070a0
@@ -1862,6 +1862,30 @@ def get_shared_secret():
1070a0
        return -1
1070a0
     return str(data).strip()
1070a0
 
1070a0
+def get_localhost_addr(port):
1070a0
+    (sock, sa, af) = (None, None, None)
1070a0
+    for res in socket.getaddrinfo('localhost', port, socket.AF_UNSPEC, socket.SOCK_STREAM):
1070a0
+        af, socktype, proto, canonname, sa = res
1070a0
+        try:
1070a0
+            sock = socket.socket(af, socktype, proto)
1070a0
+        except socket.error:
1070a0
+            sock = None
1070a0
+            continue
1070a0
+
1070a0
+        try:
1070a0
+            sock.connect((sa[0], sa[1]))
1070a0
+        except socket.error:
1070a0
+            sock.close()
1070a0
+            sock = None
1070a0
+            continue
1070a0
+        break
1070a0
+
1070a0
+    if sock is None:
1070a0
+        return (None, None)
1070a0
+
1070a0
+    sock.close()
1070a0
+    return (sa[0], af)
1070a0
+
1070a0
 def local_get_cobbler_api_url():
1070a0
     # Load server and http port
1070a0
     try:
1070a0
@@ -1882,7 +1906,18 @@ def local_get_cobbler_xmlrpc_url():
1070a0
     except:
1070a0
        traceback.print_exc()
1070a0
        raise CX("/etc/cobbler/settings is not a valid YAML file")
1070a0
-    return "http://%s:%s" % ("127.0.0.1",data.get("xmlrpc_port","25151"))
1070a0
+    port = data.get("xmlrpc_port","25151")
1070a0
+    addr = get_localhost_addr(port)
1070a0
+
1070a0
+    if addr[1] == socket.AF_INET:
1070a0
+        return "http://%s:%s" % (addr[0], port)
1070a0
+    if addr[1] == socket.AF_INET6:
1070a0
+        return "http://[%s]:%s" % (addr[0], port)
1070a0
+
1070a0
+    if os.path.exists('/proc/net/if_inet6'):
1070a0
+        return "http://[::1]:%s" % port
1070a0
+    else:
1070a0
+        return "http://127.0.0.1:%s" % port
1070a0
 
1070a0
 def strip_none(data, omit_none=False):
1070a0
     """
1070a0
--- ./scripts/services.py   2010-07-28 17:48:48.000000000 +0200
1070a0
+++ ./scripts/services.py   2012-01-26 11:26:05.000000000 +0100
1070a0
@@ -78,7 +78,7 @@ def handler(req):
1070a0
     # instantiate a CobblerWeb object
1070a0
     cw = CobblerSvc(
1070a0
          apache   = apache,
1070a0
-         server   = "http://127.0.0.1:%s" % remote_port
1070a0
+         server   = utils.local_get_cobbler_xmlrpc_url()
1070a0
     )
1070a0
 
1070a0
     # check for a valid path/mode
1070a0
--- ./scripts/services.wsgi 2010-10-07 20:12:03.000000000 +0200
1070a0
+++ ./scripts/services.wsgi 2012-01-26 11:26:05.000000000 +0100
1070a0
@@ -23,6 +23,7 @@ import yaml
1070a0
 import os
1070a0
 
1070a0
 from cobbler.services import CobblerSvc
1070a0
+import cobbler.utils as utils
1070a0
 
1070a0
 def application(environ, start_response):
1070a0
 
1070a0
@@ -64,7 +65,7 @@ def application(environ, start_response)
1070a0
     remote_port = ydata.get("xmlrpc_port",25151)
1070a0
 
1070a0
     # instantiate a CobblerWeb object
1070a0
-    cw = CobblerSvc(server = "http://127.0.0.1:%s" % remote_port)
1070a0
+    cw = CobblerSvc(server = utils.local_get_cobbler_xmlrpc_url())
1070a0
 
1070a0
     # check for a valid path/mode
1070a0
     # handle invalid paths gracefully
1070a0