← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~daniel-thewatkins/cloud-init/lp1464253 into lp:cloud-init

 

Dan Watkins has proposed merging lp:~daniel-thewatkins/cloud-init/lp1464253 into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)
Related bugs:
  Bug #1440263 in cloud-init: "CloudStack reset password not working"
  https://bugs.launchpad.net/cloud-init/+bug/1440263

For more details, see:
https://code.launchpad.net/~daniel-thewatkins/cloud-init/lp1464253/+merge/261849
-- 
Your team cloud init development team is requested to review the proposed merge of lp:~daniel-thewatkins/cloud-init/lp1464253 into lp:cloud-init.
=== modified file 'cloudinit/sources/DataSourceCloudStack.py'
--- cloudinit/sources/DataSourceCloudStack.py	2015-02-23 09:36:36 +0000
+++ cloudinit/sources/DataSourceCloudStack.py	2015-06-12 13:45:10 +0000
@@ -47,35 +47,21 @@
     has documentation about the system.  This implementation is following that
     found at
     https://github.com/shankerbalan/cloudstack-scripts/blob/master/cloud-set-guest-password-debian
-
-    The CloudStack password server is, essentially, a broken HTTP
-    server. It requires us to provide a valid HTTP request (including a
-    DomU_Request header, which is the meat of the request), but just
-    writes the text of its response on to the socket, without a status
-    line or any HTTP headers.  This makes HTTP libraries sad, which
-    explains the screwiness of the implementation of this class.
-
-    This should be fixed in CloudStack by commit
-    a72f14ea9cb832faaac946b3cf9f56856b50142a in December 2014.
     """
 
     def __init__(self, virtual_router_address):
         self.virtual_router_address = virtual_router_address
 
     def _do_request(self, domu_request):
-        # We have to provide a valid HTTP request, but a valid HTTP
-        # response is not returned. This means that getresponse() chokes,
-        # so we use the socket directly to read off the response.
-        # Because we're reading off the socket directly, we can't re-use the
-        # connection.
-        conn = http_client.HTTPConnection(self.virtual_router_address, 8080)
-        try:
-            conn.request('GET', '', headers={'DomU_Request': domu_request})
-            conn.sock.settimeout(30)
-            output = conn.sock.recv(1024).decode('utf-8').strip()
-        finally:
-            conn.close()
-        return output
+        # The password server was in the past, a broken HTTP server, but is now
+        # fixed.  wget handles this seamlessly, so it's easier to shell out to
+        # that rather than write our own handling code.
+        output, _ = util.subp(
+            'wget -q -t 3 -T 20 -O -'
+            ' --header "DomU_Request: {0}" {1}:8080'.format(
+                domu_request, self.virtual_router_address),
+            shell=True)
+        return output.strip()
 
     def get_password(self):
         password = self._do_request('send_my_password')


Follow ups