def runtrace(request): sourceip = request.POST.get('sourceip') destip = request.POST.get('destip') vrf = request.POST.get('vrf') network = request.POST.get('network') vrfname = request.POST.get('vrfname') baseurl = get_vars('ansibengineemc') emcvrfname = getvrflist('emc') if sourceip == '' or destip == '' or vrf == '' or vrfname == '' or network == '': return render( request, 'traceroute/traceroute.html', { 'task': "task", 'emcvrf': emcvrfname, 'message': "Please fill in all the details!!" }) if str(network).lower() == 'EMC'.lower(): baseurl = get_vars('ansibengineemc') else: baseurl = get_vars('ansibenginemtn') if vrf == 'True': vrf = "True" else: vrf = "False" return render( request, 'traceroute/runtraceroute.html', { 'sourceip': sourceip, 'destip': destip, 'vrfname': vrfname, 'vrf': vrf, 'baseurl': baseurl })
def allRowPingTest(request, id): emcbaseurl = get_vars('ansibengineemc') mtnbaseurl = get_vars('ansibenginemtn') reqbody = {} if request.method == 'POST': baseurl = request.POST.get('baseurl') reqbody['value'] = request.POST.get('value') # if request.method == 'POST': # baseurl = request.POST.get('baseurl') emcurl = 'http://200.12.221.43:5000' + '/rowPingTest' mtnurl = 'http://10.200.96.103:5000' + '/rowPingTest' headers = {'content-type': 'application/json'} data= {} temp={} response='' # data["value"] = "RAI_LND_1Gig_T-SYSTEM_0EV/3_Diessen,OEV/3 Diessen 56 SCF1 . London T7 / 7LB/2 / Port 15.3,DU1400739,RAI-LND,EMC_CORE_RAI_7606_2,GigabitEthernet3/24,10.10.10.71,EMC_CORE_LND_7606_2,GigabitEthernet1/2/1,10.10.10.203,Deutsche Telekom,999-RAI-LON-102-FB-Deutsche_Telekom-(CID-0EV/3-Diessen-1),20,35,40,+49 69 20060 55 58*EMC-DIVEO-XConn-CID:5511206801-MIAMI-BRAZIL-DIVEO-10Mbps-Copper,DU0506772,DU0506772,MIAMI-BRAZIL,EMC_CORE_MIAMI_ASR_2,GigabitEthernet0/0/3.101,10.10.10.226,EMC_CORE_BRAZ_ASR1K1_1,GigabitEthernet0/0/0,10.10.10.50,T-Systems,999-MIAMI-Brazil-101-CO-TSystems-(CID:5511206801_TSYSTEMS,139,144,149,0800160066,55113097-5239" try: if id == '0': response = requests.post(emcurl, data=json.dumps(reqbody), headers=headers) # mtnresponse = requests.post(mtnurl, data=json.dumps(data), headers=headers) elif id == '1': response = requests.post(mtnurl, data=json.dumps(reqbody), headers=headers) # mtnresponse = requests.post(mtnurl, data=json.dumps(data), headers=headers) if not response.status_code == 200: temp['value']="Error !! Unexpected response. Please report this" return HttpResponse(json.dumps(temp), content_type = "application/json") except requests.exceptions.RequestException as e: # return "Error: {}".format(e) temp['value']="Error connecting to API. Please report this" return HttpResponse(json.dumps(temp), content_type = "application/json") return HttpResponse(json.dumps(response), content_type = "application/json")
def orionNodeStates(request, id): emcbaseurl = get_vars('ansibengineemc') mtnbaseurl = get_vars('ansibenginemtn') emcurl = 'http://200.12.221.43:5000' + '/orionNodeStates' mtnurl = 'http://10.200.96.103:5000' + '/orionNodeStates' headers = {'content-type': 'application/json'} data= {} temp={} response='' try: if id == '0': response = requests.post(emcurl, data=json.dumps(data), headers=headers) # mtnresponse = requests.post(mtnurl, data=json.dumps(data), headers=headers) elif id == '1': response = requests.post(mtnurl, data=json.dumps(data), headers=headers) # mtnresponse = requests.post(mtnurl, data=json.dumps(data), headers=headers) if not response.status_code == 200: temp['value']="Error !! Unexpected response. Please report this" return HttpResponse(json.dumps(temp), content_type = "application/json") except requests.exceptions.RequestException as e: # return "Error: {}".format(e) temp['value']="Error connecting to API. Please report this" return HttpResponse(json.dumps(temp), content_type = "application/json") return HttpResponse(response, content_type = "application/json")
def runipamcheck(request): emcbaseurl = get_vars('ansibengineemc') mtnbaseurl = get_vars('ansibenginemtn') if request.method == 'POST': baseurl = request.POST.get('baseurl') destip = request.POST.get('destip') # if request.method == 'POST': # baseurl = request.POST.get('baseurl') emcurl = emcbaseurl + '/ansibengine/api/v1.0/checkipam' mtnurl = mtnbaseurl + '/ansibengine/api/v1.0/checkipam' headers = {'content-type': 'application/json'} data = {} temp = {} data['destip'] = destip try: emcresponse = requests.post(emcurl, data=json.dumps(data), headers=headers, auth=('netbot', 'N#tB@t')) mtnresponse = requests.post(mtnurl, data=json.dumps(data), headers=headers, auth=('netbot', 'N#tB@t')) if not emcresponse.status_code == 200 or not mtnresponse.status_code == 200: temp['value'] = "Error !! Unexpected response. Please report this" return HttpResponse(json.dumps(temp), content_type="application/json") except requests.exceptions.RequestException as e: # return "Error: {}".format(e) temp['value'] = "Error connecting to API. Please report this" return HttpResponse(json.dumps(temp), content_type="application/json") # if (json.loads(mtnresponse.text)['value']) is None: # temp['value']="Entered Subnet :"+destip+"\n\n On EMC Network\n\n "+json.loads(emcresponse.text)['value']+"\n\n\n On MTN Network\n\nApi returned null" # return HttpResponse(json.dumps(temp), content_type = "application/json") # elif (json.loads(emcresponse.text)['value']) is None: # temp['value']="Entered Subnet :"+destip+"\n\n On MTN Network\n\n "+json.loads(mtnresponse.text)['value']+"\n\n\n On EMC Network\n\nApi returned null" # return HttpResponse(json.dumps(temp), content_type = "application/json") temp[ 'value'] = "Entered Subnet :" + destip + "\n\n On EMC Network\n\n " + json.loads( emcresponse.text )['value'] + "\n\n\n On MTN Network\n\n " + json.loads( mtnresponse.text)['value'] + " " return HttpResponse(json.dumps(temp), content_type="application/json")
def getresultout(request, id): result = get_object_or_404(Result, pk=id) baseurl = get_vars('baseurl') return render(request, 'results/outputfile.html', { 'result': result, 'baseurl': baseurl })
def rerunresult(request): baseurl = get_vars('baseurl') if request.method == 'POST': resultid = request.POST.get('resultid') oldresult = get_object_or_404(Result, pk=resultid) result = Result() result.create_user = request.user result.inventory = oldresult.inventory # if not request.POST.get('factfile'): # result.factfile = request.POST.get('factfile') # task = get_object_or_404(Task, pk=taskid) result.task = oldresult.task result.factfile = oldresult.factfile result.name = oldresult.name result.description = oldresult.description result.network = oldresult.network result.playbook = oldresult.playbook result.credential = oldresult.credential result.factstatus = oldresult.factstatus result.save() # tags = form.cleaned_data.get('tags') # task.create_tags(tags) # return redirect('/results/') return render(request, 'results/playoutput.html', { 'result': result, 'baseurl': baseurl })
def rowPingTest(request, id): emcbaseurl = get_vars('ansibengineemc') mtnbaseurl = get_vars('ansibenginemtn') reqbody = {} if request.method == 'POST': baseurl = request.POST.get('baseurl') reqbody['ca']= request.POST.get('ca') reqbody['cai'] = request.POST.get('cai') reqbody['caa'] = request.POST.get('caa') reqbody['cz'] = request.POST.get('cz') reqbody['czi'] = request.POST.get('czi') reqbody['cza'] = request.POST.get('cza') emcurl = 'http://200.12.221.43:5000' + '/rowPingTest' mtnurl = 'http://10.200.96.103:5000' + '/rowPingTest' headers = {'content-type': 'application/json'} data= {} temp={} response='' try: if id == '0': response = requests.post(emcurl, data=json.dumps(reqbody), headers=headers) # mtnresponse = requests.post(mtnurl, data=json.dumps(data), headers=headers) elif id == '1': response = requests.post(mtnurl, data=json.dumps(reqbody), headers=headers) # mtnresponse = requests.post(mtnurl, data=json.dumps(data), headers=headers) if not response.status_code == 200: temp['value']="Error !! Unexpected response. Please report this" return HttpResponse(json.dumps(temp), content_type = "application/json") # data["ca"] = "EMC_CORE_RAI_7606_2" # data["cai"] = "GigabitEthernet3/24" # data["caa"] = "10.10.10.71" # data["cz"] = "EMC_CORE_LND_7606_2" # data["czi"] = "GigabitEthernet1/2/1" # data["cza"] = "10.10.10.203" except requests.exceptions.RequestException as e: # return "Error: {}".format(e) temp['value']="Error connecting to API. Please report this" return HttpResponse(json.dumps(temp), content_type = "application/json") return HttpResponse(json.dumps(response), content_type = "application/json")
def edit(request, id): tags = '' if id: inventory = get_object_or_404(Inventory, pk=id) # for tag in task.get_tags(): # tags = u'{0} {1}'.format(tags, tag.tag) # tags = tags.strip() else: inventory = Inventory(create_user=request.user) if inventory.create_user.id != request.user.id: return redirect('home') if request.POST: form = InventoryForm(request.POST, instance=inventory, initial={'inventory': inventory.pk}) # form.fields['inventory'].queryset = invinstance = get_object_or_404(Inventory, pk=id) if form.is_valid(): form.save() ansibengineemc = get_vars('ansibengineemc') ansibenginemtn = get_vars('ansibenginemtn') if invinstance.network == 'EMC': url = ansibengineemc + '/ansibengine/api/v1.0/altinventory' else: url = ansibenginemtn + '/ansibengine/api/v1.0/altinventory' # url = 'http://200.12.221.13:5555/ansibengine/api/v1.0/altinventory' headers = {'content-type': 'application/json'} data = {} data['variable'] = invinstance.network + str("inv") + str( invinstance.id) data['inventory'] = form.cleaned_data.get('variable') # data='{"variable":"10.10.10.102","inventory":invinstance}' # data = '{"query":{"bool":{"must":[{"text":{"record.document":"SOME_JOURNAL"}},{"text":{"record.articleTitle":"farmers"}}],"must_not":[],"should":[]}},"from":0,"size":50,"sort":[],"facets":{}}' response = requests.post(url, data=json.dumps(data), headers=headers, auth=('netbot', 'N#tB@t')) return redirect('/inventories/') else: form = InventoryForm(instance=inventory, initial={'tags': tags}) return render(request, 'inventories/edit.html', {'form': form})
def search(request): if 'q' in request.GET: querystring = request.GET.get('q').strip() if len(querystring) == 0: return redirect('/search/') try: search_type = request.GET.get('type') if search_type not in [ 'results', 'inventories', 'tasks', 'feed', 'articles', 'questions', 'users' ]: search_type = 'tasks' except Exception, e: search_type = 'tasks' count = {} results = {} results['tasks'] = Task.objects.filter(name__icontains=querystring) results['inventories'] = Inventory.objects.filter( name__icontains=querystring) results['results'] = Result.objects.filter(name__icontains=querystring) results['feed'] = Feed.objects.filter(post__icontains=querystring, parent=None) results['articles'] = Article.objects.filter( Q(title__icontains=querystring) | Q(content__icontains=querystring)) results['questions'] = Question.objects.filter( Q(title__icontains=querystring) | Q(description__icontains=querystring)) results['users'] = User.objects.filter( Q(username__icontains=querystring) | Q(first_name__icontains=querystring) | Q(last_name__icontains=querystring)) count['tasks'] = results['tasks'].count() count['inventories'] = results['inventories'].count() count['results'] = results['results'].count() count['feed'] = results['feed'].count() count['articles'] = results['articles'].count() count['questions'] = results['questions'].count() count['users'] = results['users'].count() # baseurl = "http://127.0.0.1:8000" baseurl = get_vars('baseurl') return render( request, 'search/results.html', { 'hide_search': True, 'querystring': querystring, 'active': search_type, 'count': count, 'baseurl': baseurl, 'results': results[search_type], })
def delONSRecord(request, id): emcbaseurl = get_vars('ansibengineemc') mtnbaseurl = get_vars('ansibenginemtn') reqbody = {} if request.method == 'DELETE': baseurl = request.DELETE.get('baseurl') reqbody['nodeName']= request.DELETE.get('nodeName') reqbody['city']= request.DELETE.get('city') emcurl = 'http://200.12.221.43:5000' + '/coreCircuitStates' mtnurl = 'http://10.200.96.103:5000' + '/coreCircuitStates' headers = {'content-type': 'application/json'} data= {} temp={} response='' data["icd"] = reqbody['nodeName'] data["city"] = reqbody['city'] # data["icd"] = "Testing1" try: if id == '0': response = requests.post(emcurl, data=json.dumps(data), headers=headers) # mtnresponse = requests.post(mtnurl, data=json.dumps(data), headers=headers) elif id == '1': response = requests.post(mtnurl, data=json.dumps(data), headers=headers) # mtnresponse = requests.post(mtnurl, data=json.dumps(data), headers=headers) if not response.status_code == 200: temp['value']="Error !! Unexpected response. Please report this" return HttpResponse(json.dumps(temp), content_type = "application/json") except requests.exceptions.RequestException as e: # return "Error: {}".format(e) temp['value']="Error connecting to API. Please report this" return HttpResponse(json.dumps(temp), content_type = "application/json") return HttpResponse(response, content_type = "application/json")
def runinterfacetraceroute(request): baseurl = get_vars('ansibengineemc') if request.method == 'POST': baseurl = request.POST.get('baseurl') # if request.method == 'POST': # baseurl = request.POST.get('baseurl') url = baseurl + '/ansibengine/api/v1.0/runinterfacetraceroute' headers = {'content-type': 'application/json'} data = {} data['value'] = url response = requests.post(url, data=json.dumps(data), headers=headers, auth=('netbot', 'N#tB@t')) return HttpResponse(response.text, content_type="application/json")
def runcommand(request): # taskid=request.POST['taskid'] # tasks = Task.objects.filter(pk=id) # result = get_object_or_404(ConfCreator, pk=id) # commands = ConfCreator.objects.filter(network="EMC") reqbody = {} baseurl = get_vars('baseurl') if request.method == 'POST': # reqbody['commands'] = request.POST.get('commands').splitlines() reqbody['network'] = request.POST.get('network') reqbody['inventory'] = request.POST.get('inventory') reqbody['id'] = request.POST.get('id') return render(request, 'confcreator/execcommandoutput.html', { 'id': reqbody['id'], 'inventory': reqbody['inventory'], 'baseurl': baseurl })
def runcommandoutapi(request): # taskid=request.POST['taskid'] # tasks = Task.objects.filter(pk=id) # result = get_object_or_404(ConfCreator, pk=id) # commands = ConfCreator.objects.filter(network="EMC") reqbody = {} baseurl = get_vars('baseurl') if request.method == 'POST': # reqbody['commands'] = request.POST.get('commands').splitlines() reqbody['inventory'] = request.POST.get('inventory') id = request.POST.get('id') requrl = '' confcreator = get_object_or_404(ConfCreator, pk=id) reqbody['network'] = confcreator.network reqbody['commands'] = confcreator.commands.splitlines() if reqbody['network'] == 'EMC': requrl = 'http://200.12.221.13:5000' + '/executecommand' elif reqbody['network'] == 'MTN': requrl = 'http://10.200.96.164:5000' + '/executecommand' headers = {'content-type': 'application/json'} data = {} temp = {} response = '' # data["value"] = "RAI_LND_1Gig_T-SYSTEM_0EV/3_Diessen,OEV/3 Diessen 56 SCF1 . London T7 / 7LB/2 / Port 15.3,DU1400739,RAI-LND,EMC_CORE_RAI_7606_2,GigabitEthernet3/24,10.10.10.71,EMC_CORE_LND_7606_2,GigabitEthernet1/2/1,10.10.10.203,Deutsche Telekom,999-RAI-LON-102-FB-Deutsche_Telekom-(CID-0EV/3-Diessen-1),20,35,40,+49 69 20060 55 58*EMC-DIVEO-XConn-CID:5511206801-MIAMI-BRAZIL-DIVEO-10Mbps-Copper,DU0506772,DU0506772,MIAMI-BRAZIL,EMC_CORE_MIAMI_ASR_2,GigabitEthernet0/0/3.101,10.10.10.226,EMC_CORE_BRAZ_ASR1K1_1,GigabitEthernet0/0/0,10.10.10.50,T-Systems,999-MIAMI-Brazil-101-CO-TSystems-(CID:5511206801_TSYSTEMS,139,144,149,0800160066,55113097-5239" try: response = requests.post(requrl, data=json.dumps(reqbody), headers=headers) # mtnresponse = requests.post(mtnurl, data=json.dumps(data), headers=headers) if not response.status_code == 200: temp['value'] = "Error !! Unexpected response. Please report this" return HttpResponse(json.dumps(temp), content_type="application/json") except requests.exceptions.RequestException as e: # return "Error: {}".format(e) temp['value'] = "Error connecting to API. Please report this" return HttpResponse(json.dumps(temp), content_type="application/json") return HttpResponse(json.dumps(response), content_type="application/json")
def _inventories(request, inventories): paginator = Paginator(inventories, 10) # baseurl="http://127.0.0.1:8000" baseurl = get_vars('baseurl') page = request.GET.get('page') try: inventories = paginator.page(page) except PageNotAnInteger: inventories = paginator.page(1) except EmptyPage: inventories = paginator.page(paginator.num_pages) # popular_tags = Tag.get_popular_tags() return render( request, 'inventories/inventories.html', { 'inventories': inventories, 'baseurl': baseurl, 'inventory': inventories # 'popular_tags': popular_tags })
def _results(request, results): paginator = Paginator(results, 10) # baseurl="http://127.0.0.1:8000" baseurl = get_vars('baseurl') page = request.GET.get('page') try: results = paginator.page(page) except PageNotAnInteger: results = paginator.page(1) except EmptyPage: results = paginator.page(paginator.num_pages) # popular_tags = Tag.get_popular_tags() return render( request, 'results/results.html', { 'results': results, 'baseurl': baseurl, 'result': results # 'popular_tags': popular_tags })
def createresult(request): baseurl = get_vars('baseurl') if request.method == 'POST': result = Result() inventory = request.POST.get('inventory') # inventory = get_object_or_404(Inventory, pk=inventoryid) result.inventory = inventory result.create_user = request.user taskid = request.POST.get('taskid') status = request.POST.get('status') if status in [Result.ACTIVE, Result.DELETED]: result.status = request.POST.get('status') # if not request.POST.get('factfile'): result.factfile = request.POST.get('factfile') if request.POST.get( 'factfile') is not None or request.POST.get('factfile') != '': result.factfile = request.POST.get('factfile') else: result.factfile = "nofile" task = get_object_or_404(Task, pk=taskid) result.task = task result.name = task.name result.description = task.description result.network = task.network result.playbook = task.playbook result.credential = task.credential result.factstatus = task.factstatus result.save() # tags = form.cleaned_data.get('tags') # task.create_tags(tags) # return redirect('/results/') return render(request, 'results/playoutput.html', { 'result': result, 'baseurl': baseurl })
def createinventory(request): if request.method == 'POST': form = InventoryForm(request.POST) if form.is_valid(): inventory = Inventory() inventory.create_user = request.user inventory.name = form.cleaned_data.get('name') inventory.network = form.cleaned_data.get('network') inventory.playbook = form.cleaned_data.get('playbook') inventory.variable = form.cleaned_data.get('variable') inventory.description = form.cleaned_data.get('description') inventory.factstatus = form.cleaned_data.get('factfilerequired') status = form.cleaned_data.get('status') if status in [Inventory.ACTIVE, Inventory.DELETED]: inventory.status = form.cleaned_data.get('status') inventory.save() inventory.filename = form.cleaned_data.get('network') + str( "inv") + str(inventory.id) inventory.save() ansibengineemc = get_vars('ansibengineemc') ansibenginemtn = get_vars('ansibenginemtn') if inventory.network == 'EMC': url = ansibengineemc + '/ansibengine/api/v1.0/altinventory' else: url = ansibenginemtn + '/ansibengine/api/v1.0/altinventory' # url = 'http://200.12.221.13:5555/ansibengine/api/v1.0/altinventory' headers = {'content-type': 'application/json'} temp = {} data = {} data['variable'] = form.cleaned_data.get('network') + str( "inv") + str(inventory.id) data['inventory'] = form.cleaned_data.get('variable') # data='{"variable":"10.10.10.102"}' # data = '{"query":{"bool":{"must":[{"text":{"record.document":"SOME_JOURNAL"}},{"text":{"record.articleTitle":"farmers"}}],"must_not":[],"should":[]}},"from":0,"size":50,"sort":[],"facets":{}}' try: response = requests.post(url, data=json.dumps(data), headers=headers, auth=('netbot', 'N#tB@t')) # if not response.status_code == 201 : # temp['value']="Error!! Unexpected response. Please report this" # return HttpResponse(json.dumps(temp), content_type = "application/json") return redirect('/inventories/') except requests.exceptions.RequestException as e: # return "Error: {}".format(e) # temp['value']="Error connecting to API. Please report this" # return HttpResponse(json.dumps(temp), content_type = "application/json") return redirect('/inventories/') # tags = form.cleaned_data.get('tags') # task.create_tags(tags) return redirect('/inventories/') else: form = InventoryForm() return render(request, 'inventories/createinventory.html', {'form': form})
def emccm(request): baseurl = get_vars('baseurl') return render(request, 'cmapp/emccmapp.html', {'baseurl':baseurl})
def runresult(request): resultid = '' if request.method == 'POST': resultid = request.POST.get('result') test = request.POST.get('test') result = get_object_or_404(Result, pk=resultid) playbook = result.playbook inventory = result.inventory emcpath = '/etc/emcansibout' mtnpath = '/etc/mtnansibout' fact = 'nofile' headers = {'content-type': 'application/json'} ansibengineemc = get_vars('ansibengineemc') ansibenginemtn = get_vars('ansibenginemtn') temp = {} if result.factstatus: if result.network == 'EMC': facturl = ansibengineemc + '/ansibengine/api/v1.0/sharefact' else: facturl = ansibenginemtn + '/ansibengine/api/v1.0/sharefact' fact = result.factfile factdata = {} factdata["fact"] = fact try: factresponse = requests.post(facturl, data=json.dumps(factdata), headers=headers, auth=('netbot', 'N#tB@t')) if not factresponse.status_code == 201: temp[ 'value'] = "Error!! Unexpected response. Please report this" return HttpResponse(json.dumps(temp), content_type="application/json") except requests.exceptions.RequestException as e: # return "Error: {}".format(e) temp['value'] = "Error connecting to API. Please report this" return HttpResponse(json.dumps(temp), content_type="application/json") if result.network == 'EMC': url = ansibengineemc + '/ansibengine/api/v1.0/runplaybook' else: url = ansibenginemtn + '/ansibengine/api/v1.0/runplaybook' temp = {} data = {} # data='{"playbook":"cisco_demo.yml" , "inventory":"dev","resultid":"1000","fact":"factshare.txt"}' data["playbook"] = playbook data["inventory"] = inventory data["resultid"] = resultid data["fact"] = fact try: response = requests.post(url, data=json.dumps(data), headers=headers, auth=('netbot', 'N#tB@t')) if not response.status_code == 201: temp['value'] = "Error!! Unexpected response. Please report this" return HttpResponse(json.dumps(temp), content_type="application/json") except requests.exceptions.RequestException as e: # return "Error: {}".format(e) temp['value'] = "Error connecting to API. Please report this" return HttpResponse(json.dumps(temp), content_type="application/json") stdoutfilename = "stdout" + str(result.id) + ".out" if result.network == 'EMC': stdoutpath = emcpath else: stdoutpath = mtnpath stdoutfile = stdoutpath + "/" + stdoutfilename ####update value in model (equivalent to update query) updateresult = Result.objects.filter(pk=resultid).update( outputfile=stdoutfile) # updateresult = get_object_or_404(Result, pk=resultid) # updateresult.outputfile = stdoutfile # updateresult.save() target = open(stdoutfile, 'w') target.write(response.text) fileRead = open(stdoutfile) Output = fileRead.read() Output = Output.replace("[0;32m", "") Output = Output.replace("[0;31m", "") Output = Output.replace("[0m", " ") Output = Output.replace("\x1b", " ") # data = {} # data['value'] = "va" return HttpResponse(response.text, content_type="application/json")
def getinterfacetraceroute(request): routerip = request.POST.get('sourceip') interfaceip = request.POST.get('sourceint') destip = request.POST.get('destip') vrf = request.POST.get('vrf') network = request.POST.get('network') vrfname = request.POST.get('vrfdropdown') baseurl = get_vars('ansibengineemc') if network.lower() == 'EMC'.lower(): baseurl = get_vars('ansibengineemc') else: baseurl = get_vars('ansibenginemtn') url = baseurl + '/ansibengine/api/v1.0/getinterfacetraceroute' headers = {'content-type': 'application/json'} emcvrfname = getvrflist('emc') if vrf is True: data = {} data['routerip'] = routerip data['interfaceip'] = interfaceip data['destip'] = destip data['vrf'] = "True" data['vrfname'] = vrfname response = requests.post(url, data=json.dumps(data), headers=headers, auth=('netbot', 'N#tB@t')) statuscode = response.status_code if int(statuscode) == 200: return render( request, 'traceroute/inttraceroute.html', { 'task': "task", 'emcvrf': emcvrfname, 'message': "Another task is running! Please wait.." }) else: data = {} data['routerip'] = routerip data['interfaceip'] = interfaceip data['destip'] = destip data['vrf'] = "False" data['vrfname'] = vrfname response = requests.post(url, data=json.dumps(data), headers=headers, auth=('netbot', 'N#tB@t')) statuscode = response.status_code if int(statuscode) == 200: return render( request, 'traceroute/inttraceroute.html', { 'task': "task", 'emcvrf': emcvrfname, 'message': "Another task is running! Please wait.." }) return render(request, 'traceroute/runinterfacetraceroute.html', { 'task': "task", 'baseurl': baseurl })