Exemplo n.º 1
0
    def get_facts(self):

        sh_ver = self.device.show_version()

        for line in sh_ver.splitlines():
            if 'Cisco IOS XR Software' in line:
                os_version = line.split()[-1]
            elif 'uptime' in line:
                uptime = string_parsers.convert_uptime_string_seconds(line)
                hostname = line.split()[0]
                fqdn = line.split()[0]
            elif 'Series' in line:
                model = ' '.join(line.split()[1:3])

        interface_list = list()

        for x in self.device.show_interface_description().splitlines()[3:-1]:
            if '.' not in x:
                interface_list.append(x.split()[0])

        result = {
            'vendor': u'Cisco',
            'os_version': unicode(os_version),
            'hostname': unicode(hostname),
            'uptime': uptime,
            'model': unicode(model),
            'serial_number': u'',
            'fqdn': unicode(fqdn),
            'interface_list': interface_list,
        }

        return result
Exemplo n.º 2
0
    def get_facts(self):
        system_status = execute_get(self.device, 'get system status')
        performance_status = execute_get(self.device,
                                         'get system performance status')

        interfaces = execute_get(self.device, 'get system interface | grep ==')
        interface_list = [x.split()[2] for x in interfaces.keys()]

        domain = execute_get(self.device,
                             'get system dns | grep domain')['domain']

        return {
            'vendor':
            unicode('Fortigate'),
            'os_version':
            unicode(system_status['Version'].split(',')[0].split()[1]),
            'uptime':
            convert_uptime_string_seconds(performance_status['Uptime']),
            'serial_number':
            unicode(system_status['Serial-Number']),
            'model':
            unicode(system_status['Version'].split(',')[0].split()[0]),
            'hostname':
            unicode(system_status['Hostname']),
            'fqdn':
            u'{}.{}'.format(system_status['Hostname'], domain),
            'interface_list':
            interface_list
        }
Exemplo n.º 3
0
Arquivo: iosxr.py Projeto: t2d/napalm
    def get_facts(self):

        sh_ver = self.device.show_version()

        for line in sh_ver.splitlines():
            if 'Cisco IOS XR Software' in line:
                os_version = line.split()[-1]
            elif 'uptime' in line:
                uptime = string_parsers.convert_uptime_string_seconds(line)
                hostname = line.split()[0]
                fqdn = line.split()[0]
            elif 'Series' in line:
                model = ' '.join(line.split()[1:3])

        interface_list = list()

        for x in self.device.show_interface_description().splitlines()[3:-1]:
            if '.' not in x:
                interface_list.append(x.split()[0])

        result = {
            'vendor': u'Cisco',
            'os_version': unicode(os_version),
            'hostname': unicode(hostname),
            'uptime': uptime,
            'model': unicode(model),
            'serial_number': u'',
            'fqdn': unicode(fqdn),
            'interface_list': interface_list,
        }

        return result
Exemplo n.º 4
0
    def get_facts(self):
        system_status = self.get_command_with_vdom('get system status',
                                                   vdom='global')
        performance_status = self.get_command_with_vdom(
            'get system performance status', vdom='global')

        interfaces = self.execute_command_with_vdom(
            'get system interface | grep ==', vdom='global')
        interface_list = [
            x.split()[2] for x in interfaces if x.strip() is not ''
        ]

        domain = self.get_command_with_vdom('get system dns | grep domain',
                                            vdom='global')['domain']

        return {
            'vendor':
            unicode('Fortigate'),
            'os_version':
            unicode(system_status['Version'].split(',')[0].split()[1]),
            'uptime':
            convert_uptime_string_seconds(performance_status['Uptime']),
            'serial_number':
            unicode(system_status['Serial-Number']),
            'model':
            unicode(system_status['Version'].split(',')[0].split()[0]),
            'hostname':
            unicode(system_status['Hostname']),
            'fqdn':
            u'{}.{}'.format(system_status['Hostname'], domain),
            'interface_list':
            interface_list
        }
