コード例 #1
0
ファイル: cisco.py プロジェクト: emmurd/netman
def parse_interface(data):
    if data and (regex.match("interface (\w*Ethernet[^\s]*)", data[0])
                 or regex.match("interface (Port-channel[^\s]*)", data[0])):
        i = Interface(name=regex[0], shutdown=False)
        port_mode = access_vlan = native_vlan = trunk_vlans = None
        for line in data:
            if regex.match(" switchport mode (.*)", line): port_mode = regex[0]
            if regex.match(" switchport access vlan (\d*)", line): access_vlan = int(regex[0])
            if regex.match(" switchport trunk native vlan (\d*)", line): native_vlan = int(regex[0])
            if regex.match(" switchport trunk allowed vlan (.*)", line): trunk_vlans = regex[0]
            if regex.match(" shutdown", line): i.shutdown = True

        if not port_mode:
            i.port_mode = DYNAMIC
            i.access_vlan = access_vlan
            i.trunk_native_vlan = native_vlan
            i.trunk_vlans = parse_vlan_ranges(trunk_vlans) if trunk_vlans else []
        elif port_mode == 'access':
            i.port_mode = ACCESS
            i.access_vlan = access_vlan
        elif port_mode == 'trunk':
            i.port_mode = TRUNK
            i.trunk_native_vlan = native_vlan
            i.trunk_vlans = parse_vlan_ranges(trunk_vlans) if trunk_vlans else []

        return i
    return None
コード例 #2
0
ファイル: cisco.py プロジェクト: simon-begin/netman
def parse_interface(data):
    if data and (regex.match("interface (\w*Ethernet[^\s]*)", data[0])
                 or regex.match("interface (Port-channel[^\s]*)", data[0])):
        i = Interface(name=regex[0], shutdown=False)
        port_mode = access_vlan = native_vlan = trunk_vlans = None
        for line in data:
            if regex.match(" switchport mode (.*)", line):
                port_mode = regex[0]
            if regex.match(" switchport access vlan (\d*)", line):
                access_vlan = int(regex[0])
            if regex.match(" switchport trunk native vlan (\d*)", line):
                native_vlan = int(regex[0])
            if regex.match(" switchport trunk allowed vlan (.*)", line):
                trunk_vlans = regex[0]
            if regex.match(" shutdown", line):
                i.shutdown = True

        if not port_mode:
            i.port_mode = DYNAMIC
            i.access_vlan = access_vlan
            i.trunk_native_vlan = native_vlan
            i.trunk_vlans = parse_vlan_ranges(
                trunk_vlans) if trunk_vlans else []
        elif port_mode == 'access':
            i.port_mode = ACCESS
            i.access_vlan = access_vlan
        elif port_mode == 'trunk':
            i.port_mode = TRUNK
            i.trunk_native_vlan = native_vlan
            i.trunk_vlans = parse_vlan_ranges(
                trunk_vlans) if trunk_vlans else []

        return i
    return None
コード例 #3
0
ファイル: base.py プロジェクト: mlecours/netman
 def node_to_interface(self, interface_node, config):
     interface = Interface()
     interface.bond_master = get_bond_master(interface_node)
     interface.port_mode = self.get_port_mode(interface_node) or ACCESS
     vlans = list_vlan_members(interface_node, config)
     if interface.port_mode is ACCESS:
         interface.access_vlan = first(vlans)
     else:
         interface.trunk_vlans = vlans
     interface.trunk_native_vlan = value_of(interface_node.xpath("unit/family/ethernet-switching/native-vlan-id"), transformer=int)
     interface.name = value_of(interface_node.xpath("name"))
     interface.shutdown = first(interface_node.xpath("disable")) is not None
     return interface
コード例 #4
0
ファイル: dell10g.py プロジェクト: stephanerobert/netman
    def read_interface(self, interface_name):
        data = self.get_interface_data(interface_name)

        interface = Interface(name=interface_name, port_mode=ACCESS, shutdown=False)
        for line in data:
            if regex.match("switchport mode \S+", line):
                interface.port_mode = TRUNK
            if regex.match("shutdown", line):
                interface.shutdown = True
            if regex.match("switchport access vlan (\d+)", line):
                interface.access_vlan = int(regex[0])
            if regex.match("switchport general pvid (\d+)", line):
                interface.trunk_native_vlan = int(regex[0])
            if regex.match("switchport \S* allowed vlan (add )?(\S+)", line):
                interface.trunk_vlans = parse_vlan_ranges(regex[1])

        return interface
コード例 #5
0
ファイル: dell10g.py プロジェクト: simon-begin/netman
    def read_interface(self, interface_name):
        data = self.get_interface_data(interface_name)

        interface = Interface(name=interface_name, port_mode=ACCESS, shutdown=False)
        for line in data:
            if regex.match("switchport mode \S+", line):
                interface.port_mode = TRUNK
            if regex.match("shutdown", line):
                interface.shutdown = True
            if regex.match("switchport access vlan (\d+)", line):
                interface.access_vlan = int(regex[0])
            if regex.match("switchport general pvid (\d+)", line):
                interface.trunk_native_vlan = int(regex[0])
            if regex.match("switchport \S* allowed vlan (add )?(\S+)", line):
                interface.trunk_vlans = parse_vlan_ranges(regex[1])

        return interface
コード例 #6
0
ファイル: arista.py プロジェクト: simon-begin/netman
def parse_interfaces(interfaces_data, switchports_data):
    interfaces = []
    for interface_data in interfaces_data.values():
        if regex.match("(\w*Ethernet[^\s]*)", interface_data["name"]) or \
                regex.match("(Port-channel[^\s]*)", interface_data["name"]):

            interface = Interface(name=interface_data["name"], shutdown=False)

            if interface_data["lineProtocolStatus"] == "down":
                interface.shutdown = True

            interface.mtu = int(interface_data["mtu"])
            interface.auto_negotiation = ON if interface_data["autoNegotiate"] == "on" else OFF

            if interface.name in switchports_data:
                patch_switchport(interface, switchports_data[interface.name]["switchportInfo"])

            interfaces.append(interface)

    return interfaces