Ejemplo n.º 1
0
 def operation(self, ip, community, version):
     temp_walk = Devices.Devices(community, version)
     self.result_desc = temp_walk.walkthrongh(ip, self.IFDESCR)
     self.result_Type = temp_walk.walkthrongh(ip, self.IFTYPE)
     self.result_Mtu = temp_walk.walkthrongh(ip, self.IFMTU)
     self.result_Speed = temp_walk.walkthrongh(ip, self.IFSPEED)
     self.result_Admin = temp_walk.walkthrongh(ip, self.IFADMINSTATUS)
     self.result_Opera = temp_walk.walkthrongh(ip, self.IFOPERSTATUS)
     self.removeDWDM()
Ejemplo n.º 2
0
    def config_ip_addr(*args):
        """args[0] is Router name ex., R1
           args[1] is Router link ex., Link_R1_R2
           args[2] has options 'configure'/ """

        dev = Devices.Devices()
        sys.stdout.write("Configuring IP address for %s" % args[0])
        status  = dev.set_IP(args[0],args[1],args[2])
        if status is False:
            sys.stdout.write("Configuration of IP Address for %s Failed" % args[0])
        else:
            sys.stdout.write("Configured  IP Address for %s" % args[0])
Ejemplo n.º 3
0
    def route(self, Device, AS_id, Interface):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)
        if (child):

            clear_buffer.flushBuffer(10, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([
                hostname + '>', hostname + '#', 'Router\>', 'Router\#',
                pexpect.EOF, pexpect.TIMEOUT
            ],
                                timeout=90)
            #print 'flag =%d' % flag
            if flag == 0 or flag == 2:
                Dev.Login(Device, child)
                configs = """
				configure terminal
				router bgp %d
				neighbor %s next-hop-self
				end
				""" % (AS_id, Interface)
                commands = configs.split('\n')
                execute.execute(child, commands)
                #time.sleep(5)
                child.sendcontrol('m')
            #	print "BGP synchronization enabled in %s " % (Device)

            if flag == 1 or flag == 3:
                configs = """
				configure terminal
				router bgp %d
				neighbor %s next-hop-self
				end
				""" % (AS_id, Interface)
                commands = configs.split('\n')
                execute.execute(child, commands)
                #time.sleep(5)
                child.sendcontrol('m')
            #	print "BGP synchronization enabled in %s " % (Device)

            #else:
            #	print 'Expected prompt not found'

            return True

        else:
            return False
Ejemplo n.º 4
0
    def redistribution(self, Device, AS_id, Process_id=None):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)
        if (child):

            clear_buffer.flushBuffer(10, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([
                hostname + '>', hostname + '#', 'Router\>', 'Router\#',
                pexpect.EOF, pexpect.TIMEOUT
            ],
                                timeout=90)
            if flag == 0 or flag == 2:
                Dev.Login(Device, child)
                configs = """
				configure terminal
				router bgp %d
				redistribute ospf %d
				exit
				router ospf %d
				redistribute bgp %d subnets
				end
				""" % (AS_id, Process_id, Process_id, AS_id)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            if flag == 1 or flag == 3:
                configs = """
				configure terminal
				router bgp %d
				redistribute ospf %d
				exit
				router ospf %d
				redistribute bgp %d subnets
				end
				""" % (AS_id, Process_id, Process_id, AS_id)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            return True

        else:
            return False
Ejemplo n.º 5
0
def readDevices():
    res = os.popen('wmic /output:devices.csv diskdrive list brief /format:csv')
    res.close()
    reader = csv.reader(open('devices.csv', encoding='UTF-16LE'))
    startIndex = 0
    devices = list()
    for tmp in reader:
        startIndex += 1
        if startIndex > 2:
            size = int(int(tmp[5]) / 1024 / 1024 / 1024)
            device = Devices(tmp[1], tmp[2], tmp[3], str(size) + 'G')
            devices.append(device)

    return devices
Ejemplo n.º 6
0
def checking_operabilty(Device, command):
    device_data = getdata.get_data()
    hostname = device_data['Device_Details'][Device]['Hostname']
    Dev = Devices.Devices()
    child = Dev.connect(Device)
    if child:

      clear_buffer.flushBuffer(1, child)
      child.sendcontrol('m')
      child.sendcontrol('m')
      child.sendcontrol('m')
      flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#',\
             pexpect.EOF, pexpect.TIMEOUT], timeout=90)
      if flag in (0, 2):
        Dev.Login(Device, child)
        configs = """
        %s
        """ % (command)
        commands = configs.split('\n')
        execute.execute(child, commands)
        resp = child.before.decode('utf-8')
        child.sendcontrol('m')
        child.sendcontrol('m')
        regex = r'up'
        if re.search(regex, resp):
          return True
        else:
          return False

      if flag in (1, 3):
        configs = """
        %s
        """ % (command)
        commands = configs.split('\n')
        execute.execute(child, commands)
        resp = child.before.decode('utf-8')
        child.sendcontrol('m')
        child.sendcontrol('m')
        regex = r'up'
        if re.search(regex, resp):
          return True
        else:
          return False

      return True

    else:
      return False