Exemplo n.º 5
0
    def get_bgp_neighbors(self):

        families = ["ipv4", "ipv6"]
        terms = dict({"accepted_prefixes": "accepted", "sent_prefixes": "announced"})
        command_sum = "get router info bgp sum"
        command_detail = "get router info bgp neighbor {}"
        command_received = "get router info bgp neighbors {} received-routes | grep prefixes "
        peers = dict()

        bgp_sum = self.execute_command_with_vdom(command_sum)

        re_neigh = re.compile("^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
        neighbors = {n.split()[0]: n.split()[1:] for n in bgp_sum if re.match(re_neigh, n)}

        self.device.load_config("router bgp")

        for neighbor, parameters in neighbors.iteritems():
            logger.debug("NEW PEER")
            neigh_conf = self.device.running_config["router bgp"]["neighbor"]["{}".format(neighbor)]

            neighbor_dict = peers.get(neighbor, dict())

            if not neighbor_dict:
                neighbor_dict["local_as"] = int(bgp_sum[0].split()[7])
                neighbor_dict["remote_as"] = int(neigh_conf.get_param("remote-as"))
                neighbor_dict["is_up"] = "never" != parameters[7] or False
                neighbor_dict["is_enabled"] = neigh_conf.get_param("shutdown") != "enable" or False
                neighbor_dict["description"] = u""
                neighbor_dict["uptime"] = convert_uptime_string_seconds(parameters[7])
                neighbor_dict["address_family"] = dict()
                neighbor_dict["address_family"]["ipv4"] = dict()
                neighbor_dict["address_family"]["ipv6"] = dict()

            detail_output = [x.lower() for x in self.execute_command_with_vdom(command_detail.format(neighbor))]
            m = re.search("remote router id (.+?)\n", "\n".join(detail_output))
            if m:
                neighbor_dict["remote_id"] = unicode(m.group(1))
            else:
                raise Exception("cannot find remote router id for %s" % neighbor)

            for family in families:
                # find block
                x = detail_output.index(" for address family: {} unicast".format(family))
                block = detail_output[x:]

                for term, fortiname in terms.iteritems():
                    text = self._search_line_in_lines("%s prefixes" % fortiname, block)
                    t = [int(s) for s in text.split() if s.isdigit()][0]
                    neighbor_dict["address_family"][family][term] = t

                received = self.execute_command_with_vdom(command_received.format(neighbor))[0].split()
                if len(received) > 0:
                    neighbor_dict["address_family"][family]["received_prefixes"] = received[-1]
                else:
                    # Soft-reconfig is not enabled
                    neighbor_dict["address_family"][family]["received_prefixes"] = 0
            peers[neighbor] = neighbor_dict

        return {"global": {"router_id": unicode(bgp_sum[0].split()[3]), "peers": peers}}
Exemplo n.º 6
0
    def get_facts(self):
        system_status = execute_get(self.device, 'get system status')
        performance_status = execute_get(self.device, 'get system performance status')

        interfaces = execute_get(self.device, 'get system interface | grep ==')
        interface_list = [x.split()[2] for x in interfaces.keys()]

        domain = execute_get(self.device, 'get system dns | grep domain')['domain']

        return {
            'vendor': unicode('Fortigate'),
            'os_version': unicode(system_status['Version'].split(',')[0].split()[1]),
            'uptime': convert_uptime_string_seconds(performance_status['Uptime']),
            'serial_number': unicode(system_status['Serial-Number']),
            'model': unicode(system_status['Version'].split(',')[0].split()[0]),
            'hostname': unicode(system_status['Hostname']),
            'fqdn': u'{}.{}'.format(system_status['Hostname'], domain),
            'interface_list': interface_list
        }
Exemplo n.º 7
0
    def get_facts(self):
        system_status = self.get_command_with_vdom('get system status', vdom='global')
        performance_status = self.get_command_with_vdom('get system performance status', vdom='global')

        interfaces = self.execute_command_with_vdom('get system interface | grep ==', vdom='global')
        interface_list = [x.split()[2] for x in interfaces if x.strip() is not '']

        domain = self.get_command_with_vdom('get system dns | grep domain', vdom='global')['domain']

        return {
            'vendor': unicode('Fortigate'),
            'os_version': unicode(system_status['Version'].split(',')[0].split()[1]),
            'uptime': convert_uptime_string_seconds(performance_status['Uptime']),
            'serial_number': unicode(system_status['Serial-Number']),
            'model': unicode(system_status['Version'].split(',')[0].split()[0]),
            'hostname': unicode(system_status['Hostname']),
            'fqdn': u'{}.{}'.format(system_status['Hostname'], domain),
            'interface_list': interface_list
        }
Exemplo n.º 8
0
    def get_facts(self):
        system_status = self.get_command_with_vdom("get system status", vdom="global")
        performance_status = self.get_command_with_vdom("get system performance status", vdom="global")

        interfaces = self.execute_command_with_vdom("get system interface | grep ==", vdom="global")
        interface_list = [x.split()[2] for x in interfaces if x.strip() is not ""]

        domain = self.get_command_with_vdom("get system dns | grep domain", vdom="global")["domain"]

        return {
            "vendor": unicode("Fortigate"),
            "os_version": unicode(system_status["Version"].split(",")[0].split()[1]),
            "uptime": convert_uptime_string_seconds(performance_status["Uptime"]),
            "serial_number": unicode(system_status["Serial-Number"]),
            "model": unicode(system_status["Version"].split(",")[0].split()[0]),
            "hostname": unicode(system_status["Hostname"]),
            "fqdn": u"{}.{}".format(system_status["Hostname"], domain),
            "interface_list": interface_list,
        }
Exemplo n.º 9
0
    def get_bgp_neighbors(self):

        families = ['ipv4', 'ipv6']
        terms = dict({'accepted_prefixes': 'accepted', 'sent_prefixes': 'announced'})
        command_sum = 'get router info bgp sum'
        command_detail = 'get router info bgp neighbor {}'
        command_received = 'get router info bgp neighbors {} received-routes | grep prefixes '
        peers = dict()

        bgp_sum = self.device.execute_command(command_sum)
        re_neigh = re.compile("^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
        neighbors = {n.split()[0]: n.split()[1:] for n in bgp_sum if re.match(re_neigh, n)}

        self.device.load_config('router bgp')

        for neighbor, parameters in neighbors.iteritems():
            logger.debug('NEW PEER')
            neigh_conf = self.device.running_config['router bgp']['neighbor']['{}'.format(neighbor)]

            neighbor_dict = peers.get(neighbor, dict())

            if not neighbor_dict:
                neighbor_dict['local_as'] = int(bgp_sum[0].split()[7])
                neighbor_dict['remote_as'] = int(neigh_conf.get_param('remote-as'))
                neighbor_dict['is_up'] = 'never' != parameters[7] or False
                neighbor_dict['is_enabled'] = neigh_conf.get_param('shutdown') != 'enable' or False
                neighbor_dict['description'] = u''
                neighbor_dict['uptime'] = convert_uptime_string_seconds(parameters[7])
                neighbor_dict['address_family'] = dict()
                neighbor_dict['address_family']['ipv4'] = dict()
                neighbor_dict['address_family']['ipv6'] = dict()

            detail_output = [x.lower() for x in self.device.execute_command(command_detail.format(neighbor))]
            m = re.search('remote router id (.+?)\n', '\n'.join(detail_output))
            if m:
                neighbor_dict['remote_id'] = unicode(m.group(1))
            else:
                raise Exception('cannot find remote router id for %s' % neighbor)

            for family in families:
                # find block
                x = detail_output.index(' for address family: {} unicast'.format(family))
                block = detail_output[x:]

                for term, fortiname in terms.iteritems():
                    text = self._search_line_in_lines('%s prefixes' % fortiname, block)
                    t = [int(s) for s in text.split() if s.isdigit()][0]
                    neighbor_dict['address_family'][family][term] = t

                received = self.device.execute_command(
                    command_received.format(neighbor))[0].split()
                if len(received) > 0:
                    neighbor_dict['address_family'][family]['received_prefixes'] = received[-1]
                else:
                    # Soft-reconfig is not enabled
                    neighbor_dict['address_family'][family]['received_prefixes'] = 0
            peers[neighbor] = neighbor_dict

        return {
            'global': {
                'router_id': unicode(bgp_sum[0].split()[3]),
                'peers': peers
            }
        }
Exemplo n.º 10
0
    def get_bgp_neighbors(self):

        families = ['ipv4', 'ipv6']
        terms = dict({
            'accepted_prefixes': 'accepted',
            'sent_prefixes': 'announced'
        })
        command_sum = 'get router info bgp sum'
        command_detail = 'get router info bgp neighbor {}'
        command_received = 'get router info bgp neighbors {} received-routes | grep prefixes '
        peers = dict()

        bgp_sum = self.device.execute_command(command_sum)
        re_neigh = re.compile("^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
        neighbors = {
            n.split()[0]: n.split()[1:]
            for n in bgp_sum if re.match(re_neigh, n)
        }

        self.device.load_config('router bgp')

        for neighbor, parameters in neighbors.iteritems():
            logger.debug('NEW PEER')
            neigh_conf = self.device.running_config['router bgp']['neighbor'][
                '{}'.format(neighbor)]

            neighbor_dict = peers.get(neighbor, dict())

            if not neighbor_dict:
                neighbor_dict['local_as'] = int(bgp_sum[0].split()[7])
                neighbor_dict['remote_as'] = int(
                    neigh_conf.get_param('remote-as'))
                neighbor_dict['is_up'] = 'never' != parameters[7] or False
                neighbor_dict['is_enabled'] = neigh_conf.get_param(
                    'shutdown') != 'enable' or False
                neighbor_dict['description'] = u''
                neighbor_dict['uptime'] = convert_uptime_string_seconds(
                    parameters[7])
                neighbor_dict['address_family'] = dict()
                neighbor_dict['address_family']['ipv4'] = dict()
                neighbor_dict['address_family']['ipv6'] = dict()

            detail_output = [
                x.lower() for x in self.device.execute_command(
                    command_detail.format(neighbor))
            ]
            m = re.search('remote router id (.+?)\n', '\n'.join(detail_output))
            if m:
                neighbor_dict['remote_id'] = unicode(m.group(1))
            else:
                raise Exception('cannot find remote router id for %s' %
                                neighbor)

            for family in families:
                # find block
                x = detail_output.index(
                    ' for address family: {} unicast'.format(family))
                block = detail_output[x:]

                for term, fortiname in terms.iteritems():
                    text = self._search_line_in_lines(
                        '%s prefixes' % fortiname, block)
                    t = [int(s) for s in text.split() if s.isdigit()][0]
                    neighbor_dict['address_family'][family][term] = t

                received = self.device.execute_command(
                    command_received.format(neighbor))[0].split()
                if len(received) > 0:
                    neighbor_dict['address_family'][family][
                        'received_prefixes'] = received[-1]
                else:
                    # Soft-reconfig is not enabled
                    neighbor_dict['address_family'][family][
                        'received_prefixes'] = 0
            peers[neighbor] = neighbor_dict

        return {
            'global': {
                'router_id': unicode(bgp_sum[0].split()[3]),
                'peers': peers
            }
        }