Commit f9013a15 authored by Cristiano Urban's avatar Cristiano Urban
Browse files

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

parent 56de4c43
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ class DbConnector(object):
            connect_timeout = 0
        )

    def getConnection(self, retry = 5, timeout = 2):
    def getConnection(self, retry = 10, timeout = 30):
        if retry < 1:
            retry = 1
        if timeout < 1:
@@ -702,6 +702,26 @@ class DbConnector(object):
        finally:
            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 #####

    def getLocationId(self, destStorageId):