Python interface.Interface() Examples

The following are 18 code examples of interface.Interface(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module interface , or try the search function .
Example #1
Source File: node.py    From rift-python with Apache License 2.0 6 votes vote down vote up
def auth_errors_table(self):
        tab = table.Table()
        tab.add_row([
            "Interface",
            ["Authentication", "Errors"],
            ["Error", "Count"],
            ["Error", "Rate"],
            ["Last Change"]
        ])
        for intf in self.interfaces_by_name.values():
            for counter in intf.auth_error_counters():
                if not counter.is_zero():
                    tab.add_row([
                        intf.name,
                        counter.description(),
                        counter.value_display_str(),
                        counter.rate_display_str(),
                        counter.last_change_display_str()
                    ])
        return tab 
Example #2
Source File: node.py    From rift-python with Apache License 2.0 5 votes vote down vote up
def command_show_node_stats(self, cli_session, exclude_zero):
        cli_session.print("Node ZTP FSM:")
        tab = self.node_ztp_fsm_stats_group.table(exclude_zero, sort_by_description=True)
        cli_session.print(tab.to_string())
        cli_session.print("Node Interfaces Traffic:")
        tab = self.intf_traffic_stats_group.table(exclude_zero)
        cli_session.print(tab.to_string())
        cli_session.print("Node Interfaces Security:")
        tab = self.intf_security_stats_group.table(exclude_zero)
        cli_session.print(tab.to_string())
        cli_session.print("Node Interface LIE FSMs:")
        tab = self.intf_lie_fsm_stats_group.table(exclude_zero, sort_by_description=True)
        cli_session.print(tab.to_string()) 
Example #3
Source File: scutum.py    From scutum with GNU General Public License v3.0 5 votes vote down vote up
def update_arp():
    """ Update gateway MAC address

    This function creates an instance for each handled
    interface and locks it's corresponded gateway mac
    address into nftables or arptables.
    """

    # reset arptables, removing all rules and
    # accept all incoming packages
    ac.flush_all()

    if args.interface:
        interface = Interface(args.interface)
        interface.update_gateway_addrs()
        Avalon.info(f'ADAPTER={interface.interface}', log=True)
        Avalon.info(f'GATEWAY_MAC={interface.gateway_mac}', log=True)
        Avalon.info(f'SELF_IP={interface.get_ip()}', log=True)
        if interface.gateway_mac:
            ac.block(interface.gateway_mac)
    else:
        # Create one instance for each interface
        for interface in interfaces:
            interface = Interface(interface)
            interface_objects.append(interface)

        # make each interface update gateway mac address
        for interface in interface_objects:
            interface.update_gateway_addrs()
            if interface.gateway_mac or interface.get_ip():
                Avalon.info(f'ADAPTER={interface.interface}', log=True)
                Avalon.info(f'GATEWAY_MAC={interface.gateway_mac}', log=True)
                Avalon.info(f'SELF_IP={interface.get_ip()}', log=True)

        for interface in interface_objects:
            if interface.gateway_mac:
                ac.append_allowed_mac(interface.gateway_mac) 
Example #4
Source File: main.py    From kiwi with Apache License 2.0 5 votes vote down vote up
def main():
    args = parse_args()
    logging.basicConfig(
        level=args.loglevel,
        format='%(name)s [%(process)d] %(levelname)s %(message)s')

    if args.loglevel and not args.debug_requests:
        logging.getLogger('requests').setLevel(logging.WARN)

    LOG.info('Starting up')
    LOG.info('Kubernetes is %s', args.kube_endpoint)
    LOG.info('Etcd is %s', args.etcd_endpoint)
    LOG.info('Managing interface %s', args.interface)

    if args.no_driver:
        iface_driver = None
        fw_driver = None
    else:
        iface_driver = interface.Interface(args.interface)
        fw_driver = firewall.Firewall(fwchain=args.fwchain,
                                      fwmark=args.fwmark)

    mgr = manager.Manager(etcd_endpoint=args.etcd_endpoint,
                          kube_endpoint=args.kube_endpoint,
                          etcd_prefix=args.etcd_prefix,
                          iface_driver=iface_driver,
                          fw_driver=fw_driver,
                          cidr_ranges=args.cidr_range,
                          refresh_interval=args.refresh_interval,
                          id=args.agent_id)

    LOG.info('My id is: %s', mgr.id)
    mgr.run() 
Example #5
Source File: topology.py    From nornir-workshop with MIT License 5 votes vote down vote up
def parse_cdp_neighbors(task):
    url = constants.RESTCONF_ROOT + constants.CDP_NEIGHBORS_ENDPOINT
    url = url.format(host=task.host.hostname)
    response = requests.get(
        url,
        headers=constants.HEADERS,
        auth=(task.host.username, task.host.password),
        verify=False,
    )
    response.raise_for_status()
    cdp_entries = response.json().get("Cisco-IOS-XE-cdp-oper:cdp-neighbor-detail", [])
    device_name = task.host.name
    host_interfaces = {}
    task.host.data["interfaces"] = host_interfaces
    for cdp_entry in cdp_entries:
        interface_name = cdp_entry["local-intf-name"]
        if interface_name in host_interfaces:
            interface = host_interfaces[interface_name]
        else:
            interface = Interface(interface_name, device_name)
            host_interfaces[interface_name] = interface

        remote_interface_name = cdp_entry["port-id"]
        remote_device_fqdn = cdp_entry["device-name"]
        remote_device_name = extract_hostname_from_fqdn(remote_device_fqdn)
        remote_interface = Interface(remote_interface_name, remote_device_name)
        interface.neighbors.append(remote_interface) 
Example #6
Source File: link.py    From nornir-workshop with MIT License 5 votes vote down vote up
def __init__(self, interfaces: List["Interface"]) -> None:
        self.interfaces = sorted(interfaces) 
Example #7
Source File: network.py    From encompass with GNU General Public License v3.0 5 votes vote down vote up
def start_interface(self, server):
        if server in self.interfaces.keys():
            return
        i = interface.Interface(server, self.config)
        self.pending_servers.add(server)
        i.start(self.queue)
        return i 
Example #8
Source File: link.py    From network-programmability-stream with MIT License 5 votes vote down vote up
def __init__(self, interfaces: List["Interface"]) -> None:
        self.interfaces = sorted(interfaces) 
Example #9
Source File: main.py    From network-programmability-stream with MIT License 5 votes vote down vote up
def update_lldp_neighbors(task):
    url = constants.RESTCONF_ROOT + constants.OPENCONFIG_LLDP_NEIGHBORS_ENDPOINT
    url = url.format(host=task.host.hostname)
    response = requests.get(
        url,
        headers=constants.HEADERS,
        auth=(task.host.username, task.host.password),
        verify=False,
    )
    response.raise_for_status()
    result = response.json()["openconfig-lldp:interface"]
    device_name = task.host.name
    host_interfaces = {}
    task.host.data["interfaces"] = host_interfaces
    for interface_info in result:
        interface_name = interface_info["name"]
        interface = Interface(interface_name, device_name)
        neighbors = interface_info.get("neighbors")
        if not neighbors:
            continue
        for neighbor_info in neighbors["neighbor"]:
            neighbor_state = neighbor_info["state"]
            remote_interface_name = neighbor_state["port-description"]
            remote_device_fqdn = neighbor_state["system-name"]
            remote_device_name = extract_hostname_from_fqdn(remote_device_fqdn)
            remote_interface = Interface(remote_interface_name, remote_device_name)
            interface.neighbors.append(remote_interface)

        host_interfaces[interface.name] = interface 
Example #10
Source File: DNS.py    From XFLTReaT with MIT License 5 votes vote down vote up
def set_mtu_ugly(self, cap):
		# sorry about this, this is a hack
		# no better solution till the custom fragmentation is not implemented
		interface = Interface()
		interface.set_mtu(self.config.get("Global", "clientif"), cap)
		cap -= 40 # IP+TCP
		os.system("iptables -t mangle -F")
		os.system("iptables -t mangle -A POSTROUTING -p tcp --tcp-flags SYN,RST SYN -o {0} -j TCPMSS --set-mss {1}".format(self.config.get("Global", "clientif"), cap))

		return

	# autotune control message handler
	# this handler answers to the tune requests to find the best bandwidth 
Example #11
Source File: node.py    From rift-python with Apache License 2.0 5 votes vote down vote up
def floodred_interfaces_table(self):
        tab = table.Table()
        tab.add_row(interface.Interface.cli_floodred_summary_headers())
        for intf in self.interfaces_by_name.values():
            tab.add_row(intf.cli_floodred_summary_attributes())
        return tab 
Example #12
Source File: node.py    From rift-python with Apache License 2.0 5 votes vote down vote up
def command_show_interfaces(self, cli_session):
        # TODO: Report neighbor uptime (time in THREE_WAY state)
        tab = table.Table()
        tab.add_row(interface.Interface.cli_summary_headers())
        for intf in self.interfaces_by_name.values():
            tab.add_row(intf.cli_summary_attributes())
        cli_session.print(tab.to_string()) 
Example #13
Source File: node.py    From rift-python with Apache License 2.0 5 votes vote down vote up
def command_show_interface(self, cli_session, parameters):
        interface_name = parameters['interface']
        if not interface_name in self.interfaces_by_name:
            cli_session.print("Error: interface {} not present".format(interface_name))
            return
        intf = self.interfaces_by_name[interface_name]
        cli_session.print("Interface:")
        cli_session.print(intf.cli_details_table().to_string())
        neighbor_table = intf.cli_neighbor_details_table()
        if neighbor_table:
            cli_session.print("Neighbor:")
            cli_session.print(neighbor_table.to_string()) 
Example #14
Source File: node.py    From rift-python with Apache License 2.0 5 votes vote down vote up
def have_ew_adjacency(self):
        # Does this node have at least one east-west adjacency?
        return any(filter(lambda x: x.fsm.state == interface.Interface.State.THREE_WAY and
                          x.neighbor_direction() == constants.DIR_EAST_WEST,
                          self.interfaces_by_name.values())) 
Example #15
Source File: node.py    From rift-python with Apache License 2.0 5 votes vote down vote up
def have_s_or_ew_adjacency(self, interface_going_down):
        # Does this node have at least one south-bound or east-west adjacency?
        for intf in self.interfaces_by_name.values():
            if ((intf.fsm.state == interface.Interface.State.THREE_WAY) and
                    (intf != interface_going_down)):
                if intf.neighbor_direction() in [constants.DIR_SOUTH,
                                                 constants.DIR_EAST_WEST]:
                    return True
        return False 
Example #16
Source File: node.py    From rift-python with Apache License 2.0 5 votes vote down vote up
def up_interfaces(self, interface_going_down):
        for intf in self.interfaces_by_name.values():
            if ((intf.fsm.state == interface.Interface.State.THREE_WAY) and
                    (intf != interface_going_down)):
                yield intf 
Example #17
Source File: node.py    From rift-python with Apache License 2.0 5 votes vote down vote up
def create_interface(self, interface_config):
        interface_name = interface_config['name']
        intf = interface.Interface(self, interface_config)
        self.interfaces_by_name[interface_name] = intf
        self.interfaces_by_id[intf.local_id] = intf
        return intf 
Example #18
Source File: node.py    From rift-python with Apache License 2.0 5 votes vote down vote up
def better_offer(self, offer1, offer2, three_way_only):
        # Don't consider removed offers
        if (offer1 is not None) and (offer1.removed):
            offer1 = None
        if (offer2 is not None) and (offer2.removed):
            offer2 = None
        # Don't consider offers that are marked "not a ZTP offer"
        if (offer1 is not None) and (offer1.not_a_ztp_offer):
            offer1 = None
        if (offer2 is not None) and (offer2.not_a_ztp_offer):
            offer2 = None
        # If asked to do so, only consider offers from neighbors in state 3-way as valid candidates
        if three_way_only:
            if (offer1 is not None) and (offer1.state != interface.Interface.State.THREE_WAY):
                offer1 = None
            if (offer2 is not None) and (offer2.state != interface.Interface.State.THREE_WAY):
                offer2 = None
        # If there is only one candidate, it automatically wins. If there are no candidates, there
        # is no best.
        if offer1 is None:
            return offer2
        if offer2 is None:
            return offer1
        # Pick the offer with the highest level
        if offer1.level > offer2.level:
            return offer1
        if offer2.level < offer1.level:
            return offer2
        # If the level is the same for both offers, pick offer with lowest system id as tie breaker
        if offer1.system_id < offer2.system_id:
            return offer1
        return offer2