Beispiel #1
0
    def _get_body(self):
        # H2N
        assert callable(self.settings_getter), repr(self.settings_getter)
        pre_settings = self.settings_getter()
        assert isinstance(pre_settings, dict), repr(pre_settings)

        settings = {name: (value, strftime(time))
                        for name, (value, time) in pre_settings.iteritems()}

        result = {}

        # For "revive", we always get the up-to-date information from the app.
        # Note that .revive field is in AbstractMessage, and we override
        # it here.
        self.revive = _revive = self.revive_getter()
        logger.debug('For heartbeat, revive=%r', _revive)
        if not _revive:
            result['revive'] = 0
        if settings:
            result['settings'] = settings

        if self.inbox_update:
            result['msgs'] = HeartbeatMessage.serialize_inbox_update(
                                 self.inbox_update)
            logger.verbose('Host sends inbox_update: %s', self.inbox_update)

        if self.last_auth_token_sync_ts is not None:
            assert isinstance(self.last_auth_token_sync_ts, datetime), \
                   repr(self.last_auth_token_sync_ts)
            result['last_auth_token_sync_ts'] = \
                    dt_to_ts(self.last_auth_token_sync_ts)
            logger.verbose('Host sends last_auth_token_sync_ts: %s',
                           self.last_auth_token_sync_ts)

        return result
Beispiel #2
0
    def _get_body_ack(self):
        # N2H
        result = {}

        # Process the last update time
        if self.ack_lu_time is not None:
            # We have a "last update time" to report back to the host
            assert isinstance(self.ack_lu_time, datetime), \
                   repr(self.ack_lu_time)
            result['last update time'] = strftime(self.ack_lu_time)
        else:
            # The settings were not updated on the node
            pass

        # Process the restore progress information:
        if self.ack_restore_progress:
            result['restore'] = \
                map(HeartbeatMessage.serialize_restore_progress,
                    self.ack_restore_progress)

        if self.inbox_update:
            result['msgs'] = HeartbeatMessage.serialize_inbox_update(
                                 self.inbox_update)
            logger.verbose('Node sends inbox_update: %s', self.inbox_update)

        if self.auth_tokens:
            assert consists_of(self.auth_tokens, AuthToken), \
                   repr(self.auth_tokens)
            result['auth_tokens'] = [t.to_json() for t in self.auth_tokens]
            logger.verbose('Node sends auth_tokens: %s',
                           self.auth_tokens)

        return result
Beispiel #3
0
    def _get_body_ack(self):
        # N2H
        result = {}

        # Process the last update time
        if self.ack_lu_time is not None:
            # We have a "last update time" to report back to the host
            assert isinstance(self.ack_lu_time, datetime), \
                   repr(self.ack_lu_time)
            result['last update time'] = strftime(self.ack_lu_time)
        else:
            # The settings were not updated on the node
            pass

        # Process the restore progress information:
        if self.ack_restore_progress:
            result['restore'] = \
                map(HeartbeatMessage.serialize_restore_progress,
                    self.ack_restore_progress)

        if self.inbox_update:
            result['msgs'] = HeartbeatMessage.serialize_inbox_update(
                self.inbox_update)
            logger.verbose('Node sends inbox_update: %s', self.inbox_update)

        if self.auth_tokens:
            assert consists_of(self.auth_tokens, AuthToken), \
                   repr(self.auth_tokens)
            result['auth_tokens'] = [t.to_json() for t in self.auth_tokens]
            logger.verbose('Node sends auth_tokens: %s', self.auth_tokens)

        return result
Beispiel #4
0
    def _get_body(self):
        # N2H
        assert isinstance(self.settings, col.Mapping), repr(self.settings)

        logger.debug('Sending updated settings to the host %s: %r',
                     self.dst.uuid, self.settings)

        # The value may be binary, so use base64 encoding
        return {'settings': {name: (base64.b64encode(value), strftime(time))
                                 for name, (value, time)
                                     in self.settings.iteritems()}}
Beispiel #5
0
    def _get_body(self):
        # N2H
        assert isinstance(self.settings, col.Mapping), repr(self.settings)

        logger.debug('Sending updated settings to the host %s: %r',
                     self.dst.uuid, self.settings)

        # The value may be binary, so use base64 encoding
        return {
            'settings': {
                name: (base64.b64encode(value), strftime(time))
                for name, (value, time) in self.settings.iteritems()
            }
        }
Beispiel #6
0
    def _get_body(self):
        # H2N
        assert callable(self.settings_getter), repr(self.settings_getter)
        pre_settings = self.settings_getter()
        assert isinstance(pre_settings, dict), repr(pre_settings)

        settings = {
            name: (value, strftime(time))
            for name, (value, time) in pre_settings.iteritems()
        }

        result = {}

        # For "revive", we always get the up-to-date information from the app.
        # Note that .revive field is in AbstractMessage, and we override
        # it here.
        self.revive = _revive = self.revive_getter()
        logger.debug('For heartbeat, revive=%r', _revive)
        if not _revive:
            result['revive'] = 0
        if settings:
            result['settings'] = settings

        if self.inbox_update:
            result['msgs'] = HeartbeatMessage.serialize_inbox_update(
                self.inbox_update)
            logger.verbose('Host sends inbox_update: %s', self.inbox_update)

        if self.last_auth_token_sync_ts is not None:
            assert isinstance(self.last_auth_token_sync_ts, datetime), \
                   repr(self.last_auth_token_sync_ts)
            result['last_auth_token_sync_ts'] = \
                    dt_to_ts(self.last_auth_token_sync_ts)
            logger.verbose('Host sends last_auth_token_sync_ts: %s',
                           self.last_auth_token_sync_ts)

        return result