コード例 #1
0
ファイル: enabled.py プロジェクト: JoProvost/fake-switches
    def get_port_configuration(self, port):
        conf = []
        if port.shutdown:
            conf.append('shutdown')
        if port.description:
            conf.append("description \"{}\"".format(port.description))
        if port.mode and port.mode != "access":
            conf.append('switchport mode {}'.format(port.mode))
        if port.access_vlan:
            conf.append('switchport access vlan {}'.format(port.access_vlan))
        if port.trunk_native_vlan:
            conf.append('switchport general pvid {}'.format(port.trunk_native_vlan))
        if port.trunk_vlans:
            if port.mode == "general":
                conf.append('switchport {} allowed vlan add {}'.format(port.mode, to_vlan_ranges(port.trunk_vlans)))
            else:
                conf.append('switchport trunk allowed vlan {}'.format(to_vlan_ranges(port.trunk_vlans)))

        if port.spanning_tree is False:
            conf.append("spanning-tree disable")
        if port.spanning_tree_portfast:
            conf.append("spanning-tree portfast")
        if port.lldp_transmit is False:
            conf.append('no lldp transmit')
        if port.lldp_receive is False:
            conf.append('no lldp receive')
        if port.lldp_med is False:
            conf.append('no lldp med')
        if port.lldp_med_transmit_capabilities is False:
            conf.append('no lldp med transmit-tlv capabilities')
        if port.lldp_med_transmit_network_policy is False:
            conf.append('no lldp med transmit-tlv network-policy')

        return conf
コード例 #2
0
def _allow_vlans(vlans):
    if vlans is None:
        return "ALL"
    if len(vlans) == 0:
        return "NONE"

    return to_vlan_ranges(vlans)
コード例 #3
0
ファイル: enabled.py プロジェクト: smk4664/fake-switches
 def _show_run_interfaces(self, ports):
     for port in ports:
         self.write_line("interface {}".format(port.name))
         if port.trunk_vlans is not None:
             self.write_line("   switchport trunk allowed vlan {}".format(
                 to_vlan_ranges(port.trunk_vlans)))
         if port.mode is not None:
             self.write_line("   switchport mode {}".format(port.mode))
         if isinstance(port, VlanPort):
             if port.load_interval is not None:
                 self.write_line("   load-interval {}".format(
                     port.load_interval))
             for ip in port.ips[:1]:
                 self.write_line("   ip address {}".format(ip))
             for ip in port.ips[1:]:
                 self.write_line("   ip address {} secondary".format(ip))
             if port.mpls_ip is False:
                 self.write_line("   no mpls ip")
             for ip_helper in port.ip_helpers:
                 self.write_line(
                     "   ip helper-address {}".format(ip_helper))
             for varp_address in sorted(port.varp_addresses):
                 self.write_line("   ip virtual-router address {}".format(
                     varp_address
                     if varp_address.prefixlen < 32 else varp_address.ip))
コード例 #4
0
ファイル: enabled.py プロジェクト: idjaw/fake-switches
    def get_port_configuration(self, port):
        conf = []
        if port.shutdown:
            conf.append('shutdown')
        if port.description:
            conf.append("description \"{}\"".format(port.description))
        if port.mode and port.mode != "access":
            conf.append('switchport mode {}'.format(port.mode))
        if port.access_vlan:
            conf.append('switchport access vlan {}'.format(port.access_vlan))
        if port.trunk_native_vlan:
            conf.append('switchport general pvid {}'.format(
                port.trunk_native_vlan))
        if port.trunk_vlans:
            if port.mode == "general":
                conf.append('switchport {} allowed vlan add {}'.format(
                    port.mode, to_vlan_ranges(port.trunk_vlans)))
            else:
                conf.append('switchport trunk allowed vlan {}'.format(
                    to_vlan_ranges(port.trunk_vlans)))

        if port.spanning_tree is False:
            conf.append("spanning-tree disable")
        if port.spanning_tree_portfast:
            conf.append("spanning-tree portfast")
        if port.lldp_transmit is False:
            conf.append('no lldp transmit')
        if port.lldp_receive is False:
            conf.append('no lldp receive')
        if port.lldp_med is False:
            conf.append('no lldp med')
        if port.lldp_med_transmit_capabilities is False:
            conf.append('no lldp med transmit-tlv capabilities')
        if port.lldp_med_transmit_network_policy is False:
            conf.append('no lldp med transmit-tlv network-policy')

        return conf
コード例 #5
0
ファイル: enabled.py プロジェクト: JoProvost/fake-switches
    def write_vlans(self):
        named_vlans = []
        other_vlans = []
        for v in self.switch_configuration.vlans:
            if v.name is not None:
                named_vlans.append(v)
            else:
                other_vlans.append(v)

        for vlan in named_vlans:
            self.write_line('vlan {}'.format(vlan.number))
            if vlan.name is not None:
                self.write_line('name {}'.format(vlan.name))
            self.write_line('exit')

        self.write_line('vlan {}'.format(to_vlan_ranges([v.number for v in other_vlans])))
        self.write_line('exit')
コード例 #6
0
ファイル: enabled.py プロジェクト: idjaw/fake-switches
    def write_vlans(self):
        named_vlans = []
        other_vlans = []
        for v in self.switch_configuration.vlans:
            if v.name is not None:
                named_vlans.append(v)
            else:
                other_vlans.append(v)

        for vlan in named_vlans:
            self.write_line('vlan {}'.format(vlan.number))
            if vlan.name is not None:
                self.write_line('name {}'.format(vlan.name))
            self.write_line('exit')

        self.write_line('vlan {}'.format(
            to_vlan_ranges([v.number for v in other_vlans])))
        self.write_line('exit')