Skip to content
Snippets Groups Projects
Commit f9013a15 authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Added 'getStorageHostname()' method + increased connection retries and wait time.

parent 56de4c43
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,7 @@ class DbConnector(object): ...@@ -44,7 +44,7 @@ class DbConnector(object):
connect_timeout = 0 connect_timeout = 0
) )
def getConnection(self, retry = 5, timeout = 2): def getConnection(self, retry = 10, timeout = 30):
if retry < 1: if retry < 1:
retry = 1 retry = 1
if timeout < 1: if timeout < 1:
...@@ -702,6 +702,26 @@ class DbConnector(object): ...@@ -702,6 +702,26 @@ class DbConnector(object):
finally: finally:
self.connPool.putconn(conn, close = False) self.connPool.putconn(conn, close = False)
def getStorageHostname(self, storageId):
"""Returns the storage hostname for a given storage id, if any. Otherwise it returns 'False'."""
conn = self.getConnection()
try:
cursor = conn.cursor(cursor_factory = RealDictCursor)
cursor.execute("SELECT hostname FROM storage WHERE storage_id = %s;", (storageId,))
result = cursor.fetchall()
cursor.close()
except Exception:
if not conn.closed:
conn.rollback()
raise
else:
if result:
return result[0]["hostname"]
else:
return False
finally:
self.connPool.putconn(conn, close = False)
##### Location ##### ##### Location #####
def getLocationId(self, destStorageId): def getLocationId(self, destStorageId):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment