def search(): if request.method == 'GET' : return render_template("form_submit.html") else: searchOptions = {'macAddrQ' : 'mac', 'deviceTypeQ' : 'device', 'softwareQ' : 'software' } queryType = {'serialNumberQ' : 'Serial Number', 'ipAddrQ': 'IP Address' , 'macAddrQ': 'MAC Address', 'deviceTypeQ': 'Device Type', 'softwareQ': 'Software Type'} option ='' query = request.form['query'] print('Query=', query) if query != 'softwareQ': searchValue = request.form['searchValue'].upper().strip() else: searchValue = '' if (query in searchOptions) : option = request.form[searchOptions[query]] print('queryType =', queryType) print('searchValue =', searchValue) print('option =', option) result = getDevice(startup_vars, query, searchValue, option) print('result=', result) if query in ['softwareQ', 'deviceTypeQ'] : print('queryType[query]=', queryType[query]) print('searchValue=,', searchValue) print('option=', option) #print(' queryType = queryType[query], searchValue=searchValue, option=option, result=result)') return render_template('device_action_list.html', queryType = queryType[query], searchValue=searchValue, option=option, result=result) return render_template('device_action.html', queryType = queryType[query], searchValue=searchValue, option=option, result=result)
def get_serial(searchValue): result = getDevice(startup_vars, 'serialNumberQ', searchValue, '') if not result : result_msg = 'Nothing returned from search. Item %s not found in Prime database.<br/>' % searchValue else: result_msg = 'Summary details for search with Serial Number: %s !<br/>' % searchValue for key, value in result.items() : result_msg += (key + ' : ' + value + '<br/>') print(result_msg) return result_msg
def get_cmac(searchValue): result = getDevice(startup_vars, 'macAddrQ', searchValue, 'client') if not result : result_msg = 'Nothing returned from search. Item %s not found in Prime database.<br/>' % searchValue else: result_msg = 'Summary details for search with mac address: %s !<br/>' % searchValue for key, value in result.items() : result_msg += (key + ' : ' + value + '<br/>') print(result_msg) return result_msg
elif query == 'deviceTypeQ': searchOp = input('Select the search option for Device Type (A, B or C):\nA Equal \nB Starts With \nC Contains') option = searchOp_options[searchOp.upper()] elif query == 'softwareQ' : print('\nA IOS \nB IOS-XE \nC NX-OS \nD Cisco Controller') software = input('Select the software type (A, B or C):') option = software_options[software.upper()] searchValue ='' if not query == 'softwareQ' : searchValue = input('\nEnter search value:\n').upper().strip() print('query is:', query) print('option is:', option) print('searchValue is:', searchValue) result = getDevice(startup_vars, query, searchValue, option) if query in ['serialNumberQ', 'ipAddrQ', 'macAddrQ'] : print('\n\nSummary details for search with', queryType[query], ':', searchValue, '!') for key, value in result.items() : print(key, ' : ', value) if query in ['softwareQ', 'deviceTypeQ'] : print('Total records found: ', len(result), '\n\n') for record in range(len(result)) : print('Record Number: ', record + 1) print('----------------------------------------\n') for key, value in result[record].items() : print(key, ':', value)
def display_options(): startup_vars = check_startup(spark_bot=False) print('From __main__: startup_vars=', startup_vars) print('new startup_vars =', startup_vars) query_options = { 'macAddrQ': macVar.get(), 'deviceTypeQ': dtypeVar.get(), 'softwareQ': stypeVar.get() } queryType = { 'serialNumberQ': 'Serial Number', 'ipAddrQ': 'IP Address', 'macAddrQ': 'MAC Address', 'deviceTypeQ': 'Device Type', 'softwareQ': 'Software Type' } query = query_gui.get() searchValue = searchValue_gui.get() if query not in ['serialNumberQ', 'ipAddrQ']: option = query_options[query.get()] if 'Network' in option: option = 'network' elif 'Client' in option: option = 'client' else: option = '' ''' Label(gui, text='').grid(row=22) Label(gui, text='').grid(row=23) Label(gui, text='').grid(row=24) Label(gui, text='Variable Selection:', font=("Arial", 18)).grid(row=25, column=0, sticky=W) start_row = 26 for key, value in entries.items(): print(start_row) print(key, value) Label(gui, text=key, width=15, borderwidth=2, relief=SUNKEN).grid(row=start_row, column=0, ipadx=30) Label(gui, text=value, width=15, borderwidth=2, relief=SUNKEN).grid(row=start_row, column=1, ipadx=30) start_row = start_row +1 ''' print('query is:', query) print('option is:', option) print('searchValue is:', searchValue) result = getDevice(startup_vars, query, searchValue, option) height = str(500 + (len(result)) * 20) print('height = ', height) gui.geometry('550x' + height) Label(gui, text='').grid(row=22) Label(gui, text='').grid(row=23) if query in ['serialNumberQ', 'ipAddrQ', 'macAddrQ']: print('\n\nSummary details for search with', queryType[query], ':', searchValue, '!') query_text = 'Summary details for search with ' + queryType[ query] + ': ' + searchValue + '!' print(('query_text = ', query_text)) Label(gui, text=query_text, font=("Arial", 18)).grid(row=24, column=0, sticky=W) Label(gui, text='').grid(row=25) for key, value in result.items(): print(key, ' : ', value) start_row = 26 for key, value in result.items(): print(start_row) print(key, value) Label(gui, text=key, width=15, borderwidth=2, relief=SUNKEN).grid(row=start_row, column=0, sticky=E) Label(gui, text=value, width=45, borderwidth=2, relief=SUNKEN).grid(row=start_row, column=1, sticky=W) start_row = start_row + 1 if query in ['softwareQ', 'deviceTypeQ']: print('Total records found: ', len(result), '\n\n') for record in range(len(result)): print('Record Number: ', record + 1) print('----------------------------------------\n') for key, value in result[record].items(): print(key, ':', value) print('\n\n') if not result: print('Nothing returned from search. Item', searchValue, 'not found in Prime database.')