You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ro...@apache.org on 2019/07/01 18:23:54 UTC

[cloudstack] branch master updated: systemvm: don't fork to curl to save password (#3437)

This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ecd5ec  systemvm: don't fork to curl to save password (#3437)
2ecd5ec is described below

commit 2ecd5ec804a51978cde645a363bf334c5491c5db
Author: Rohit Yadav <ro...@shapeblue.com>
AuthorDate: Mon Jul 1 23:53:44 2019 +0530

    systemvm: don't fork to curl to save password (#3437)
    
    This fixes to avoid forking curl to save password but instead call
    a HTTP POST url directly within Python code. This may reduce bottleneck
    during high VM launches that require passwords.
    
    Fixes #3182
    
    Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
---
 systemvm/debian/opt/cloud/bin/configure.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/systemvm/debian/opt/cloud/bin/configure.py b/systemvm/debian/opt/cloud/bin/configure.py
index a7f297e..0ddce52 100755
--- a/systemvm/debian/opt/cloud/bin/configure.py
+++ b/systemvm/debian/opt/cloud/bin/configure.py
@@ -21,6 +21,8 @@ import logging
 import os
 import re
 import sys
+import urllib
+import urllib2
 import time
 
 from collections import OrderedDict
@@ -62,10 +64,15 @@ class CsPassword(CsDataBag):
             server_ip = ip.split('/')[0]
             proc = CsProcess(['/opt/cloud/bin/passwd_server_ip.py', server_ip])
             if proc.find():
-                update_command = 'curl --header "DomU_Request: save_password" "http://{SERVER_IP}:8080/" -F "ip={VM_IP}" -F "password={PASSWORD}" ' \
-                                 '-F "token={TOKEN}" >/dev/null 2>/dev/null &'.format(SERVER_IP=server_ip, VM_IP=vm_ip, PASSWORD=password, TOKEN=token)
-                result = CsHelper.execute(update_command)
-                logging.debug("Update password server result ==> %s" % result)
+                url = "http://%s:8080/" % server_ip
+                payload = {"ip": vm_ip, "password": password, "token": token}
+                data = urllib.urlencode(payload)
+                request = urllib2.Request(url, data=data, headers={"DomU_Request" : "save_password"})
+                try:
+                    resp = urllib2.urlopen(request, data)
+                    logging.debug("Update password server result: http:%s, content:%s" % (resp.code, resp.read()))
+                except Exception as e:
+                    logging.error("Failed to update password server due to: %s" % e)
 
 
 class CsAcl(CsDataBag):