def main_return():
    # Get user informaation
    creds = Sidekick.objects.first()
    user = creds.user
    ipaddress= creds.ipaddress

    # Insert chart data
    charts=build_charts()

    # Get switch information switch database
    switch_array=get_switches()

    return render_template('main/sidekick1.html',u=user,i=ipaddress,g1_data=charts[0],g2_data=charts[1],s=switch_array)
Beispiel #2
0
def newterm():
    '''
    Saves the cloned record

    '''
    os.system("mate-terminal")
    # Return Main menu
    # Get user informaation
    creds=Companion.objects.first()
    user=creds.user
    ipaddress=creds.ipaddress

    # Insert chart data
    charts=build_charts()

    # Get switch information switch database
    switch_array=get_switches()

    return render_template('main/companion1.html',u=user,i=ipaddress,g1_data=charts[0],g2_data=charts[1],s=switch_array)
def autolag():

    # Clear ports database on new session.
    Ports.objects().delete()

    # Clear ports database on new session.
    b_Ports.objects().delete()

    switch_list_out = []
    switch_list = []

    vlan_list_out = []
    vlan_list = []

    # Get a client connection.
    switches = get_switches()
    for switch in switches:
        switch_name = switch[3].encode('utf-8')
        switch_uuid = switch[5].encode('utf-8')
        switch_list = [switch_name, switch_uuid]
        switch_list_out.append(switch_list)

    # Get a client connection.
    vlans = get_vlans()
    for vlan in vlans:
        vlansx = vlan['vlans'].encode('utf-8')
        uuid = vlan['uuid'].encode('utf-8')
        vlan_list = [vlansx, uuid]
        vlan_list_out.append(vlan_list)

    count = [
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
        21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
        39, 40, 41, 42, 43, 44, 45, 46, 47, 48
    ]

    return render_template('lags/autolag.html',
                           switches=switch_list_out,
                           vlans=vlan_list_out,
                           count=count)
def snmp_interface():
    '''
    Edit an existing entry from the database

    '''
    if request.method == 'POST':
        # Get number of interfaces.

        # Get desired switch_ip
        ipaddress = request.form['ipaddress']

        # Perform the SNMP gets
        ifDesc = get_ifDesc_oids(ipaddress)
        ifType = get_ifType_oids(ipaddress)
        ifMtu = get_ifMtu_oids(ipaddress)
        ifSpeed = get_ifSpeed_oids(ipaddress)
        ifAdminStatus = get_ifAdminStatus_oids(ipaddress)
        ifOperStatus = get_ifOperStatus_oids(ipaddress)
        ifInUcastPkts = get_ifInUcastPkts_oids(ipaddress)
        ifOutUcastPkts = get_ifOutUcastPkts_oids(ipaddress)

        output = []
        counter = 0
        while counter < len(ifDesc):
            # Check the type
            if ifType[counter] == '6':
                XifType = 'Access'
            else:
                XifType = 'Fabric'

            # Check the Admin status
            if ifAdminStatus[counter] == '1':
                XifAdminStatus = 'up'
            elif ifAdminStatus[counter] == '2':
                XifAdminStatus = 'down'
            else:
                XifAdminStatus = 'unknown'

            # Check the operation status
            if ifOperStatus[counter] == '1':
                XifOperStatus = 'up'
            elif ifOperStatus[counter] == '2':
                XifOperStatus = 'down'
            else:
                XifOperStatus = 'unknown'

            interface = {
                'interface': counter + 1,
                'ifDesc': ifDesc[counter],
                'ifType': XifType,
                'ifMtu': ifMtu[counter],
                'ifSpeed': ifSpeed[counter],
                'ifAdminStatus': XifAdminStatus,
                'ifOperStatus': XifOperStatus,
                'ifInUcastPkts': ifInUcastPkts[counter],
                'ifOutUcastPkts': ifOutUcastPkts[counter]
            }

            output.append(interface)
            counter = counter + 1

        #send delete success
        return render_template('snmp/interfaces.html',
                               output=output,
                               ipaddress=ipaddress)

    # Get switch information switch database

    switch_array = get_switches()

    ips = []
    for switch in switch_array:
        ips.append(switch[1])

    return render_template('snmp/snmp_select_switch.html',
                           switch_ip_list=ips,
                           s=switch_array)