def scan_network(request, network_id): network_msg = \ { "network" : None } network = DeviceNetwork.objects.get(pk=network_id) loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) AMQPH = AMQPHandler(loop) loop.run_until_complete(AMQPH.connect(amqp_connect_string=settings.RMQ_HOST)) network_msg['network'] = network.network loop.run_until_complete( AMQPH.send( settings.RMQ_PING_COMMANDER_RMQ_EXCHANGE, settings.RMQ_PING_OPERATOR_RMQ_QUEUE_IN, json.dumps(network_msg) ) ) loop.close() return redirect('main')
def main(): loop = asyncio.get_event_loop() AMQPH = AMQPHandler(loop) loop.run_until_complete( AMQPH.connect(amqp_connect_string=config['rmq_host'])) loop.run_until_complete( AMQPH.receive(config['rmq_exchange'], config['rmq_queue_in'], rmq_msg_proc)) loop.close()
def create(self, request): try: route_name = request.data.get('Name', str(uuid.uuid4())) owner_name = request.data.get('Owner') start_point_name = request.data['Start_Point_Name'] end_point_name = request.data['End_Point_Name'] create_route_msg = { 'route_name': route_name, } owner = User.objects.get(username=owner_name) start_point = Point.objects.get(Name=start_point_name) end_point = Point.objects.get(Name=end_point_name) route = Route(Name=route_name, Owner=owner) route.save() route.Points.add(start_point) route.Points.add(end_point) current_order = route.Order current_order['point_list'].append(start_point.pk) current_order['point_list'].append(end_point.pk) current_order['point_list_x'].append(start_point.X) current_order['point_list_y'].append(start_point.Y) current_order['point_list_x'].append(end_point.X) current_order['point_list_y'].append(end_point.Y) route.save() loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) AMQPH = AMQPHandler(loop) loop.run_until_complete( AMQPH.connect(amqp_connect_string=settings.RMQ_HOST)) loop.run_until_complete( AMQPH.send(settings.RMQ_ROUTE_CREATOR_EXCHANGE, settings.RMQ_ROUTE_CREATOR_QUEUE_IN, json.dumps(create_route_msg))) loop.close() return Response({True: "Request for creating new route sent"}) except Exception as e: return Response({False: "Route didn't created, {}".format(e)}, status=status.HTTP_412_PRECONDITION_FAILED)
def main(): logger.info('=== Activating route_creator service ===') loop = asyncio.get_event_loop() AMQPH = AMQPHandler(loop) loop.run_until_complete( AMQPH.connect(amqp_connect_string=config['rmq_host'])) loop.run_until_complete( AMQPH.receive(config['rmq_exchange'], config['rmq_queue_in'], awaitable_msg_proc_func=rmq_msg_proc)) loop.close()
def update_config_history(request, device_id='All'): device_j = \ { "telnet_ipv4" : None, "telnet_username" : None, "telnet_password" : None, "operation" : None, "device_id" : None } loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) AMQPH = AMQPHandler(loop) loop.run_until_complete(AMQPH.connect(amqp_connect_string=settings.RMQ_HOST)) if device_id == 'All': device_list = Device.objects.all() else: # we get it in to [] because it is the only one item. # and sent it to the cycle device_list = [Device.objects.get(pk=device_id)] for device in device_list: device_j['telnet_ipv4'] = device.device_ipv4 device_j['telnet_username'] = device.device_username device_j['telnet_password'] = device.device_password device_j['operation'] = "show running-config" device_j['device_id'] = device.id loop.run_until_complete( AMQPH.send( settings.RMQ_TELNET_OPERATOR_RMQ_EXCHANGE, settings.RMQ_TELNET_OPERATOR_RMQ_QUEUE_IN, json.dumps(device_j) ) ) loop.close() if device_id == 'All': return redirect('show_devices_group_list') return redirect('/show_device/{}'.format(device_id))
def update_config_history_by_ipv4(request, device_ipv4): device_j = \ { "telnet_ipv4" : None, "telnet_username" : None, "telnet_password" : None, "operation" : None, "device_id" : None } loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) AMQPH = AMQPHandler(loop) loop.run_until_complete(AMQPH.connect(amqp_connect_string=settings.RMQ_HOST)) try: device = Device.objects.get(device_ipv4=device_ipv4) device_j['telnet_ipv4'] = device.device_ipv4 device_j['telnet_username'] = device.device_username device_j['telnet_password'] = device.device_password device_j['operation'] = "show running-config" device_j['device_id'] = device.id loop.run_until_complete( AMQPH.send( settings.RMQ_TELNET_OPERATOR_RMQ_EXCHANGE, settings.RMQ_TELNET_OPERATOR_RMQ_QUEUE_IN, json.dumps(device_j) ) ) loop.close() response = { 'response': 'sent_to_queue' } except ObjectDoesNotExist as exc: response = { 'response': 'device_not_found' } data = json.dumps(response) return HttpResponse(data, content_type='application/json')
def main(): loop = asyncio.get_event_loop() AMQPH = AMQPHandler(loop) loop.run_until_complete(AMQPH.connect()) print('connected') loop.run_until_complete( AMQPH.send('test_ex', 'test_queue', 'Test Message!')) print('sended') loop.run_until_complete( AMQPH.send('test_ex', 'test_queue', 'Test Message1')) loop.run_until_complete( AMQPH.send('test_ex', 'test_queue', 'Test Message2')) asyncio.sleep(15) loop.run_until_complete( AMQPH.send('test_ex', 'test_queue', 'Test Message2')) # loop.run_until_complete(AMQPH.receive('test_ex', 'test_queue', test_msg_processor)) loop.close()