Example #1
0
    def getStatus(self, session: str, startMessage: int,
                  getNodes: bool) -> AddHostStatus:
        """
        Raises:
            NotFound
        """
        with self._addHostLock:
            nodeList = self._nodeDbApi.getNodesByAddHostSession(session) \
                if getNodes else TortugaObjectList()

            # Lock and copy for data consistency
            if session not in self._sessions:
                raise NotFound('Invalid add host session ID [%s]' % (session))

            sessionDict = self._sessions.get(session)

            statusCopy = AddHostStatus()

            # Copy simple data
            for key in sessionDict['status'].getKeys():
                statusCopy.set(key, sessionDict['status'].get(key))

            # Get slice of status messages
            messages = sessionDict['status'].getMessageList()[startMessage:]

            statusCopy.setMessageList(messages)

            if nodeList:
                statusCopy.getNodeList().extend(nodeList)

            return statusCopy
Example #2
0
    def getStatus(self, session, startMessage, getNodes):
        """
        Raises:
            NotFound
        """

        statusCopy = AddHostStatus()

        self._addHostLock.acquire()

        try:
            if getNodes and session is not None and \
                    self._nodeDbApi is not None:
                nodeList = self._nodeDbApi.getNodesByAddHostSession(session)
            else:
                nodeList = TortugaObjectList()

            # Lock and copy for data consistency
            if session not in self._sessions:
                raise NotFound('Invalid add host session ID [%s]' % (session))

            sessionDict = self._sessions.get(session)

            # Copy simple data
            for key in sessionDict['status'].getKeys():
                statusCopy.set(key, sessionDict['status'].get(key))

            # Get slice of status messages
            messages = sessionDict['status'].getMessageList()[startMessage:]

            statusCopy.setMessageList(messages)

            statusCopy.getNodeList().extend(nodeList)

            return statusCopy
        finally:
            self._addHostLock.release()