Exemple #1
0
    def send(self, report):
        request = PDServerRequest('/api/routers/{router_id}')
        d = request.patch(*report)

        # Check for error code and retry.
        def cbresponse(response):
            if not response.success:
                out.warn('{} to {} returned code {}'.format(
                    request.method, request.url, response.code))
                if self.max_retries is None or self.retries < self.max_retries:
                    reactor.callLater(self.retryDelay, self.send, report)
                    self.retries += 1
                    self.increaseDelay()
                nexus.core.jwt_valid = False
            else:
                nexus.core.jwt_valid = True

        # Check for connection failures and retry.
        def cberror(ignored):
            out.warn('{} to {} failed'.format(request.method, request.url))
            if self.max_retries is None or self.retries < self.max_retries:
                reactor.callLater(self.retryDelay, self.send, report)
                self.retries += 1
                self.increaseDelay()
            nexus.core.jwt_valid = False

        d.addCallback(cbresponse)
        d.addErrback(cberror)
        return d
Exemple #2
0
    def _update_complete(self, update):
        """
        Internal: callback after an update operation has been completed
        (successfuly or otherwise) and send a notification to the server.
        """
        # If delegated to an external program, we do not report to pdserver
        # that the update is complete.
        if update.delegated:
            return

        out.info("The update is done, report it to server...")
        update_id = update.external['update_id']
        success = update.result.get('success', False)

        request = PDServerRequest('/api/routers/{router_id}/updates/' +
                                  str(update_id))
        d = request.patch(
            {
                'op': 'replace',
                'path': '/completed',
                'value': True
            }, {
                'op': 'replace',
                'path': '/success',
                'value': success
            })

        return d
Exemple #3
0
    def send(self, report):
        request = PDServerRequest('/api/routers/{router_id}')
        d = request.patch(*report)

        # Check for error code and retry.
        def cbresponse(response):
            if not response.success:
                out.warn('{} to {} returned code {}'.format(request.method,
                    request.url, response.code))
                if self.max_retries is None or self.retries < self.max_retries:
                    reactor.callLater(self.retryDelay, self.send, report)
                    self.retries += 1
                    self.increaseDelay()
                nexus.core.jwt_valid = False
            else:
                nexus.core.jwt_valid = True

        # Check for connection failures and retry.
        def cberror(ignored):
            out.warn('{} to {} failed'.format(request.method, request.url))
            if self.max_retries is None or self.retries < self.max_retries:
                reactor.callLater(self.retryDelay, self.send, report)
                self.retries += 1
                self.increaseDelay()
            nexus.core.jwt_valid = False

        d.addCallback(cbresponse)
        d.addErrback(cberror)
        return d
    def started(self):
        """
        This function should be called when the updated object is dequeued and
        execution is about to begin.

        Sends a notification to the pdserver if this is a tracked update.
        """
        # TODO Look into this.
        # This might happen during router initialization.  If nexus.core is
        # None, we do not know the router's identity, so we cannot publish any
        # messages.
        if nexus.core is None:
            return

        # The external field is set for updates from pdserver but not for
        # locally-initiated (sideloaded) updates.
        if hasattr(self, 'external'):
            update_id = self.external['update_id']
            request = PDServerRequest('/api/routers/{router_id}/updates/' +
                                      str(update_id))
            request.patch({'op': 'replace', 'path': '/started', 'value': True})
Exemple #5
0
 def _update_ignored(self, update):
     """
     Internal: callback for an update that we are ignoring because
     it was started previously and never completed.
     """
     update_id = update['_id']
     request = PDServerRequest('/api/routers/{router_id}/updates/' +
             str(update_id))
     d = request.patch(
         {'op': 'replace', 'path': '/completed', 'value': True},
         {'op': 'replace', 'path': '/success', 'value': False}
     )
     return d