Ejemplo n.º 7
0
    def Configure_ebgpvrf(self, Device, AS_id, VRF_Name, Interface,
                          neighbor_AS_id, Action):
        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)

        if child:
            clear_buffer.flushBuffer(1, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \
                     pexpect.EOF, pexpect.TIMEOUT], timeout=90)
            if flag in (1, 3):
                Dev.Login(Device, child)
                if Action == 'enable':
                    configs = """
                        configure terminal
                        router bgp %d
                        address-family ipv4 vrf %s
                        neighbor %s remote-as %s
                        neighbor %s activate     
                        exit-address-family
                        end
                        """ % (AS_id, VRF_Name, Interface, neighbor_AS_id,
                               Interface)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    time.sleep(6)
                    child.sendcontrol('m')
                    child.sendline('exit')
                    child.sendcontrol('m')

                else:
                    unconfig = """
                    configure terminal
                    no router bgp %s
                    end
                    """ % (AS_id)
                    commands = unconfig.split('\n')
                    execute.execute(child, commands)
                    child.sendcontrol('m')

                return True

        else:
            return False
Ejemplo n.º 8
0
def checking_operabilty(Device, command):
    device_data = getdata.get_data()
    hostname = device_data['Device_Details'][Device]['Hostname']
    Dev = Devices.Devices()
    child = Dev.connect(Device)
    if (child):

        clear_buffer.flushBuffer(10, child)
        child.sendcontrol('m')
        child.sendcontrol('m')
        child.sendcontrol('m')
        flag = child.expect([
            hostname + '>', hostname + '#', 'Router\>', 'Router\#',
            pexpect.EOF, pexpect.TIMEOUT
        ],
                            timeout=90)
        #print 'flag =%d' % flag
        if flag == 0 or flag == 2:
            Dev.Login(Device, child)
            configs = """
				%s
				""" % (command)
            commands = configs.split('\n')
            execute.execute(child, commands)
            #time.sleep(15)
            child.sendcontrol('m')
        #	print "BGP synchronization enabled in %s " % (Device)

        if flag == 1 or flag == 3:
            configs = """
				%s
				""" % (command)
            commands = configs.split('\n')
            execute.execute(child, commands)
            #time.sleep(15)
            child.sendcontrol('m')
        #	print "BGP synchronization enabled in %s " % (Device)

        #else:
        #	print 'Expected prompt not found'

        return True

    else:
        return False
Ejemplo n.º 9
0
    def route(self, Device, AS_id, Interface):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)
        if (child):

            clear_buffer.flushBuffer(10, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([
                hostname + '>', hostname + '#', 'Router\>', 'Router\#',
                pexpect.EOF, pexpect.TIMEOUT
            ],
                                timeout=90)
            if flag == 0 or flag == 2:
                Dev.Login(Device, child)
                configs = """
				configure terminal
				router bgp %d
				neighbor %s next-hop-self
				end
				""" % (AS_id, Interface)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            if flag == 1 or flag == 3:
                configs = """
				configure terminal
				router bgp %d
				neighbor %s next-hop-self
				end
				""" % (AS_id, Interface)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            return True

        else:
            return False
    def save_device(self, request, access_token, refresh_token):
        """
        Create a new device instance.
        Args:
            request.
            access_token.
            refresh_token.

        Returns:
            new device instance.
        """
        device = Devices.objects.filter(device_token=request.headers[DEVICE_TOKEN_HEADER]).first()
        if device is not None:
            to_delete = AccessToken.objects.get(pk=device.access_token.id)
            device.access_token = access_token
            device.refresh_token = refresh_token
            device.user = request.user
            device.language = request.headers['HTTP_ACCEPT_LANGUAGE']
            device.save()
            to_delete.delete()
        else:
            application_arn = self.get_application_arn(request)
            device = Devices(device_token=request.headers[DEVICE_TOKEN_HEADER],
                             user=request.user,
                             access_token=access_token,
                             refresh_token=refresh_token,
                             language=request.headers['HTTP_ACCEPT_LANGUAGE'])

            operational_system = device.ANDROID \
                if application_arn == settings.ANDROID_ARN \
                else device.iOS

            device.operational_system = operational_system
            awsclient = boto3.client('sns')

            response = awsclient.create_platform_endpoint(
                PlatformApplicationArn=application_arn,
                Token=device.device_token,
            )

            device.arn = response['EndpointArn']
            return device.save()
Ejemplo n.º 11
0
    def enable_syn(self, Device, AS_id):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)
        if child:

            clear_buffer.flushBuffer(1, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \
                    pexpect.EOF, pexpect.TIMEOUT], timeout=90)
            if flag in (0, 2):
                Dev.Login(Device, child)
                configs = """
                configure terminal
                router bgp %d
                synchronization
                end
                """ % (AS_id)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            if flag in (1, 3):
                configs = """
                configure terminal
                router bgp %d
                synchronization
                end
                """ % (AS_id)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            return True

        else:
            return False
