Skip to content

Commit 2ecd5ec

Browse files
authored
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 <rohit.yadav@shapeblue.com>
1 parent 4449556 commit 2ecd5ec

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

systemvm/debian/opt/cloud/bin/configure.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import os
2222
import re
2323
import sys
24+
import urllib
25+
import urllib2
2426
import time
2527

2628
from collections import OrderedDict
@@ -62,10 +64,15 @@ def __update(self, vm_ip, password):
6264
server_ip = ip.split('/')[0]
6365
proc = CsProcess(['/opt/cloud/bin/passwd_server_ip.py', server_ip])
6466
if proc.find():
65-
update_command = 'curl --header "DomU_Request: save_password" "http://{SERVER_IP}:8080/" -F "ip={VM_IP}" -F "password={PASSWORD}" ' \
66-
'-F "token={TOKEN}" >/dev/null 2>/dev/null &'.format(SERVER_IP=server_ip, VM_IP=vm_ip, PASSWORD=password, TOKEN=token)
67-
result = CsHelper.execute(update_command)
68-
logging.debug("Update password server result ==> %s" % result)
67+
url = "http://%s:8080/" % server_ip
68+
payload = {"ip": vm_ip, "password": password, "token": token}
69+
data = urllib.urlencode(payload)
70+
request = urllib2.Request(url, data=data, headers={"DomU_Request" : "save_password"})
71+
try:
72+
resp = urllib2.urlopen(request, data)
73+
logging.debug("Update password server result: http:%s, content:%s" % (resp.code, resp.read()))
74+
except Exception as e:
75+
logging.error("Failed to update password server due to: %s" % e)
6976

7077

7178
class CsAcl(CsDataBag):

0 commit comments

Comments
 (0)