mirror of
https://opendev.org/x/pyghmi
synced 2025-01-27 19:37:44 +00:00
Reduce memory usage for uploading
A per instance copy of data was kept in scope throughout download process. Minimize that to once regardless of instances, and have lifetime of the extra copy be very short. Change-Id: Ife3c7f83bf9b97925cf079597f014db648b227ba
This commit is contained in:
parent
fcdfdd763c
commit
3adae44c07
@ -279,7 +279,10 @@ class IMMClient(object):
|
||||
|
||||
def weblogout(self):
|
||||
if self._wc:
|
||||
self._wc.grab_json_response(self.logouturl)
|
||||
try:
|
||||
self._wc.grab_json_response(self.logouturl)
|
||||
except Exception:
|
||||
pass
|
||||
self._wc = None
|
||||
|
||||
def hardware_inventory_map(self):
|
||||
@ -531,6 +534,7 @@ class XCCClient(IMMClient):
|
||||
self.wc.set_header('X-XSRF-TOKEN', self.wc.cookies['_csrf_token'])
|
||||
|
||||
def update_firmware_backend(self, filename, data=None, progress=None):
|
||||
self.weblogout()
|
||||
self._refresh_token()
|
||||
rsv = self.wc.grab_json_response('/api/providers/fwupdate', json.dumps(
|
||||
{'UPD_WebReserve': 1}))
|
||||
|
@ -43,6 +43,8 @@ def get_upload_form(filename, data):
|
||||
try:
|
||||
return uploadforms[filename]
|
||||
except KeyError:
|
||||
if isinstance(data, file):
|
||||
data = data.read()
|
||||
form = '--' + BND + '\r\nContent-Disposition: form-data; ' \
|
||||
'name="{0}"; filename="{0}"\r\n'.format(filename)
|
||||
form += 'Content-Type: application/octet-stream\r\n\r\n' + data
|
||||
@ -118,8 +120,6 @@ class SecureHTTPConnection(httplib.HTTPConnection, object):
|
||||
"""
|
||||
if data is None:
|
||||
data = open(filename, 'rb')
|
||||
if isinstance(data, file):
|
||||
data = data.read()
|
||||
form = get_upload_form(filename, data)
|
||||
ulheaders = self.stdheaders.copy()
|
||||
ulheaders['Content-Type'] = 'multipart/form-data; boundary=' + BND
|
||||
|
Loading…
x
Reference in New Issue
Block a user