コード例 #1
0
def parse_poch_interface(form, mode, device, password, username):
    """Parse, build, send info for trunk configuration"""

    # Convert interface number back to slashes from %2f

    if form.get("pochCustomForm"):
        status = send_config_cli(device, username, password,
                                 form.get('pochCustomForm'))
        DbOps.update_configurations(device, username,
                                    form.get('pochCustomForm'),
                                    'Add Link to Portchannel')
    else:
        int_num = [
            i for i in form.get("interface") if i not in string.ascii_letters
        ]
        int_type = [
            i for i in form.get("interface") if i in string.ascii_letters
        ]
        config = build_porch_link(''.join(int_type) + ''.join(int_num),
                                  form.get('pochannel'), mode)
        status = send_config(device, username, password, config)
        DbOps.update_configurations(device, username, config,
                                    'Add Link to Portchannel')

    return status
コード例 #2
0
def parse_int_form(form, device, password, username):
    """Parse, build, send info for interface configuration"""

    ip, mask, status, descr, vrf, switchport = None, None, None, None, None, None

    if not form.get('newIntCustomForm'):
        if form.get('ip') and form.get('mask'):
            ip = form.get('ip')
            mask = form.get('mask')
        if form.get('status'):
            status = form.get('status')
        if form.get('description'):
            descr = form.get('description')
        if form.get('vrf'):
            vrf = form.get('vrf')
        if form.get('negotiation'):
            negotiation = form.get('negotiation')
        if form.get('vlan'):
            negotiation = form.get('negotiation')
        if form.get('switchport'):
            switchport = form.get('switchport')

        # Convert interface number back to slashes from %2f
        int_num = [
            i for i in form.get("interface") if i not in string.ascii_letters
        ]
        int_type = [
            i for i in form.get("interface") if i in string.ascii_letters
        ]

        # Validate interface perameters
        validation = ValidateConfig.validate_interface(
            ''.join(int_type) + ''.join(int_num), ip, mask, status, vrf, descr,
            QueryDbFor.query_interfaces(device))
        config = build_interface(''.join(int_type) + ''.join(int_num), ip,
                                 mask, status, vrf, descr, switchport)
        # If validation passes which is 0, send config, update DB
        if validation == 0:
            status = send_config(device, username, password, config)
            DbOps.update_configurations(device, username, config,
                                        "Modify/Add Interface")
    else:
        status = send_config_cli(device, username, password,
                                 form.get('newIntCustomForm'))
        DbOps.update_configurations(device, username,
                                    form.get('newIntCustomForm'),
                                    "Modify/Add Interface")

    return status
コード例 #3
0
def parse_add_vlan_form(form, device, password, username):
    """Parse, build, send info for vlan configuration"""

    if not form.get('vlanCustomForm'):
        config = build_vlan(form.get('vlanId'), form.get('vlanName'),
                            form.get('action'))
        status = send_config_cli(device, username, password, config)
        DbOps.update_configurations(device, username, config, 'Vlan')
    else:
        status = send_config_cli(device, username, password,
                                 form.get('vlanCustomForm'))
        DbOps.update_configurations(device, username,
                                    form.get('vlanCustomForm'), 'Vlan')

    return status
コード例 #4
0
def parse_trunk_interface(form, device, password, username):
    """Parse, build, send info for trunk configuration"""

    if form.get("trunkCustomForm"):
        status = send_config_cli(device, username, password,
                                 form.get("trunkCustomForm"))
        DbOps.update_configurations(device, username,
                                    form.get("trunkCustomForm"),
                                    'Modify Trunk')
    else:
        config = build_add_trunk_vlan(''.join(int_type) + ''.join(int_num),
                                      form.get('vlan'), form.get('action'))
        # Convert interface number back to slashes from %2f
        int_num = [
            i for i in form.get("interface") if i not in string.ascii_letters
        ]
        int_type = [
            i for i in form.get("interface") if i in string.ascii_letters
        ]
        status = send_config(device, username, password, config)
        DbOps.update_configurations(device, username, config, 'Modify Trunk')

    return status
コード例 #5
0
def parse_access_int_form(form, device, password, username):
    """Parse, build, send info for access interface configuration"""

    vlan, descr, status, voice_vlan = None, None, None, None

    if not form.get('vlanCustomForm'):
        if form.get('status'):
            status = form.get('status')
        if form.get('description'):
            descr = form.get('description')
        if form.get('vlan'):
            vlan = form.get('vlan')
        if form.get('voiceVlan') != 'None':
            voice_vlan = form.get('voiceVlan')
        else:
            voice_vlan = None

        # Convert interface number back to slashes from %2f
        int_num = [
            i for i in form.get("interface") if i not in string.ascii_letters
        ]
        int_type = [
            i for i in form.get("interface") if i in string.ascii_letters
        ]

        # Build and send config, updated DB
        status = send_config(device, username, password, config)
        DbOps.update_configurations(device, username, config,
                                    'Modify Access Interface')
    else:
        status = send_config_cli(device, username, password,
                                 form.get('vlanCustomForm'))
        DbOps.update_configurations(device, username,
                                    form.get('vlanCustomForm'),
                                    'Modify Access Interface')

    return status
コード例 #6
0
def parse_routing_config(form, device, password, username):
    """Parse, build, and send new routing configuration"""

    # Proccess for data from input fields
    if request.form.get("process") is not None:
        config = BuildConfig.build_ospf(request.form.get("process"),
                                        request.form.get("neighbor"),
                                        request.form.get("wildcard"),
                                        request.form.get("area"))
        status = BuildConfig.send_config(device, username, password, config)
        DbOps.update_configurations(device, username, config, 'Ospf')

    elif request.form.get("remoteAs") is not None:
        config = BuildConfig.build_bgp(
            request.form.get("neighborId"),
            request.form.get("remoteAs"),
            request.form.get("softReconfig"),
            request.form.get("nextHop"),
            policy=[request.form.get("direction"),
                    request.form.get("policy")])
        status = BuildConfig.send_config(device, username, password, config)
        DbOps.update_configurations(device, username, config, 'Bgp')

    # Proccess for data from input field TEXT AREA
    if request.form.get("bgpCustomForm") is not None:
        status = BuildConfig.send_config(device, username, password,
                                         request.form.get("bgpCustomForm"))
        DbOps.update_configurations(device, username,
                                    request.form.get("bgpCustomForm"), 'Bgp')

    elif request.form.get("ospfCustomForm") is not None:
        status = BuildConfig.send_config(device, username, password,
                                         request.form.get("ospfCustomForm"))
        DbOps.update_configurations(device, username,
                                    request.form.get("ospfCustomForm"), 'Ospf')

    return status