Ejemplo n.º 12
0
    def advertising_loopback(self, Device, AS_id, Interface, mask):
        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)
        if child:

            clear_buffer.flushBuffer(10, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \
                   pexpect.EOF, pexpect.TIMEOUT], timeout=90)
            if flag in (0, 2):
                Dev.Login(Device, child)
                configs = """
                configure terminal
                router bgp %d
                network %s mask %s
                end
                """ % (AS_id, Interface, mask)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            if flag in (1, 3):
                configs = """
                configure terminal
                router bgp %d
                network %s mask %s
                end
                """ % (AS_id, Interface, mask)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            return True

        else:
            return False
Ejemplo n.º 13
0
def singleOutput():
    print '''
        <table class="table is-bordered is-narrow is-fullwidth">
          <tr>
            <th>OID</th>
            <th>Description</th>
          </tr>
        '''
    # --------------------------------------------------------------
    user = Devices.Devices(community, 2)
    user.main(ipList, community, 2, mib)

    for item in user.result:
        print '<tr class="is-selected"><td><strong>' + mib.upper(
        ) + '</strong></td><td></td></tr>'
        for x in range(len(item)):
            if item[x].value != '':
                if (item[x].snmp_type).upper() == 'TICKS':
                    t_item = tools.humanize(int(item[x].value))
                else:
                    t_item = item[x].value
                print '<tr><td>' + item[
                    x].oid + '</td><td>' + t_item + '</td></tr>'
Ejemplo n.º 14
0
def checking_operabilty(Device, command):
    device_data = getdata.get_data()
    hostname = device_data['Device_Details'][Device]['Hostname']
    Dev = Devices.Devices()
    child = Dev.connect(Device)
    if (child):

        clear_buffer.flushBuffer(10, child)
        child.sendcontrol('m')
        child.sendcontrol('m')
        child.sendcontrol('m')
        flag = child.expect([
            hostname + '>', hostname + '#', 'Router\>', 'Router\#',
            pexpect.EOF, pexpect.TIMEOUT
        ],
                            timeout=90)
        if flag == 0 or flag == 2:
            Dev.Login(Device, child)
            configs = """
				%s
				""" % (command)
            commands = configs.split('\n')
            execute.execute(child, commands)
            child.sendcontrol('m')

        if flag == 1 or flag == 3:
            configs = """
				%s
				""" % (command)
            commands = configs.split('\n')
            execute.execute(child, commands)
            child.sendcontrol('m')

        return True

    else:
        return False
Ejemplo n.º 15
0
    def redistribution_connected(self, Device, AS_id):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)
        port = device_data['Device_Details'][Device]['port']

        if port != "zebra":
            if child:

                clear_buffer.flushBuffer(1, child)
                child.sendcontrol('m')
                child.sendcontrol('m')
                child.sendcontrol('m')
                flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \
                       pexpect.EOF, pexpect.TIMEOUT], timeout=90)
                if flag in (0, 2):
                    Dev.Login(Device, child)
                    configs = """
                                  configure terminal
                                  router bgp %d
                                  redistribute connected
                                  end
                                  """ % (AS_id)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    child.sendcontrol('m')

                if flag in (1, 3):
                    configs = """
                                  configure terminal
                                  router bgp %d
                                  redistribute connected
                                  end
                                  """ % (AS_id)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    child.sendcontrol('m')

                return True

        elif port == 'zebra':
            port = "bgpd"
            device_data = getdata.get_data()
            IP_add = device_data['Device_Details'][Device]['ip_add']
            child = pexpect.spawn('telnet ' + IP_add + ' ' + port)
            hostname = device_data['Device_Details'][Device]['Hostname']
            clear_buffer.flushBuffer(1, child)

            child.sendcontrol('m')
            flag = (child.expect(['bgpd*', 'Password*', pexpect.EOF,\
                    pexpect.TIMEOUT], timeout=100))
            if flag == 1:
                child.send('zebra')
                child.sendcontrol('m')
                flag = child.expect(['bgpd*>', pexpect.EOF,\
                       pexpect.TIMEOUT], timeout=50)
                if flag == 0:
                    child.send('enable')
                    child.sendcontrol('m')

                if child:

                    clear_buffer.flushBuffer(1, child)
                    child.sendcontrol('m')
                    child.sendcontrol('m')
                    child.sendcontrol('m')
                    flag = child.expect(['bgpd#*', pexpect.EOF, \
                           pexpect.TIMEOUT], timeout=90)
                    if flag in (0, 2):
                        Dev.Login(Device, child)
                        configs = """
                             configure terminal
                             router bgp %d
                             redistribute connected
                             end
                             """ % (AS_id)
                        commands = configs.split('\n')
                        execute.execute(child, commands)
                        child.sendcontrol('m')

                    if flag in (1, 3):
                        configs = """
                             configure terminal
                             router bgp %d
                             redistribute connected
                             end
                             """ % (AS_id)
                        commands = configs.split('\n')
                        execute.execute(child, commands)
                        child.sendcontrol('m')

                    return True
        else:
            return False
