connection: Return copys of cached object lists

Incase any users manipulate the lists, we don't want that to affect
our caching. Could prevent future mistakes
This commit is contained in:
Cole Robinson 2017-07-19 14:56:10 -04:00
parent 4e4a6c817f
commit 55aa23b400
2 changed files with 8 additions and 8 deletions

View File

@ -93,20 +93,20 @@ def openconn(uri):
cache = _conn_cache[uri].copy()
def cb_fetch_all_guests():
return cache["vms"]
return cache["vms"][:]
def cb_fetch_all_nodedevs():
return cache["nodedevs"]
return cache["nodedevs"][:]
def cb_fetch_all_pools():
if "pools" not in cache:
cache["pools"] = conn._fetch_all_pools_raw()
return cache["pools"]
return cache["pools"][:]
def cb_fetch_all_vols():
if "vols" not in cache:
cache["vols"] = conn._fetch_all_vols_raw()
return cache["vols"]
return cache["vols"][:]
def cb_clear_cache(pools=False):
if pools:

View File

@ -190,7 +190,7 @@ class VirtualConnection(object):
key = self._FETCH_KEY_GUESTS
if key not in self._fetch_cache:
self._fetch_cache[key] = self._fetch_all_guests_raw()
return self._fetch_cache[key]
return self._fetch_cache[key][:]
def _fetch_all_pools_raw(self):
ignore, ignore, ret = pollhelpers.fetch_pools(
@ -208,7 +208,7 @@ class VirtualConnection(object):
key = self._FETCH_KEY_POOLS
if key not in self._fetch_cache:
self._fetch_cache[key] = self._fetch_all_pools_raw()
return self._fetch_cache[key]
return self._fetch_cache[key][:]
def _fetch_all_vols_raw(self):
ret = []
@ -239,7 +239,7 @@ class VirtualConnection(object):
key = self._FETCH_KEY_VOLS
if key not in self._fetch_cache:
self._fetch_cache[key] = self._fetch_all_vols_raw()
return self._fetch_cache[key]
return self._fetch_cache[key][:]
def _fetch_all_nodedevs_raw(self):
ignore, ignore, ret = pollhelpers.fetch_nodedevs(
@ -257,7 +257,7 @@ class VirtualConnection(object):
key = self._FETCH_KEY_NODEDEVS
if key not in self._fetch_cache:
self._fetch_cache[key] = self._fetch_all_nodedevs_raw()
return self._fetch_cache[key]
return self._fetch_cache[key][:]
#########################