def show_int(self, args): if len(args) > 1: ports = [self.switch_configuration.get_port_by_partial_name(" ".join(args[1:]))] else: ports = self.switch_configuration.ports for port in ports: if isinstance(port, VlanPort): _, port_id = split_port_name(port.name) self.write_line("Ve%s is down, line protocol is down" % port_id) self.write_line(" Hardware is Virtual Ethernet, address is 0000.0000.0000 (bia 0000.0000.0000)") if port.description: self.write_line(" Port name is %s" % port.description) else: self.write_line(" No port name") self.write_line(" Vlan id: %s" % port.vlan_id) self.write_line(" Internet address is %s, IP MTU 1500 bytes, encapsulation ethernet" % ( port.ips[0] if port.ips else "0.0.0.0/0")) else: _, port_id = split_port_name(port.name) self.write_line("GigabitEthernet%s is %s, line protocol is down" % ( port_id, "down" if port.shutdown is False else "disabled")) self.write_line(" Hardware is GigabitEthernet, address is 0000.0000.0000 (bia 0000.0000.0000)") self.write_line(" " + ", ".join([vlan_membership(port), port_mode(port), port_state(port)])) if port.description: self.write_line(" Port name is %s" % port.description) else: self.write_line(" No port name")
def to_port_ranges(ports): port_range_list = group_sequences(ports, are_in_sequence=lambda a, b: port_index(a) + 1 == port_index(b)) out = [] for port_range in port_range_list: if len(port_range) == 1: out.append("ethe %s" % split_port_name(port_range[0].name)[1]) else: out.append("ethe %s to %s" % (split_port_name(port_range[0].name)[1], split_port_name(port_range[-1].name)[1])) out_str = " ".join(out) return out_str
def show_run_int(self, args): port_list = [] if len(args) < 3: port_list = sorted(self.switch_configuration.ports, key=lambda e: ("a" if not isinstance(e, VlanPort) else "b") + e.name) else: if "ve".startswith(args[2]): port = self.switch_configuration.get_port_by_partial_name(" ".join(args[2:])) if not port: self.write_line("Error - %s was not configured" % " ".join(args[2:])) else: port_list = [port] else: port_type, port_number = split_port_name("".join(args[2:])) port = self.switch_configuration.get_port_by_partial_name(port_number) if not port: self.write_line("") else: port_list = [port] if len(port_list) > 0: for port in port_list: attributes = get_port_attributes(port) if len(attributes) > 0 or isinstance(port, VlanPort): self.write_line("interface %s" % port.name) for a in attributes: self.write_line(" " + a) self.write_line("!") self.write_line("")
def do_interface(self, *args): try: interface_name = self.read_interface_name(args) except NameIsIncomplete: self.display.invalid_command(self, "Incomplete command") return except InvalidVlanNumber: self.display.invalid_command(self, "Invalid input") return port = self.switch_configuration.get_port_by_partial_name( interface_name) if port: self.move_to(self.config_interface_processor, port) else: name, if_id = split_port_name(interface_name) if name == "Vlan": new_vlan_interface = self.switch_configuration.new( "VlanPort", if_id, interface_name) self.switch_configuration.add_port(new_vlan_interface) self.move_to(self.config_interface_processor, new_vlan_interface) else: raise NotImplementedError
def show_int(self, args): ports = [] port_name = " ".join(args[1:]) if len(args) > 1: port = self.switch_configuration.get_port_by_partial_name( port_name) if port: ports.append(port) else: ports = self.switch_configuration.ports if not ports: [self.write_line(l) for l in explain_missing_port(port_name)] for port in ports: if isinstance(port, VlanPort): _, port_id = split_port_name(port.name) self.write_line("Ve%s is down, line protocol is down" % port_id) self.write_line( " Hardware is Virtual Ethernet, address is 0000.0000.0000 (bia 0000.0000.0000)" ) if port.description: self.write_line(" Port name is %s" % port.description) else: self.write_line(" No port name") self.write_line(" Vlan id: %s" % port.vlan_id) self.write_line( " Internet address is %s, IP MTU 1500 bytes, encapsulation ethernet" % (port.ips[0] if port.ips else "0.0.0.0/0")) else: _, port_id = split_port_name(port.name) self.write_line( "GigabitEthernet%s is %s, line protocol is down" % (port_id, "down" if port.shutdown is False else "disabled")) self.write_line( " Hardware is GigabitEthernet, address is 0000.0000.0000 (bia 0000.0000.0000)" ) self.write_line(" " + ", ".join( [vlan_membership(port), port_mode(port), port_state(port)])) if port.description: self.write_line(" Port name is %s" % port.description) else: self.write_line(" No port name")
def do_router_interface(self, *args): actual_ve = next( (p for p in self.switch_configuration.ports if isinstance(p, VlanPort) and p.vlan_id == self.vlan.number), False) if not actual_ve: name = " ".join(args) self.switch_configuration.add_port(self.switch_configuration.new("VlanPort", self.vlan.number, name)) else: self.write_line("Error: VLAN: %s already has router-interface %s" % ( self.vlan.number, split_port_name(actual_ve.name)[1]))
def do_router_interface(self, *args): if len(args) != 2 or args[0] != "ve": self.write_line("Invalid input -> {}".format(" ".join(args))) self.write_line("Type ? for a list") else: actual_ve = next( (p for p in self.switch_configuration.ports if isinstance(p, VlanPort) and p.vlan_id == self.vlan.number), False) if not actual_ve: name = "ve {}".format(args[1]) self.switch_configuration.add_port(self.switch_configuration.new("VlanPort", self.vlan.number, name)) else: self.write_line("Error: VLAN: %s already has router-interface %s" % ( self.vlan.number, split_port_name(actual_ve.name)[1]))
def explain_missing_port(port_name): name, number = split_port_name(port_name) try: slot, port = number.split('/', 1) if int(port) > 64: return ['Invalid input -> {}'.format(number), 'Type ? for a list'] else: if int(slot) > 1: return ['Error - interface {} is not an ETHERNET interface'.format(number)] else: return ["Error - invalid interface {}".format(number)] except ValueError: return ['Invalid input -> {0} {1}'.format(name.replace('ethe ', ''), number), 'Type ? for a list']
def do_router_interface(self, *args): if len(args) != 2 or args[0] != "ve": self.write_line("Invalid input -> {}".format(" ".join(args))) self.write_line("Type ? for a list") else: actual_ve = next( (p for p in self.switch_configuration.ports if isinstance(p, VlanPort) and p.vlan_id == self.vlan.number), False) if not actual_ve: name = "ve {}".format(args[1]) self.switch_configuration.add_port( self.switch_configuration.new("VlanPort", self.vlan.number, name)) else: self.write_line( "Error: VLAN: %s already has router-interface %s" % (self.vlan.number, split_port_name(actual_ve.name)[1]))
def explain_missing_port(port_name): name, number = split_port_name(port_name) try: slot, port = number.split('/', 1) if int(port) > 64: return ['Invalid input -> {}'.format(number), 'Type ? for a list'] else: if int(slot) > 1: return [ 'Error - interface {} is not an ETHERNET interface'.format( number) ] else: return ["Error - invalid interface {}".format(number)] except ValueError: return [ 'Invalid input -> {0} {1}'.format(name.replace('ethe ', ''), number), 'Type ? for a list' ]
def short_port_name(port_name): name, if_id = split_port_name(port_name) return "{}{}".format(name[:2], if_id)
def get_prompt(self): return "SSH@%s(config-if-e1000-%s)#" % ( self.switch_configuration.name, split_port_name(self.port.name)[1])
def get_prompt(self): return "SSH@%s(config-if-e1000-%s)#" % (self.switch_configuration.name, split_port_name(self.port.name)[1])
def _show_vlan(self, vlan_id): vlan = self.switch_configuration.get_vlan(vlan_id) if vlan is None: self.write_line("Error: vlan {} is not configured".format(vlan_id)) else: vif = self.get_interface_vlan_for(vlan) ports = self.get_interface_ports_for(vlan) self.write_line("") self.write_line("PORT-VLAN {}, Name {}, Priority Level -, Priority Force 0, Creation Type STATIC".format( vlan_id, vlan.name if vlan.name is not None else "[None]")) self.write_line("Topo HW idx : 81 Topo SW idx: 257 Topo next vlan: 0") self.write_line("L2 protocols : STP") if len(ports["tagged"]) > 0: self.write_line("Statically tagged Ports : {}".format(to_port_ranges(ports["tagged"]))) if len(ports["untagged"]) > 0: self.write_line("Untagged Ports : {}".format(to_port_ranges(ports["untagged"]))) self.write_line("Associated Virtual Interface Id: {}".format( "NONE" if vif is None else vif.name.split(" ")[-1])) self.write_line("----------------------------------------------------------") if len(ports["untagged"]) == 0 and len(ports["tagged"]) == 0: self.write_line("No ports associated with VLAN") else: self.write_line("Port Type Tag-Mode Protocol State") for port in ports["untagged"]: self.write_line("{} PHYSICAL UNTAGGED STP DISABLED".format(split_port_name(port.name)[1])) for port in ports["tagged"]: self.write_line("{} PHYSICAL TAGGED STP DISABLED".format(split_port_name(port.name)[1])) self.write_line("Arp Inspection: 0") self.write_line("DHCP Snooping: 0") self.write_line("IPv4 Multicast Snooping: Disabled") self.write_line("IPv6 Multicast Snooping: Disabled") self.write_line("") if vif is None: self.write_line("No Virtual Interfaces configured for this vlan") else: self.write_line("Ve{} is down, line protocol is down".format(vif.name.split(" ")[-1])) self.write_line(" Type is Vlan (Vlan Id: {})".format(vlan_id)) self.write_line(" Hardware is Virtual Ethernet, address is 748e.f8a7.1b01 (bia 748e.f8a7.1b01)") self.write_line(" No port name") self.write_line(" Vlan id: {}".format(vlan_id)) self.write_line(" Internet address is 0.0.0.0/0, IP MTU 1500 bytes, encapsulation ethernet") self.write_line(" Configured BW 0 kbps")