Ejemplo n.º 16
0
    def Configure_IBGP(self, Device, AS_id, Interface, Action):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)

        if child:

            clear_buffer.flushBuffer(1, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \
                     pexpect.EOF, pexpect.TIMEOUT], timeout=90)
            if flag in (0, 2):
                Dev.Login(Device, child)
                if Action == 'enable':
                    if isinstance(Interface, list):
                        for interface in Interface:
                            configs = """
                                configure terminal
                                router bgp %d
                                neighbor %s remote-as %d
                                neighbor %s update-source loopback 0
                                exit
                                exit
                                """ % (AS_id, interface, AS_id, interface)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            time.sleep(6)
                            child.sendcontrol('m')
                        child.sendline('exit')
                        child.sendcontrol('m')

                    else:
                        interface = Interface
                        configs = """
                        configure terminal
                        router bgp %d
                        neighbor %s remote-as %d
                        neighbor %s update-source loopback 0
                        exit
                        exit
                        """ % (AS_id, interface, AS_id, interface)
                        commands = configs.split('\n')
                        execute.execute(child, commands)
                        child.sendcontrol('m')

                else:
                    unconfig = """
                    configure terminal
                    no router bgp %d
                    exit
                    exit
                    """ % (AS_id)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    child.sendcontrol('m')

            if flag in (1, 3):
                if Action == 'enable':
                    if isinstance(Interface, list):
                        for interface in Interface:
                            print(interface)
                            configs = """
                                configure terminal
                                router bgp %d
                                neighbor %s remote-as %d
                                neighbor %s update-source loopback 0
                                exit
                                exit
                                """ % (AS_id, interface, AS_id, interface)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            time.sleep(6)
                            child.sendcontrol('m')
                        child.sendline('exit')
                        child.sendcontrol('m')

                    else:
                        interface = Interface
                        configs = """
                        configure terminal
                        router bgp %d
                        neighbor %s remote-as %d
                        neighbor %s update-source loopback 0
                        exit
                        exit
                        exit
                        """ % (AS_id, interface, AS_id, interface)
                        commands = configs.split('\n')
                        execute.execute(child, commands)
                        child.sendcontrol('m')

                else:
                    unconfig = """
                    configure terminal
                    no router bgp %d
                    exit
                    exit
                    """ % (AS_id)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    child.sendcontrol('m')

                return True

        else:
            return False
Ejemplo n.º 17
0
    def Configure_VRFs(self, Device, vrf_name, rd, rt, Links, ip_addr, mask,
                       Action):
        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)

        if child:

            clear_buffer.flushBuffer(1, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \
                     pexpect.EOF, pexpect.TIMEOUT], timeout=90)
            if flag in (1, 3):
                Dev.Login(Device, child)
                if Action == 'enable':
                    if isinstance(Links, list):
                        for Lnk in Links:
                            interface = device_data['Link_Details'][Lnk][
                                Device]

                            configs = """
                                          configure terminal
                                          ip vrf %s
                                          rd %s
                                          route-target export %s
                                          route-target import %s
                                          exit
                                          interface  %s
                                          ip vrf forwarding  %s
                                          ip address %s %s
                                          exit
                                          exit
                                """ % (vrf_name, rd, rt, rt, interface,
                                       vrf_name, ip_addr, mask)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            time.sleep(6)
                            child.sendcontrol('m')
                        child.sendline('exit')
                        child.sendcontrol('m')
                else:
                    if isinstance(Links, list):
                        for Lnk in Links:
                            interface = device_data['Link_Details'][Lnk][
                                Device]
                            unconfig = """
                            configure terminal
                            no ip vrf %s
                            interface  %s
                            no ip vrf forwarding  %s
                            no ip address %s %s
                            exit
                            exit
                            """ % (vrf_name, interface, vrf_name, ip_addr,
                                   mask)
                            commands = unconfig.split('\n')
                            execute.execute(child, commands)
                            child.sendcontrol('m')

                return True

        else:
            return False
