def announce(self): ''' Announce the local node to another OpenRelay node ''' full_ip_address = self.get_full_ip_address() url = self.get_service_url('service-announce') try: response = requests.post(url, data=self.get_id_package()) except requests.ConnectionError: logger.error('unable to connect to url: %s' % url) raise AnnounceClientError('Unable to join network') if response.status_code == status.OK: node_answer = loads(response.content) if node_answer['uuid'] == LocalNode.get().uuid: logger.error('announce service on node with uuid: %s and url: %s, responded the same UUID as the local server' % (node_answer['uuid'], full_ip_address)) raise AnnounceClientError('Remote and local nodes identity conflict') else: sibling_data = { 'ip_address': node_answer['ip_address'], 'port': node_answer['port'], 'name': node_answer['name'], 'email': node_answer['email'], 'comment': node_answer['comment'], } sibling, created = Sibling.objects.get_or_create(uuid=node_answer['uuid'], defaults=sibling_data) if not created: sibling.ip_address = sibling_data['ip_address'] sibling.port = sibling_data['port'] sibling.save() else: logger.error('announce service on remote node responded with a non OK code') raise AnnounceClientError('Unable to join network')
def post(self, request): uuid = request.POST.get('uuid') ip_address = request.POST.get('ip_address') port = request.POST.get('port') logger.info('received announce call from: %s @ %s' % (uuid, request.META['REMOTE_ADDR'])) if uuid and ip_address and port: sibling_data = {'ip_address': ip_address, 'port': port} # TODO: Verify node identity sibling, created = Sibling.objects.get_or_create(uuid=uuid, defaults=sibling_data) if not created: sibling.ip_address = sibling_data['ip_address'] sibling.port = sibling_data['port'] sibling.save() local_node = LocalNode.get() local_node_info = { 'ip_address': IPADDRESS, 'port': PORT, 'uuid': local_node.uuid, 'name': local_node.name, 'email': local_node.email, 'comment': local_node.comment, } return local_node_info else: return Response(status.PARTIAL_CONTENT)
def get_id_package(self): local_node = LocalNode.get() return { 'ip_address': IPADDRESS, 'port': PORT, 'uuid': local_node.uuid, }
def node_info(request): return render_to_response('node_list.html', { 'object_list': [LocalNode.get()], 'title': _(u'Local node information'), }, context_instance=RequestContext(request))