def vlan_member(hostname): device = db.get_or_404(hostname) interfaces = device.get_interfaces() vlans = device.vlans() return render_template('vlan.html', hostname=hostname, device=device, vlans=vlans, interfaces=interfaces)
def vlan_member_save(hostname): if request.method == 'POST': device = db.get_or_404(hostname) # sanity checks # len(form) == num_of_ports * num_of_vids interfaces = device.get_interfaces() vlans = device.vlans() num_of_vids = len(vlans) num_of_ports = len(vlans) return redirect(url_for('.vlan_member', hostname=hostname))
def vlan_delete(hostname, id): device = db.get_or_404(hostname) if request.method == "POST": vlan_id = request.form.get('VLAN_ID_TO_REMOVE', None) if vlan_id == id: try: device.vlan_remove(vlan_id) except: flash("remove failed") return redirect(url_for('.detail', hostname=hostname))
def port_remove_vlan(hostname, idx): device = db.get_or_404(hostname) port = device.get_port(idx) if request.method == 'POST': if request.form.get('vlan', None) is not None: # we add only tagged vlan for now vlan_id = request.form.get('vlan') port.get_vlantable(vlan_id).set_port_status(port.idx(), 'n') flash("VLAN {0} (tagged) removed".format(str(vlan_id))) return redirect(url_for('.port_detail', hostname=hostname, idx=idx))
def port_detail(hostname, idx): device = db.get_or_404(hostname) vlans = device.vlans() port = device.get_port(idx) vlan_membership = vlans.get_port_membership(idx) return render_template('port.html', hostname=hostname, device=device, vlans=vlans, port=port, vlan_membership=vlan_membership)
def vlan_edit(hostname, id): device = db.get_or_404(hostname) if request.method == "POST": vlan_id = request.form.get('VLAN_ID_TO_RENAME', None) vlan_name = request.form.get('VLAN_NEW_NAME', None) if vlan_id == id and vlan_name: try: device.vlan_rename(int(vlan_id), vlan_name) except: flash("rename failed") return redirect(url_for('.detail', hostname=hostname))
def vlan_create(hostname): device = db.get_or_404(hostname) if request.method == "POST": vlan_name = request.form.get('VLAN_NAME', None) vlan_id = request.form.get('VLAN_ID', None) if vlan_name and vlan_id: try: device.vlan_create(vlan_id, vlan_name) except: flash("Failed to add VLAN") else: flash("Wrong input") return redirect(url_for('.detail', hostname=hostname))
def port_save(hostname, idx): device = db.get_or_404(hostname) port = device.get_port(idx) if request.method == 'POST': auth_vid = request.form.get('AUTHVID', None) unauth_vid = request.form.get('UNAUTHVID', None) port_auth = True if request.form.get('802.1x-enabled', 2) == '1' else False port.set_port_auth(port_auth, auth_vid, unauth_vid) # set alias if request.form.get('ifalias', None) is not None: port.set_alias(request.form.get('ifalias', None)) flash("Port Auth saved") return redirect(url_for('.port_detail', hostname=hostname, idx=idx))
def detail(hostname): device = db.get_or_404(hostname) device.ports().update() if request.method == 'POST': if request.form.get('802.1x-enabled', False): value = request.form.get('802.1x-enabled') setauth = True if value == "1" else False print ("setting port auth", setauth) device.set_port_auth_enabled(setauth) for key, value in request.form.items(): if key.startswith('port-auth-'): idx = int(key.split('-')[-1]) port_auth_enabled = True if value == "true" else False port = device.ports().port(idx) port.set_port_auth(port_auth_enabled) if port.has_port_auth() and not port_auth_enabled: port.set_port_auth(False) print("Set port {} to NOAUTH".format(port.idx())) if not port.has_port_auth() and port_auth_enabled: port.set_port_auth(True) print("Set port {} to AUTH".format(port.idx())) return redirect("/switch/{}".format(hostname)) return render_template('detail.html', device=device)
def detail(hostname): device = db.get_or_404(hostname) device.ports().update() if request.method == 'POST': if request.form.get('802.1x-enabled', False): value = request.form.get('802.1x-enabled') setauth = True if value == "1" else False print("setting port auth", setauth) device.set_port_auth_enabled(setauth) for key, value in request.form.items(): if key.startswith('port-auth-'): idx = int(key.split('-')[-1]) port_auth_enabled = True if value == "true" else False port = device.ports().port(idx) port.set_port_auth(port_auth_enabled) if port.has_port_auth() and not port_auth_enabled: port.set_port_auth(False) print("Set port {} to NOAUTH".format(port.idx())) if not port.has_port_auth() and port_auth_enabled: port.set_port_auth(True) print("Set port {} to AUTH".format(port.idx())) return redirect("/switch/{}".format(hostname)) return render_template('detail.html', device=device)