def configure_vlan_on_interface(self, commands_dict): """Configure vlan on specified interface/s :param commands_dict: dictionary of parameters :return: success message :rtype: string """ commands_list = get_commands_list(commands_dict) current_config = self.cli.send_command( 'show running-config interface {0}'.format(commands_dict['configure_interface'])) for line in current_config.splitlines(): if re.search(r'^\s*switchport\s+', line): line_to_remove = re.sub(r'\s+\d+[-\d+,]+', '', line) if not line_to_remove: line_to_remove = line commands_list.insert(1, 'no {0}'.format(line_to_remove.strip(' '))) expected_map = {'[\[\(][Yy]es/[Nn]o[\)\]]|\[confirm\]': lambda session: session.send_line('yes'), '[\[\(][Yy]/[Nn][\)\]]': lambda session: session.send_line('y')} output = self.send_config_command_list(commands_list, expected_map=expected_map) if re.search(r'[Cc]ommand rejected.*', output): error = 'Command rejected' for line in output.splitlines(): if line.lower().startswith('command rejected'): error = line.strip(' \t\n\r') raise Exception('Cisco OS', 'Vlan configuration failed.\n{0}'.format(error)) return 'Vlan configuration completed.'
def configure_vlan(self, ordered_parameters_dict): """Configure vlan :param ordered_parameters_dict: dictionary of parameters :return: success message :rtype: string """ commands_list = get_commands_list(ordered_parameters_dict) self.send_config_command_list(commands_list) return 'Vlan configuration completed.'