예제 #1
0
파일: monitor.py 프로젝트: m0wfo/lighthouse
	def _pull(self):
		# Ping the instance and get its version
		_logger.info( '%s Ping', self.address)

#		_logger.info( "dump_json: %s", sync.cluster_state.get_state() + [{'address': sync.cluster_state.me}])
		# Try to push your state to the other side
		helpers.push_state( self.address, helpers.dump_json( sync.cluster_state.get_state() + [{'address': sync.cluster_state.me}]))

		info = helpers.info( self.address)
		if not info:
			self._reachable = False
			return
		try:
			self._version = data.DataVersion.from_dict( info[ 'version'])
		except (TypeError, KeyError):
			_logger.error( '%s Invalid pulled data', self.address)
			return
		self._touch_last_reachable()

		# Check that the other instance has newer configuration
		if self._version <= data.cur_data().version:
			return

		# The instance has newer configuration, try to pull it
		_logger.info( '%s Pull', self.address)

		content = helpers.pull( self.address)
		if content is None:
			return False
		# Check in new data
		if data.push_data( content):
			config.save_configuration()
예제 #2
0
파일: config.py 프로젝트: m0wfo/lighthouse
def _load_from_content( content):
	# Content must contain data and state
	if not 'copy' in content or not 'cluster' in content:
		return False

	if data.push_data( content[ 'copy']):
		sync.cluster_state.update_state( content[ 'cluster'])
		return True
	return False
예제 #3
0
def _load_from_content(content):
    # Content must contain data and state
    if not 'copy' in content or not 'cluster' in content:
        return False

    if data.push_data(content['copy']):
        sync.cluster_state.update_state(content['cluster'])
        return True
    return False
예제 #4
0
파일: server.py 프로젝트: m0wfo/lighthouse
	def put_copy(self):
		""" Pushes new data """

		# Get content
		content = self._read_input_json()

		# Update with the content given
		if data.push_data( content):
			config.save_configuration()
		self._response_created()
예제 #5
0
    def put_copy(self):
        """ Pushes new data """

        # Get content
        content = self._read_input_json()

        # Update with the content given
        if data.push_data(content):
            config.save_configuration()
        self._response_created()
예제 #6
0
    def _pull(self):
        # Ping the instance and get its version
        _logger.info('%s Ping', self.address)

        #		_logger.info( "dump_json: %s", sync.cluster_state.get_state() + [{'address': sync.cluster_state.me}])
        # Try to push your state to the other side
        helpers.push_state(
            self.address,
            helpers.dump_json(sync.cluster_state.get_state() +
                              [{
                                  'address': sync.cluster_state.me
                              }]))

        info = helpers.info(self.address)
        if not info:
            self._reachable = False
            return
        try:
            self._version = data.DataVersion.from_dict(info['version'])
        except (TypeError, KeyError):
            _logger.error('%s Invalid pulled data', self.address)
            return
        self._touch_last_reachable()

        # Check that the other instance has newer configuration
        if self._version <= data.cur_data().version:
            return

        # The instance has newer configuration, try to pull it
        _logger.info('%s Pull', self.address)

        content = helpers.pull(self.address)
        if content is None:
            return False
        # Check in new data
        if data.push_data(content):
            config.save_configuration()