How to use the napalm.base.utils.py23_compat.text_type function in napalm

To help you get started, we’ve selected a few napalm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github napalm-automation / napalm / napalm / ios / ios.py View on Github external
continue

            if "%NTP is not enabled" in line:
                return []

            elif len(line.split()) == 9:
                address, ref_clock, st, when, poll, reach, delay, offset, disp = (
                    line.split()
                )
                address_regex = re.match(r"(\W*)([0-9.*]*)", address)
            try:
                ntp_stats.append(
                    {
                        "remote": py23_compat.text_type(address_regex.group(2)),
                        "synchronized": ("*" in address_regex.group(1)),
                        "referenceid": py23_compat.text_type(ref_clock),
                        "stratum": int(st),
                        "type": "-",
                        "when": py23_compat.text_type(when),
                        "hostpoll": int(poll),
                        "reachability": int(reach),
                        "delay": float(delay),
                        "offset": float(offset),
                        "jitter": float(disp),
                    }
                )
            except Exception:
                continue

        return ntp_stats
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
return []

            elif len(line.split()) == 9:
                address, ref_clock, st, when, poll, reach, delay, offset, disp = (
                    line.split()
                )
                address_regex = re.match(r"(\W*)([0-9.*]*)", address)
            try:
                ntp_stats.append(
                    {
                        "remote": py23_compat.text_type(address_regex.group(2)),
                        "synchronized": ("*" in address_regex.group(1)),
                        "referenceid": py23_compat.text_type(ref_clock),
                        "stratum": int(st),
                        "type": "-",
                        "when": py23_compat.text_type(when),
                        "hostpoll": int(poll),
                        "reachability": int(reach),
                        "delay": float(delay),
                        "offset": float(offset),
                        "jitter": float(disp),
                    }
                )
            except Exception:
                continue

        return ntp_stats
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
# interface_list filter
        interface_list = []
        show_ip_int_br = show_ip_int_br.strip()
        for line in show_ip_int_br.splitlines():
            if "Interface " in line:
                continue
            interface = line.split()[0]
            interface_list.append(interface)

        return {
            "uptime": uptime,
            "vendor": vendor,
            "os_version": py23_compat.text_type(os_version),
            "serial_number": py23_compat.text_type(serial_number),
            "model": py23_compat.text_type(model),
            "hostname": py23_compat.text_type(hostname),
            "fqdn": fqdn,
            "interface_list": interface_list,
        }
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
except AttributeError:
            model = "Unknown"

        # interface_list filter
        interface_list = []
        show_ip_int_br = show_ip_int_br.strip()
        for line in show_ip_int_br.splitlines():
            if "Interface " in line:
                continue
            interface = line.split()[0]
            interface_list.append(interface)

        return {
            "uptime": uptime,
            "vendor": vendor,
            "os_version": py23_compat.text_type(os_version),
            "serial_number": py23_compat.text_type(serial_number),
            "model": py23_compat.text_type(model),
            "hostname": py23_compat.text_type(hostname),
            "fqdn": fqdn,
            "interface_list": interface_list,
        }
github napalm-automation-community / napalm-ce / napalm_ce / ce.py View on Github external
hostname = hostname.strip()

        # interface_list filter
        interface_list = []
        if 'Interface' in show_int_status:
            _, interface_part = show_int_status.split("Interface")
            re_intf = r"(?P\S+)\s+(?Pdown|up|offline|\*down)\s+" \
                      r"(?Pdown|up|\*down)"
            search_result = re.findall(re_intf, interface_part, flags=re.M)
            for interface_info in search_result:
                interface_list.append(interface_info[0])

        return {
            'uptime': int(uptime),
            'vendor': vendor,
            'os_version': py23_compat.text_type(os_version),
            'serial_number': py23_compat.text_type(serial_number),
            'model': py23_compat.text_type(model),
            'hostname': py23_compat.text_type(hostname),
            'fqdn': fqdn,  # ? fqdn(fully qualified domain name)
            'interface_list': interface_list
        }
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
return []

            elif len(line.split()) == 9:
                address, ref_clock, st, when, poll, reach, delay, offset, disp = (
                    line.split()
                )
                address_regex = re.match(r"(\W*)([0-9.*]*)", address)
            try:
                ntp_stats.append(
                    {
                        "remote": py23_compat.text_type(address_regex.group(2)),
                        "synchronized": ("*" in address_regex.group(1)),
                        "referenceid": py23_compat.text_type(ref_clock),
                        "stratum": int(st),
                        "type": "-",
                        "when": py23_compat.text_type(when),
                        "hostpoll": int(poll),
                        "reachability": int(reach),
                        "delay": float(delay),
                        "offset": float(offset),
                        "jitter": float(disp),
                    }
                )
            except Exception:
                continue

        return ntp_stats
