Exemple #1
0
    def getStatus(self, session=None, startMessage=0, getNodes=False):
        """
        Get the status of addhost...if session is non-none get info for that
        session only.  Startmessage controls the number of removed from
        the start of the server side message list.  If getNodes is true
        also include the nodes for this session.

        Returns:
            AddHostStatus object
        Throws:
            TortugaException
        """

        url = self._buildUrl('v1/addhost/%s/status' % (session))

        # Add query parameters
        url += '?startMessage={0}&getNodes={1}'.format(
            startMessage, str(getNodes))

        try:
            _, responseDict = self.sendSessionRequest(url)

            return AddHostStatus.getFromDict(responseDict.get("addhoststatus"))
        except TortugaException:
            raise
        except Exception as ex:
            raise TortugaException(exception=ex)
Exemple #2
0
    def getStatus(self, db_session: Session, session: str, startMessage: int,
                  getNodes: bool) -> AddHostStatus:
        """
        Raises:
            NotFound
        """
        with self._addHostLock:
            nodeList = self._nodeDbApi.getNodesByAddHostSession(
                db_session, session) if getNodes else TortugaObjectList()

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

            session = self._sessions.get(session)

            status_copy = AddHostStatus()

            # Copy simple data
            status = AddHostStatus.getFromDict(session['status'])
            for key in status.getKeys():
                status_copy.set(key, status.get(key))

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

            status_copy.setMessageList(messages)

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

            return status_copy
Exemple #3
0
    def update_session(self, session_id: str, running: Optional[bool] = None):
        self.getLogger().debug(
            'Updating add host session [%s] (status: running=%s)' %
            (session_id, str(running)))

        with self._addHostLock:
            session = self._sessions.get(session_id)
            status = AddHostStatus.getFromDict(session['status'])
            session['status'] = status.getCleanDict()
            self._sessions.set(session_id, session)
Exemple #4
0
    def updateStatus(self, addHostSession: str, msg: str) -> None:
        self._addHostLock.acquire()

        try:
            if not self._sessions.exists(addHostSession):
                self.getLogger().warning(
                    'updateStatus(): unknown session ID [%s]' %
                    (addHostSession))

                return

            addHostStatus = AddHostStatus.getFromDict(
                self._sessions.get(addHostSession)['status'])

            addHostStatus.getMessageList().append(msg)
        finally:
            self._addHostLock.release()