def index(self): """ Show about information :return: """ global sdb apic_object_dn = str(request.args.get('dn')) if sdb.by_attr == {}: apic_args = APICArgs(session['ipaddr'], session['username'], session['secure'], session['password']) sdb = SearchDb.load_db(apic_args) if apic_object_dn != 'None': atk_object_info = sdb.get_object_info(apic_object_dn) else: atk_object_info = sdb.get_object_info('/') return self.render('atk_object_view.html', result=atk_object_info)
action='store_true') args = parser.parse_args() # start the flask application and tell it the static folder is called 'static' app = Flask(__name__, static_folder='static') # todo: need to validate the secrete key app.config['SECRET_KEY'] = 'Dnit7qz7mfcP0YuelDrF8vLFvk0snhwP' app.config['CSRF_ENABLED'] = True CsrfProtect(app) bootstrap = Bootstrap(app) # Create the ACI Search Database sdb = SearchDb() class APICArgs(object): """ Class to hold the Arguments of the APIC """ def __init__(self, ipaddr, username, secure, password): self.login = username self.password = password if ipaddr is not None: if secure is True: self.url = 'https://' + ipaddr else: self.url = 'http://' + ipaddr else:
def index(self): """ Allow user to select which report to show. :return: """ global sdb form = SearchBar() report = {} # object view data apic_object_dn = str(request.args.get('dn')) if apic_object_dn is not None: if sdb.by_attr == {}: try: apic_args = APICArgs(session['ipaddr'], session['username'], session['secure'], session['password']) except KeyError: return redirect(url_for('credentialsview.index')) try: sdb = SearchDb.load_db(apic_args) except Timeout: flash('Connection timeout when trying to reach the APIC', 'error') return redirect(url_for('switchreportadmin.index_view')) except LoginError: flash('Unable to login to the APIC', 'error') return redirect(url_for('credentialsview.index')) except ConnectionError: flash('Connection failure. Perhaps \'secure\' setting is wrong') return redirect(url_for('credentialsview.index')) if apic_object_dn != 'None': atk_object_info = sdb.get_object_info(apic_object_dn) else: atk_object_info = sdb.get_object_info('/') else: atk_object_info = 'None' # load data from file if it has not been otherwise loaded if sdb.by_attr == {}: apic_args = APICArgs(session['ipaddr'], session['username'], session['secure'], session['password']) try: sdb = SearchDb.load_db(apic_args) except Timeout: flash('Connection timeout when trying to reach the APIC', 'error') return redirect(url_for('switchreportadmin.index_view')) except LoginError: flash('Unable to login to the APIC', 'error') return redirect(url_for('credentialsview.index')) except ConnectionError: flash('Connection failure. Perhaps \'secure\' setting is wrong') return redirect(url_for('credentialsview.index')) if form.validate_on_submit() and form.submit.data: try: report = sdb.get_search_result(form.data['search_field']) except Timeout: flash('Connection timeout when trying to reach the APIC', 'error') return redirect(url_for('switchreportadmin.index_view')) except LoginError: flash('Unable to login to the APIC', 'error') return redirect(url_for('credentialsview.index')) except ConnectionError: flash('Connection failure. Perhaps \'secure\' setting is wrong') return redirect(url_for('credentialsview.index')) if report != {}: return self.render('search_result.html', form=form, report=report, class_attr_values=[list(elem) for elem in sorted(sdb.by_class_attr_value.keys())], result=atk_object_info) else: return self.render('search_result.html', form=form, class_attr_values=[list(elem) for elem in sorted(sdb.by_class_attr_value.keys())], result=atk_object_info)