github napalm-automation / napalm / napalm / base / recorder.py View on Github external
def replay(cls, func, *args, **kwargs):
    logger.debug("Replaying {}".format(func.__name__))
    filename = "{}.{}.yaml".format(func.__name__, cls.current_count)
    with open(os.path.join(cls.path, filename), 'r') as f:
        r = camel.load(py23_compat.text_type(f.read()))

    if isinstance(r, Exception):
        raise r
    return r
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
def _create_tmp_file(config):
        """Write temp file and for use with inline config and SCP."""
        tmp_dir = tempfile.gettempdir()
        rand_fname = py23_compat.text_type(uuid.uuid4())
        filename = os.path.join(tmp_dir, rand_fname)
        with open(filename, "wt") as fobj:
            fobj.write(config)
        return filename
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
results[current_hop]["probes"][3] = {
                "rtt": float(),
                "ip_address": "",
                "host_name": "",
            }
            current_probe = 1
            ip_address = ""
            host_name = ""
            while hop_list:
                current_element = hop_list.pop(0)
                # If current_element is * move index in dictionary to next probe
                if current_element == "*":
                    current_probe += 1
                # If current_element contains msec record the entry for probe
                elif "msec" in current_element:
                    ip_address = py23_compat.text_type(ip_address)
                    host_name = py23_compat.text_type(host_name)
                    rtt = float(current_element.replace("msec", ""))
                    results[current_hop]["probes"][current_probe][
                        "ip_address"
                    ] = ip_address
                    results[current_hop]["probes"][current_probe][
                        "host_name"
                    ] = host_name
                    results[current_hop]["probes"][current_probe]["rtt"] = rtt
                    # After recording the entry move the index to next probe
                    current_probe += 1
                # If element contains '(' and ')', the output format is 'FQDN (IP_ADDRESS)'
                # Save the IP address
                elif "(" in current_element:
                    ip_address = current_element.replace("(", "").replace(")", "")
                # Save the probe's ip_address and host_name
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
'host_name': ''}
            results[current_hop]['probes'][3] = {'rtt': float(),
                                                 'ip_address': '',
                                                 'host_name': ''}
            current_probe = 1
            ip_address = ''
            host_name = ''
            while hop_list:
                current_element = hop_list.pop(0)
                # If current_element is * move index in dictionary to next probe
                if current_element == '*':
                    current_probe += 1
                # If current_element contains msec record the entry for probe
                elif 'msec' in current_element:
                    ip_address = py23_compat.text_type(ip_address)
                    host_name = py23_compat.text_type(host_name)
                    rtt = float(current_element.replace('msec', ''))
                    results[current_hop]['probes'][current_probe]['ip_address'] = ip_address
                    results[current_hop]['probes'][current_probe]['host_name'] = host_name
                    results[current_hop]['probes'][current_probe]['rtt'] = rtt
                    # After recording the entry move the index to next probe
                    current_probe += 1
                # If element contains '(' and ')', the output format is 'FQDN (IP_ADDRESS)'
                # Save the IP address
                elif '(' in current_element:
                    ip_address = current_element.replace('(', '').replace(')', '')
                # Save the probe's ip_address and host_name
                else:
                    host_name = current_element
                    ip_address = current_element

        traceroute_dict['success'] = results