From 77b05f9cadbad1c422726a78f694d9fd392b86c8 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Fri, 28 Jun 2019 12:43:47 +0530 Subject: [PATCH 1/2] systemvm: don't fork to curl to save password 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 --- 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 a7f297edbb20..ec5405660d08 100755 --- a/systemvm/debian/opt/cloud/bin/configure.py +++ b/systemvm/debian/opt/cloud/bin/configure.py @@ -21,6 +21,8 @@ import os import re import sys +import urllib +import urllib2 import time from collections import OrderedDict @@ -62,10 +64,15 @@ def __update(self, vm_ip, password): 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): From bb34cfa42e087263c63daf57c1bdc2517d8999ac Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Fri, 28 Jun 2019 12:47:38 +0530 Subject: [PATCH 2/2] fix typo Signed-off-by: Rohit Yadav --- systemvm/debian/opt/cloud/bin/configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemvm/debian/opt/cloud/bin/configure.py b/systemvm/debian/opt/cloud/bin/configure.py index ec5405660d08..0ddce52f885e 100755 --- a/systemvm/debian/opt/cloud/bin/configure.py +++ b/systemvm/debian/opt/cloud/bin/configure.py @@ -70,7 +70,7 @@ def __update(self, vm_ip, password): 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()) + 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)