Ejemplo n.º 18
0
    def Configure_EBGP(self, Device, AS_id, Interface, neighbor_AS_id, Action,
                       NW_id, Mask):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)
        port = device_data['Device_Details'][Device]['port']

        if port != "zebra":
            if child:
                clear_buffer.flushBuffer(1, child)
                child.sendcontrol('m')
                child.sendcontrol('m')
                child.sendcontrol('m')
                flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \
                               pexpect.EOF, pexpect.TIMEOUT], timeout=90)
                if flag in (0, 2):
                    Dev.Login(Device, child)
                    if Action == 'enable':
                        if isinstance(Interface, list):
                            for interface in Interface:
                                configs = """
                                    configure terminal
                                    router bgp %d
                                    neighbor %s remote-as %d
                                    network %s mask %s
                                    exit
                                    exit
                                    """ % (AS_id, interface, neighbor_AS_id,
                                           NW_id, Mask)
                                commands = configs.split('\n')
                                execute.execute(child, commands)
                                time.sleep(6)
                                child.sendcontrol('m')
                            child.sendline('exit')
                            child.sendcontrol('m')

                        else:
                            interface = Interface
                            configs = """
                            configure terminal
                            router bgp %d
                            neighbor %s remote-as %d
                            network %s mask %s
                            exit
                            exit
                            """ % (AS_id, interface, neighbor_AS_id, NW_id,
                                   Mask)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            child.sendcontrol('m')

                    else:
                        unconfig = """
                        configure terminal
                        no router bgp %d
                        exit
                        exit
                        """ % (AS_id)
                        commands = unconfig.split('\n')
                        execute.execute(child, commands)
                        child.sendcontrol('m')

                if flag in (1, 3):
                    if Action == 'enable':
                        if isinstance(Interface, list):
                            for interface in Interface:

                                configs = """
                                    configure terminal
                                    router bgp %d
                                    neighbor %s remote-as %d
                                    network %s mask %s
                                    exit
                                    exit
                                    """ % (AS_id, interface, neighbor_AS_id,
                                           NW_id, Mask)
                                commands = configs.split('\n')
                                execute.execute(child, commands)
                                child.sendcontrol('m')
                            child.sendline('exit')
                            child.sendcontrol('m')

                        else:
                            interface = Interface
                            configs = """
                            configure terminal
                            router bgp %d
                            neighbor %s remote-as %d
                            network %s mask %s
                            exit
                            exit
                            """ % (AS_id, interface, neighbor_AS_id, NW_id,
                                   Mask)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            child.sendcontrol('m')

                    else:
                        unconfig = """
                        configure terminal
                        no router bgp %d
                        exit
                        exit
                        """ % (AS_id)
                        commands = unconfig.split('\n')
                        execute.execute(child, commands)
                        child.sendcontrol('m')

                    return True
        elif port == 'zebra':
            port = "bgpd"
            device_data = getdata.get_data()
            IP_add = device_data['Device_Details'][Device]['ip_add']
            child = pexpect.spawn('telnet ' + IP_add + ' ' + port)
            hostname = device_data['Device_Details'][Device]['Hostname']
            clear_buffer.flushBuffer(1, child)

            child.sendcontrol('m')
            flag = (child.expect(['bgpd*', 'Password*', \
                    pexpect.EOF, pexpect.TIMEOUT], timeout=100))
            if flag == 1:
                child.send('zebra')
                child.sendcontrol('m')
                flag = child.expect(['bgpd*>', pexpect.EOF, \
                       pexpect.TIMEOUT], timeout=50)
                if flag == 0:
                    child.send('enable')
                    child.sendcontrol('m')

                    if child:
                        flag = child.expect(['bgpd#*', pexpect.EOF, \
                                         pexpect.TIMEOUT], timeout=90)
                        if flag == 0:
                            Dev.Login(Device, child)
                            if Action == 'enable':
                                if isinstance(Interface, list):
                                    for interface in Interface:
                                        configs = """
                                               configure terminal
                                               router bgp %d
                                               neighbor %s remote-as %d
                                               network %s
                                               exit
                                               exit
                                               """ % (AS_id, interface,
                                                      neighbor_AS_id, NW_id)
                                        commands = configs.split('\n')
                                        execute.execute(child, commands)
                                        time.sleep(6)
                                        child.sendcontrol('m')
                                        child.sendline('exit')
                                        child.sendcontrol('m')

                                else:
                                    interface = Interface
                                    configs = """
                                           configure terminal
                                           router bgp %d
                                           neighbor %s remote-as %d
                                           network %s
                                           exit
                                           exit
                                           """ % (AS_id, interface,
                                                  neighbor_AS_id, NW_id)
                                    commands = configs.split('\n')
                                    execute.execute(child, commands)
                                    child.sendcontrol('m')

                            else:
                                unconfig = """
                                           configure terminal
                                           no router bgp %d
                                           exit
                                           exit
                                           """ % (AS_id)
                                commands = unconfig.split('\n')
                                execute.execute(child, commands)
                                child.sendcontrol('m')

                            return True

        else:
            return False
Ejemplo n.º 19
0
    def Configure_ospf(self, Device, process_id, Networks_connected, Area,
                       Action):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)

        if (child):

            clear_buffer.flushBuffer(10, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([
                hostname + '>', hostname + '#', 'Router\>', 'Router\#',
                pexpect.EOF, pexpect.TIMEOUT
            ],
                                timeout=50)
            if flag == 0 or flag == 2:
                Dev.Login(self, Device, child)
                if Action == 'enable':
                    if (isinstance(Networks_connected, list)):
                        for NID in Networks_connected:
                            print NID
                            configs = """
					 			configure terminal
								router ospf %s
								network %s area %s 
								exit
								exit
								""" % (process_id, NID, Area)
                            commands = configs.split('\n')
                            execute.execute(child, commands)

                            child.sendcontrol('m')

                        child.sendline('exit')
                        child.sendcontrol('m')

                    else:
                        NID = Networks_connected
                        configs = """
						configure terminal
						router ospf %s
						network %s area %s
						end
						""" % (process_id, NID, Area)
                        commands = configs.split('\n')
                        execute.execute(child, commands)
                        child.sendcontrol('m')

                else:
                    unconfig = """
					configure terminal
					no router ospf %s
					end 
					""" % (process_id, NID, Area)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    child.sendcontrol('m')

            if flag == 1 or flag == 3:
                if Action == 'enable':
                    if (isinstance(Networks_connected, list)):
                        for NID in Networks_connected:
                            configs = """
								configure terminal
								router ospf %s
								network %s area %s 
								exit
								exit
								""" % (process_id, NID, Area)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            child.sendcontrol('m')

                        child.sendline('exit')
                        child.sendcontrol('m')

                    else:
                        NID = Networks_connected
                        configs = """
						configure terminal
						router ospf %s
						network %s area %s
						end
						""" % (process_id, NID, Area)
                        commands = configs.split('\n')
                        execute.execute(child, commands)
                        child.sendcontrol('m')

                else:
                    unconfig = """
					configure terminal
					no router ospf %s
					end
					""" % (process_id, NID, Area)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    child.sendcontrol('m')

            return True

        else:
            return False
Ejemplo n.º 20
0
def checking_operabilty_bgp(Device, command):
    device_data = getdata.get_data()
    hostname = device_data['Device_Details'][Device]['Hostname']
    port = device_data['Device_Details'][Device]['port']
    Dev = Devices.Devices()
    child = Dev.connect(Device)

    if port != "zebra":
        if child:

          clear_buffer.flushBuffer(1, child)
          child.sendcontrol('m')
          child.sendcontrol('m')
          child.sendcontrol('m')
          flag = child.expect([hostname+'>', hostname+'#', 'Router\>', \
                 'Router\#', pexpect.EOF, pexpect.TIMEOUT], timeout=90)
          if flag in (0, 2):
              Dev.Login(Device, child)
              configs = """
              %s
              """ % (command)
              commands = configs.split('\n')
              execute.execute(child, commands)
              resp = child.before.decode('utf-8')
              child.sendcontrol('m')
              child.sendcontrol('m')
              regex = r'never'
              if re.search(regex, resp):
                  return False
              else:
                  return True


          if flag in (1, 3):
              configs = """
              %s
              """ % (command)
              commands = configs.split('\n')
              execute.execute(child, commands)
              resp = child.before.decode('utf-8')
              child.sendcontrol('m')
              child.sendcontrol('m')
              regex = r'never'
              if re.search(regex, resp):
                  return False
              else:
                  return True

    elif port == 'zebra':
        port = "bgpd"
        device_data = getdata.get_data()
        IP_add = device_data['Device_Details'][Device]['ip_add']
        child = pexpect.spawn('telnet ' + IP_add + ' ' + port)
        hostname = device_data['Device_Details'][Device]['Hostname']
        clear_buffer.flushBuffer(1, child)

        child.sendcontrol('m')
        flag = (child.expect(['bgpd*', 'Password*', pexpect.EOF, pexpect.TIMEOUT], timeout=100))
        if flag == 1:
            child.send('zebra')
            child.sendcontrol('m')
            flag = child.expect(['bgpd*>', pexpect.EOF, pexpect.TIMEOUT], timeout=50)
            if flag == 0:
                child.send('enable')
                child.sendcontrol('m')

                if child:
                   flag = child.expect(['bgpd#*', pexpect.EOF, pexpect.TIMEOUT], timeout=90)
                   if flag == 0:
                       Dev.Login(Device, child)
                       configs = """
                       %s
                       """ % (command)
                       commands = configs.split('\n')
                       execute.execute(child, commands)
                       resp = child.before.decode('utf-8')
                       child.sendcontrol('m')
                       child.sendcontrol('m')
                       regex = r'never'
                       if re.search(regex, resp):
                           return False
                       else:
                           return True

    else:
          return False
Ejemplo n.º 21
0
 def operationUpdate(self, ip, community, version):
     temp_update = Devices.Devices(community, version)
     self.result_Mtu = temp_update.walkthrongh(ip, self.IFMTU)
     self.result_Speed = temp_update.walkthrongh(ip, self.IFSPEED)
     self.result_Admin = temp_update.walkthrongh(ip, self.IFADMINSTATUS)
     self.result_Opera = temp_update.walkthrongh(ip, self.IFOPERSTATUS)
Ejemplo n.º 22
0
    def Configure_ospf(self, Device, process_id, Networks_connected, Area,
                       Action):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)

        if (child):

            clear_buffer.flushBuffer(10, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            #time.sleep(20)
            flag = child.expect([
                hostname + '>', hostname + '#', 'Router\>', 'Router\#',
                pexpect.EOF, pexpect.TIMEOUT
            ],
                                timeout=50)
            #print 'flag =%d' % flag
            if flag == 0 or flag == 2:
                Dev.Login(self, Device, child)
                if Action == 'enable':
                    if (isinstance(Networks_connected, list)):
                        for NID in Networks_connected:
                            print NID
                            configs = """
					 			configure terminal
								router ospf %s
								network %s area %s 
								exit
								exit
								""" % (process_id, NID, Area)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            #					time.sleep(6)
                            child.sendcontrol('m')
            #					print "%s advertises 'I AM CONNECTED TO %s NETWORK'" % (Device,NID)
            #			time.sleep(30)
                        child.sendline('exit')
                        child.sendcontrol('m')
            #			print "OSPF enabled & neighbors set in %s" % Device
                    else:
                        NID = Networks_connected
                        configs = """
						configure terminal
						router ospf %s
						network %s area %s
						end
						""" % (process_id, NID, Area)
                        commands = configs.split('\n')
                        execute.execute(child, commands)
                        #			time.sleep(15)
                        child.sendcontrol('m')
            #			print '%s advertises I AM CONNECTED TO %s NETWORK' % (Device,NID)
            #			print "OSPF enabled & neighbors set in %s" % Device

                else:
                    unconfig = """
					configure terminal
					no router ospf %s
					end 
					""" % (process_id, NID, Area)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    #		time.sleep(15)
                    child.sendcontrol('m')
            #		print "OSPF disabled  and neighbors unset in %s" % Device

            if flag == 1 or flag == 3:
                if Action == 'enable':
                    if (isinstance(Networks_connected, list)):
                        for NID in Networks_connected:
                            #					print NID
                            configs = """
								configure terminal
								router ospf %s
								network %s area %s 
								exit
								exit
								""" % (process_id, NID, Area)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            #					time.sleep(6)
                            child.sendcontrol('m')
            #					print "%s advertises 'I AM CONNECTED TO %s NETWORK'" % (Device,NID)
            #					time.sleep(30)
                        child.sendline('exit')
                        child.sendcontrol('m')
            #			print "OSPF enabled & neighbors set in %s" % Device
                    else:
                        NID = Networks_connected
                        configs = """
						configure terminal
						router ospf %s
						network %s area %s
						end
						""" % (process_id, NID, Area)
                        commands = configs.split('\n')
                        execute.execute(child, commands)
                        #			time.sleep(15)
                        child.sendcontrol('m')
            #			print '%s advertises I AM CONNECTED TO %s NETWORK' % (Device,NID)
            #			print "OSPF enabled & neighbors set in %s" % Device

                else:
                    unconfig = """
					configure terminal
					no router ospf %s
					end
					""" % (process_id, NID, Area)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    #		time.sleep(15)
                    child.sendcontrol('m')
            #		print "OSPF disabled  and neighbors unset in %s" % Device

            #else:
            #	print 'Expected prompt not found'

            return True

        else:
            return False
Ejemplo n.º 23
0
 def config_lo_addr(*args):
     dev = Devices.Devices()
     dev.set_loopback(args[0], args[1])
Ejemplo n.º 24
0
 def config_docker_addr(*args):
     dev = Devices.Devices()
     dev.set_IP_DockerHost(args[0], args[1], args[2])
Ejemplo n.º 25
0
    def Configure_IBGP(self, Device, AS_id, Interface, Action):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)

        if (child):

            clear_buffer.flushBuffer(10, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([
                hostname + '>', hostname + '#', 'Router\>', 'Router\#',
                pexpect.EOF, pexpect.TIMEOUT
            ],
                                timeout=90)
            #print 'flag =%d' % flag
            if flag == 0 or flag == 2:
                Dev.Login(Device, child)
                if Action == 'enable':
                    if (isinstance(Interface, list)):
                        for interface in Interface:
                            #					print interface
                            configs = """
								configure terminal
								router bgp %d
								neighbor %s remote-as %d
								neighbor %s update-source loopback 0
								exit
								exit
								""" % (AS_id, interface, AS_id, interface)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            time.sleep(6)
                            child.sendcontrol('m')
            #					print "IBGP configured in %s " % (Device)
            #				time.sleep(15)
                        child.sendline('exit')
                        child.sendcontrol('m')

                    else:
                        interface = Interface
                        configs = """
						configure terminal
						router bgp %d
						neighbor %s remote-as %d
						neighbor %s update-source loopback 0
						exit
						exit
						""" % (AS_id, interface, AS_id, interface)
                        commands = configs.split('\n')
                        execute.execute(child, commands)
                        #		time.sleep(15)
                        child.sendcontrol('m')
            #			print "IBGP configured in %s " % (Device)

                else:
                    unconfig = """
					configure terminal
					no router bgp %d
					exit
					exit
					""" % (AS_id)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    #	time.sleep(15)
                    child.sendcontrol('m')
            #		print "IBGP disabled in %s" % Device

            if flag == 1 or flag == 3:
                if Action == 'enable':
                    if (isinstance(Interface, list)):
                        for interface in Interface:
                            print interface
                            configs = """
								configure terminal
								router bgp %d
								neighbor %s remote-as %d
								neighbor %s update-source loopback 0
								exit
								exit
								""" % (AS_id, interface, AS_id, interface)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            time.sleep(6)
                            child.sendcontrol('m')
            #					print "IBGP configured in %s " % (Device)
            #				time.sleep(15)
                        child.sendline('exit')
                        child.sendcontrol('m')

                    else:
                        interface = Interface
                        configs = """
						configure terminal
						router bgp %d
						neighbor %s remote-as %d
						neighbor %s update-source loopback 0
						exit
						exit
						exit
						""" % (AS_id, interface, AS_id, interface)
                        commands = configs.split('\n')
                        execute.execute(child, commands)
                        #		time.sleep(15)
                        child.sendcontrol('m')
            #			print "IBGP configured in %s " % (Device)

                else:
                    unconfig = """
					configure terminal
					no router bgp %d
					exit
					exit
					""" % (AS_id)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    #	time.sleep(15)
                    child.sendcontrol('m')
            #		print "IBGP disable in %s" % Device

        #	else:
        #	print 'Expected prompt not found'

            return True

        else:
            return False
Ejemplo n.º 26
0
    def Configure_mpls(self, Device, Links, mpls_label_proto, Action):
        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)

        if child:
            clear_buffer.flushBuffer(1, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \
                     pexpect.EOF, pexpect.TIMEOUT], timeout=90)
            if flag in (1, 3):
                Dev.Login(Device, child)
                if Action == 'enable':
                    if isinstance(Links, list):
                        for Lnk in Links:
                            interface = device_data['Link_Details'][Lnk][
                                Device]
                            configs = """
                                          configure terminal
                                          ip cef
                                          mpls label protocol %s
                                          mpls ldp router-id Loopback0 force
                                          interface %s
                                          mpls ip
                                          mpls label protocol %s
                                          exit
                                          exit
                                """ % (mpls_label_proto, interface,
                                       mpls_label_proto)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            time.sleep(6)
                            child.sendcontrol('m')
                        child.sendline('exit')
                        child.sendcontrol('m')

                else:
                    if isinstance(Links, list):
                        for Lnk in Links:
                            interface = device_data['Link_Details'][Lnk][
                                Device]
                            unconfig = """
                           configure terminal
                           no mpls label protocol %s
                           no mpls ldp router-id Loopback0 force
                           interface %s
                           no mpls ip
                           no mpls label protocol %s
                           exit
                           exit
                           """ % (mpls_label_proto, interface,
                                  mpls_label_proto)
                            commands = unconfig.split('\n')
                            execute.execute(child, commands)
                            time.sleep(6)
                            child.sendcontrol('m')

                return True

        else:
            return False
Ejemplo n.º 27
0
 def config_host_addr(*args):
     dev = Devices.Devices()
     dev.set_IP_Host(args[0], args[1], args[2])