def set(self, command, *args, context=None): if self._validate(args, *()): exc = exceptions.CommandSyntaxError(command=command) exc.template = 'syntax_error' exc.template_scopes = ('login', 'base', 'syntax_errors') raise exc elif self._validate(args, 'Service', str, str, str, str) and context['path'].split('/')[-1] == 'cfgm': address, svid, stag, vlan = self._dissect(args, 'Service', str, str, str, str) try: service_name = self.component_name services = self._model.get_srvcs('name', service_name) service = None for s in services: if s.service_type.lower( ) == context['ServiceType'] and s.name == service_name: service = s break if not service: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) service.set_service(address, int(svid), stag, vlan) except exceptions.SoftboxenError: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors'))
def on_unknown_command(self, command, *args, context=None): if len(args) == 0: if '/' in command: if command.startswith('/'): path = '/' + '/'.join([x for x in command.split('/') if x ][:-1]).replace('_', '-') else: path = '/'.join([x for x in command.split('/') if x][:-1]).replace('_', '-') command = [x for x in command.split('/') if x][-1] current_path = context['path'] try: command_proc = self.change_directory(path, context=context) command_proc._parse_and_execute_command(command, context=context) except exceptions.SoftboxenError: context['path'] = current_path self.set_prompt_end_pos(context=context) raise exceptions.CommandExecutionError( template='invalid_management_function_error', template_scopes=('login', 'base', 'execution_errors'), command=None) context['path'] = current_path self.set_prompt_end_pos(context=context) else: raise exceptions.CommandExecutionError( template='invalid_management_function_error', template_scopes=('login', 'base', 'execution_errors'), command=None) else: raise exceptions.CommandExecutionError( template='invalid_management_function_error', template_scopes=('login', 'base', 'execution_errors'), command=None)
def do_ls(self, command, *args, context=None): if self._validate(args, ): self.ls(context=context) elif self._validate(args, '-e'): pass elif self._validate(args, str): path = args[0] current_path = context['path'] try: tmp_cmdproc = self.change_directory(path, context=context) tmp_cmdproc.ls(context=context) except exceptions.CommandExecutionError: context['path'] = current_path self.set_prompt_end_pos(context=context) raise exceptions.CommandExecutionError( template='invalid_management_function_error', template_scopes=('login', 'base', 'execution_errors'), command=None) context['path'] = current_path self.set_prompt_end_pos(context=context) else: raise exceptions.CommandExecutionError( template='invalid_management_function_error', template_scopes=('login', 'base', 'execution_errors'), command=command)
def set(self, command, *args, context=None): if self._validate(args, *()): exc = exceptions.CommandSyntaxError(command=command) exc.template = 'syntax_error' exc.template_scopes = ('login', 'base', 'syntax_errors') raise exc elif self._validate(args, 'VlanId', str) and context['path'].split('/')[-1] == 'cfgm': vlan_id, = self._dissect(args, 'VlanId', str) vlan_id = int(vlan_id) if not 1 < vlan_id < 4089: raise exceptions.CommandExecutionError( template='syntax_error', template_scopes=('login', 'base', 'syntax_errors'), command=None) self._model.set_vlan_id(vlan_id) elif self._validate(args, 'IP_Address', str, str, str) and context['path'].split('/')[-1] == 'cfgm': new_ip, net_mask, gateway = self._dissect(args, 'IP_Address', str, str, str) self._model.set_mgmt_address(new_ip) self._model.set_net_mask(net_mask) self._model.set_default_gateway(gateway) else: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors'))
def do_get(self, command, *args, context=None): if len(args) >= 1: if '/' in args[0]: path = '' for component in args[0].split('/')[:-1]: path += component + '/' prop = args[0].split('/')[-1] current_path = context['path'] try: tmp_cmdproc = self.change_directory(path, context=context) tmp_cmdproc.get_property(command, prop, context=context) except exceptions.SoftboxenError: context['path'] = current_path self.set_prompt_end_pos(context=context) raise exceptions.CommandExecutionError( template='invalid_property', template_scopes=('login', 'base', 'syntax_errors'), command=None) context['path'] = current_path self.set_prompt_end_pos(context=context) else: try: self.get_property(command, args[0], context=context) except exceptions.SoftboxenError: raise exceptions.CommandExecutionError( template='invalid_property', template_scopes=('login', 'base', 'execution_errors'), command=None) else: raise exceptions.CommandExecutionError( template='invalid_management_function_error', template_scopes=('login', 'base', 'execution_errors'), command=None)
def do_set(self, command, *args, context=None): if len(args) == 0: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) elif args[0].count('/') > 0: path = '' for el in args[0].split('/')[:-1]: path += el + '/' current_path = context['path'] try: proc = self.change_directory(str(path[:-1]), context=context) res = (args[0].split('/')[-1], ) + args[1:] proc.set(command, *res, context=context) except exceptions.CommandExecutionError: context['path'] = current_path self.set_prompt_end_pos(context=context) raise exceptions.CommandExecutionError( template='syntax_error', template_scopes=('login', 'base', 'syntax_errors'), command=None) context['path'] = current_path self.set_prompt_end_pos(context=context) elif args[0].count('/') == 0: self.set(command, *args, context=context) return
def do_interface(self, command, *args, context=None): if self._validate(args, str): ident, = self._dissect(args, str) if ident.startswith('GigaEthernet'): context['ftth_prefix'] = 'g' port = ident[12:] try: port = self._model.get_port('name', port) except exceptions.SoftboxenError: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandExecutionError( command=command, template='parameter_error', template_scopes=('login', 'mainloop', 'ena', 'conf')) from .interfaceCommandProcessor import InterfaceCommandProcessor subprocessor = self._create_subprocessor( InterfaceCommandProcessor, 'login', 'mainloop', 'ena', 'conf', 'interface') context['component'] = port subprocessor.loop(context=dict(context, port=port)) elif ident.startswith('ePon'): context['ftth_prefix'] = 'epon' port = ident[4:] try: port = self._model.get_port('name', port) except exceptions.SoftboxenError: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandExecutionError( command=command, template='parameter_error', template_scopes=('login', 'mainloop', 'ena', 'conf')) from .interfaceCommandProcessor import InterfaceCommandProcessor subprocessor = self._create_subprocessor( InterfaceCommandProcessor, 'login', 'mainloop', 'ena', 'conf', 'interface') context['component'] = port subprocessor.loop(context=dict(context, port=port)) else: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandSyntaxError(command=command) else: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandSyntaxError(command=command)
def get_property(self, command, *args, context=None): service_name = self.component_name services = self._model.get_srvcs('name', service_name) service = None for s in services: if s.service_type.lower( ) == context['ServiceType'] and s.name == service_name: service = s context['service'] = service break if not service: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) scopes = ('login', 'base', 'get') if self._validate( (args[0], ), 'Service') and context['path'].split('/')[-1] == 'cfgm': # TODO: Find missing templates, and replace placeholder templates if service.service_type == '1to1doubletag': template_name = 'service_onetoonedoubletag' elif service.service_type == '1to1singletag': template_name = 'service_onetoonesingletag' elif service.service_type == 'mcast': template_name = 'service_mcast' elif service.service_type == 'nto1': template_name = 'service_nto1' elif service.service_type == 'pls': template_name = 'service_pls' elif service.service_type == 'tls': template_name = 'service_tls' else: raise exceptions.CommandExecutionError(command=command) context['spacer1'] = self.create_spacers( (67, ), (service.address, ))[0] * ' ' context['spacer2'] = self.create_spacers((67, ), (service.svid, ))[0] * ' ' context['spacer3'] = self.create_spacers( (67, ), (service.stag_priority, ))[0] * ' ' context['spacer4'] = self.create_spacers( (67, ), (service.vlan_handling, ))[0] * ' ' text = self._render(template_name, *scopes, context=context) self._write(text) else: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors'))
def get_property(self, command, *args, context=None): scopes = ('login', 'base', 'get') if self._validate(args, "CurrTemperature") and context['path'].split( '/')[-1] == 'status': context['currTemperature'] = self._model.currTemperature context['spacer'] = self.create_spacers( (67, ), (context['currTemperature'], ))[0] * ' ' self._write( self._render('currTemperature', *scopes, context=context)) elif self._validate( args, 'IP_Address') and context['path'].split('/')[-1] == 'cfgm': context['ip_address'] = self._model.mgmt_address context['spacer1'] = self.create_spacers( (67, ), (self._model.mgmt_address, ))[0] * ' ' context['net_mask'] = self._model.net_mask context['spacer2'] = self.create_spacers( (67, ), (self._model.net_mask, ))[0] * ' ' context['default_gateway'] = self._model.default_gateway context['spacer3'] = self.create_spacers( (67, ), (self._model.default_gateway, ))[0] * ' ' self._write(self._render('ip_address', *scopes, context=context)) elif self._validate( args, 'VlanId') and context['path'].split('/')[-1] == 'cfgm': context['vlan_id'] = self._model.network_element_management_vlan_id context['spacer'] = self.create_spacers( (67, ), (context['vlan_id'], ))[0] * ' ' self._write(self._render('vlan_id', *scopes, context=context)) else: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors'))
def get_actual_port(self, command): if self.component_name is None: raise exceptions.CommandExecutionError( command='Component name is None') try: return self._model.get_port('name', self.component_name) except exceptions.SoftboxenError: raise exceptions.CommandSyntaxError(command=command)
def set(self, command, *args, context=None): scopes = ('login', 'base', 'set') try: super().set(command, *args, context=None) except exceptions.CommandExecutionError: if self._validate(args, *()): exc = exceptions.CommandSyntaxError(command=command) exc.template = 'syntax_error' exc.template_scopes = ('login', 'base', 'syntax_errors') raise exc else: raise exceptions.CommandExecutionError(command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors'))
def set(self, command, *args, context=None): scopes = ('login', 'base', 'set') card = self._model.get_card('name', self.component_name.split('/')[0]) if self._validate(args, *()): exc = exceptions.CommandSyntaxError(command=command) exc.template = 'syntax_error' exc.template_scopes = ('login', 'base', 'syntax_errors') raise exc elif self._validate(args, 'AdministrativeStatus', str) and context['path'].split('/')[-1] == 'main': state, = self._dissect(args, 'AdministrativeStatus', str) try: port = self.get_component() if state == 'up': port.admin_up() elif state == 'down': port.admin_down() else: raise exceptions.SoftboxenError() except exceptions.SoftboxenError(): raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) elif self._validate(args, 'Labels', str, str, str) and context['path'].split('/')[-1] == 'main': label1, label2, description = self._dissect( args, 'Labels', str, str, str) try: port = self.get_component() port.set_label(label1, label2, description) except exceptions.SoftboxenError(): raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) else: raise exceptions.CommandSyntaxError(command=command)
def do_no_interface(self, command, *args, context=None): if self._validate(args, str): ident, = self._dissect(args, str) if ident.startswith('GigaEthernet'): context['ftth_prefix'] = 'g' port = ident[12:] try: port = self._model.get_port('name', port) port.set('description', '') port.set('spanning_tree_guard_root', False) port.set('switchport_trunk_vlan_allowed', None) port.set('switchport_mode_trunk', False) port.set('switchport_pvid', None) port.set('no_lldp_transmit', False) port.set('pbn_speed', None) port.set('switchport_block_multicast', False) port.set('switchport_rate_limit_egress', None) port.set('switchport_rate_limit_ingress', None) port.set('exclamation_mark', False) port.admin_down() except exceptions.SoftboxenError: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandExecutionError( command=command, template='parameter_error', template_scopes=('login', 'mainloop', 'ena', 'conf')) from .interfaceCommandProcessor import InterfaceCommandProcessor subprocessor = self._create_subprocessor( InterfaceCommandProcessor, 'login', 'mainloop', 'ena', 'conf', 'interface') context['component'] = port subprocessor.loop(context=dict(context, port=port)) else: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandSyntaxError(command=command) else: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandSyntaxError(command=command)
def get_property(self, command, *args, context=None): card = self._model.get_card('name', self._parent._parent.component_name) scopes = ('login', 'base', 'get') if self._validate(args, *()): exc = exceptions.CommandSyntaxError(command=command) exc.template = 'syntax_error' exc.template_scopes = ('login', 'base', 'syntax_errors') raise exc elif self._validate(args, 'Chanprofile') and 'SUV' in card.board_name: channel = self.get_component() context['spacer1'] = self.create_spacers( (67, ), (channel.chan_profile_name, ))[0] * ' ' context['profile_name'] = channel.chan_profile_name text = self._render('chan_profile', *scopes, context=context) self._write(text) elif self._validate(args, 'ProfileName') and 'SUV' not in card.board_name: channel = self.get_component() context['spacer1'] = self.create_spacers( (67, ), (channel.chan_profile_name, ))[0] * ' ' context['profile_name'] = channel.chan_profile_name text = self._render('chan_profile', *scopes, context=context) self._write(text) elif self._validate( args, 'Status') and context['path'].split('/')[-1] == 'status': channel = self.get_component() context['spacer1'] = self.create_spacers( (67, ), (channel.curr_rate_d, ))[0] * ' ' context['spacer2'] = self.create_spacers( (67, ), (channel.prev_rate_d, ))[0] * ' ' context['spacer3'] = self.create_spacers( (67, ), (channel.curr_delay_d, ))[0] * ' ' context['spacer4'] = self.create_spacers( (67, ), (channel.curr_rate_u, ))[0] * ' ' context['spacer5'] = self.create_spacers( (67, ), (channel.prev_rate_u, ))[0] * ' ' context['spacer6'] = self.create_spacers( (67, ), (channel.curr_delay_u, ))[0] * ' ' text = self._render('status', *scopes, context=dict(context, channel=channel)) self._write(text) else: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors'))
def get_component(self, command, *args, context=None): portname = context['component'].name try: port = self._model.get_port('name', portname) except exceptions.SoftboxenError: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandExecutionError( command=command, template='parameter_error', template_scopes=('login', 'mainloop', 'ena', 'conf', 'interface')) return port
def do_cd(self, command, *args, context=None): if self._validate(args, ): raise exceptions.CommandSyntaxError() elif self._validate(args, str): path = args[0] current_path = context['path'] try: subprocessor = self.change_directory(path, context=context) except: context['path'] = current_path raise subprocessor.loop(context=context, return_to=subprocessor._parent) else: raise exceptions.CommandExecutionError(template='invalid_management_function_error', template_scopes=('login', 'base', 'execution_errors'), command=command)
def get_property(self, command, *args, context=None): port = self.get_component() card = self._model.get_card('name', self.component_name.split('/')[0]) scopes = ('login', 'base', 'get') if self._validate(args, *()): exc = exceptions.CommandSyntaxError(command=command) exc.template = 'syntax_error' exc.template_scopes = ('login', 'base', 'syntax_errors') raise exc elif self._validate( (args[0], ), 'AdministrativeStatus') and context['path'].split( '/')[-1] == 'main': self.map_states(port, 'port') context['spacer'] = self.create_spacers( (67, ), (port.admin_state, ))[0] * ' ' text = self._render('administrative_status', *scopes, context=dict(context, port=port)) self._write(text) elif self._validate( args, 'Labels') and context['path'].split('/')[-1] == 'main': context['spacer1'] = self.create_spacers((67, ), (port.label1, ))[0] * ' ' context['spacer2'] = self.create_spacers((67, ), (port.label2, ))[0] * ' ' context['spacer3'] = self.create_spacers( (67, ), (port.description, ))[0] * ' ' text = self._render('labels', *scopes, context=dict(context, port=port)) self._write(text) elif self._validate( (args[0], ), 'OperationalStatus') and context['path'].split( '/')[-1] == 'main': self.map_states(port, 'port') port_operational_state = port.operational_state context['port_operational_state'] = port_operational_state context['spacer'] = self.create_spacers( (67, ), (port_operational_state, ))[0] * ' ' text = self._render('operational_status', *scopes, context=context) self._write(text) else: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors'))
def do_deleteservice(self, command, *args, context=None): if self._validate(args, str) and context['path'].split('/')[-1] == 'cfgm': srvc_id, = self._dissect(args, str) service_name = 'srvc-' + srvc_id service = None services = self._model.get_srvcs('name', service_name) for s in services: if s.service_type == context['ServiceType']: service = s break if service is None: raise exceptions.CommandExecutionError( command=command, template='unknown_service_fragment', template_scopes=('login', 'base', 'execution_errors')) service.delete() else: raise exceptions.CommandSyntaxError(command=command)
def get_property(self, command, *args, context=None): port = self.get_component() context['port'] = port scopes = ('login', 'base', 'get') try: super().get_property(command, *args, context=context) except exceptions.CommandExecutionError: if self._validate( (args[0], ), 'AttainableRate') and context['path'].split( '/')[-1] == 'status': text = self._render('attainable_rate', *scopes, context=context) self._write(text) elif self._validate( (args[0], ), 'ActualStatus') and context['path'].split( '/')[-1] == 'status': text = self._render('actual_status', *scopes, context=context) self._write(text) elif self._validate( (args[0], ), 'OperationalWireState') and context['path'].split( '/')[-1] == 'status': text = self._render('operational_wire_state', *scopes, context=context) self._write(text) elif self._validate( (args[0], ), 'SpanProfiles') and context['path'].split( '/')[-1] == 'cfgm': context['spacer1'] = self.create_spacers( (67, ), (port.profile, ))[0] * ' ' text = self._render('span_profiles', *scopes, context=context) self._write(text) else: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors'))
def set(self, command, *args, context=None): try: card = self.get_component() except exceptions.SoftboxenError: raise exceptions.CommandSyntaxError(command=command) if self._validate(args, *()): exc = exceptions.CommandSyntaxError(command=command) exc.template = 'syntax_error' exc.template_scopes = ('login', 'base', 'syntax_errors') raise exc elif self._validate(args, 'Labels', str, str, str) and context['path'].split('/')[-1] == 'main': label1, label2, description = self._dissect( args, 'Labels', str, str, str) try: component = self.get_component() component.set_label(label1, label2, description) except exceptions.SoftboxenError(): raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) else: raise exceptions.CommandSyntaxError(command=command)
def get_property(self, command, *args, context=None): port = self.get_component() context['port'] = port card = self._model.get_card('name', self.component_name.split('/')[0]) scopes = ('login', 'base', 'get') if self._validate(args, *()): exc = exceptions.CommandSyntaxError(command=command) exc.template = 'syntax_error' exc.template_scopes = ('login', 'base', 'syntax_errors') raise exc elif self._validate(args, 'Portprofile') and context['path'].split('/')[-1] == 'cfgm' and 'SUVM'\ not in card.board_name and 'SUVD2' not in card.board_name and self.__name__ == 'port': context['spacer1'] = self.create_spacers( (67, ), (port.profile1_name, ))[0] * ' ' context['profile_name'] = port.profile1_name text = self._render('port_profile', *scopes, context=context) self._write(text) elif self._validate(args, 'Portprofiles') and context['path'].split('/')[-1] == 'cfgm' and \ 'SUVD2' in card.board_name and self.__name__ == 'port': context['spacer1'] = self.create_spacers( (67, ), (port.profile1_name, ))[0] * ' ' context['profile_name'] = port.profile1_name text = self._render('port_profile', *scopes, context=context) self._write(text) elif self._validate(args, 'Portprofiles') and self.__name__ == 'port' and \ context['path'].split('/')[-1] == 'cfgm' and 'SUVM' in card.board_name: context['spacer1'] = self.create_spacers( (67, ), (port.profile1_enable, ))[0] * ' ' context['spacer2'] = self.create_spacers( (67, ), (port.profile1_name, ))[0] * ' ' context['spacer3'] = self.create_spacers( (67, ), (port.profile1_elength, ))[0] * ' ' context['spacer4'] = self.create_spacers( (67, ), (port.profile2_enable, ))[0] * ' ' context['spacer5'] = self.create_spacers( (67, ), (port.profile2_name, ))[0] * ' ' context['spacer6'] = self.create_spacers( (67, ), (port.profile2_elength, ))[0] * ' ' context['spacer7'] = self.create_spacers( (67, ), (port.profile3_enable, ))[0] * ' ' context['spacer8'] = self.create_spacers( (67, ), (port.profile3_name, ))[0] * ' ' context['spacer9'] = self.create_spacers( (67, ), (port.profile3_elength, ))[0] * ' ' context['spacer10'] = self.create_spacers( (67, ), (port.profile4_enable, ))[0] * ' ' context['spacer11'] = self.create_spacers( (67, ), (port.profile4_name, ))[0] * ' ' context['spacer12'] = self.create_spacers( (67, ), (port.profile_mode, ))[0] * ' ' text = self._render('port_profiles', *scopes, context=dict(context, port=port)) self._write(text) elif self._validate( (args[0], ), 'AttainableRate') and context['path'].split( '/')[-1] == 'status': context['spacer1'] = self.create_spacers( (67, ), (port.downstream, ))[0] * ' ' context['spacer2'] = self.create_spacers( (67, ), (port.upstream, ))[0] * ' ' text = self._render('attainable_rate', *scopes, context=dict(context, port=port)) self._write(text) elif self._validate((args[0],), 'PortMacStatus') and context['path'].split('/')[-1] == 'status' and \ card.product == 'ftth': text = self._render('port_mac_status', *scopes, context=context) self._write(text) elif self._validate((args[0],), 'DDMStatus') and context['path'].split('/')[-1] == 'status' and \ card.product == 'ftth': text = self._render('ddm_status', *scopes, context=context) self._write(text) elif self._validate((args[0],), 'PortGeneralStatus') and context['path'].split('/')[-1] == 'status' and \ card.product == 'ftth': text = self._render('port_general_status', *scopes, context=context) self._write(text) elif self._validate( (args[0], ), 'VendorId') and context['path'].split('/')[-1] == 'status': text = self._render('vendor_id', *scopes, context=context) self._write(text) elif self._validate((args[0],), 'LineActualState') and context['path'].split('/')[-1] == 'status' and \ card.product == 'sdsl': text = self._render('line_actual_state', *scopes, context=context) self._write(text) elif self._validate((args[0],), 'LineOperationState') and context['path'].split('/')[-1] == 'status' and \ card.product == 'sdsl': text = self._render('line_operation_state', *scopes, context=context) self._write(text) elif self._validate((args[0],), 'QuickLoopbackTest') and context['path'].split('/')[-1] == 'status'\ and (card.product == 'isdn' or 'SUI' in card.board_name) and self.__name__ == 'port': context['spacer'] = self.create_spacers( (67, ), (port.loopbacktest_state, ))[0] * ' ' context['loopbacktest_state'] = port.loopbacktest_state text = self._render('quickloopbacktest', *scopes, context=context) self._write(text) elif self._validate((args[0],), 'LineTestResults') and context['path'].split('/')[-1] == 'status'\ and 'SUP' in card.board_name and self.__name__ == 'port': context['spacer'] = self.create_spacers( (67, ), (port.linetest_state, ))[0] * ' ' context['test_state'] = port.linetest_state text = self._render('line_results_device', *scopes, context=context) self._write(text) elif self._validate((args[0],), 'MeltResults') and context['path'].split('/')[-1] == 'status'\ and card.product != 'isdn' and self.__name__ == 'port': context['spacer'] = self.create_spacers( (67, ), (port.melttest_state, ))[0] * ' ' context['test_state'] = port.melttest_state text = self._render('melt_results_device', *scopes, context=context) self._write(text) elif self._validate( (args[0], ), 'AdministrativeStatus') and context['path'].split( '/')[-1] == 'main': self.map_states(port, 'port') context['spacer'] = self.create_spacers( (67, ), (port.admin_state, ))[0] * ' ' text = self._render('administrative_status', *scopes, context=dict(context, port=port)) self._write(text) elif self._validate( args, 'Labels') and context['path'].split('/')[-1] == 'main': context['spacer1'] = self.create_spacers((67, ), (port.label1, ))[0] * ' ' context['spacer2'] = self.create_spacers((67, ), (port.label2, ))[0] * ' ' context['spacer3'] = self.create_spacers( (67, ), (port.description, ))[0] * ' ' text = self._render('labels', *scopes, context=dict(context, port=port)) self._write(text) elif self._validate( args, 'UnicastList') and context['path'].split('/')[-1] == 'status': port = self.get_component() try: chan = self._model.get_chan('port_id', port.id) self._model.get_interface('chan_id', chan.id) except exceptions.InvalidInputError: text = self._render('unicast_list_empty', *scopes, context=context) else: text = self._render( 'unicast_list', *scopes, context=context ) # where does the templates mac-address come from self._write(text) elif self._validate( (args[0], ), 'OperationalStatus') and context['path'].split( '/')[-1] == 'main': self.map_states(port, 'port') port_operational_state = port.operational_state context['port_operational_state'] = port_operational_state context['spacer'] = self.create_spacers( (67, ), (port_operational_state, ))[0] * ' ' text = self._render('operational_status', *scopes, context=context) self._write(text) else: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors'))
def get_property(self, command, *args, context=None): port = self.get_component() scopes = ('login', 'base', 'get') try: super().get_property(command, *args, context=context) except exceptions.CommandExecutionError: if self._validate((args[0],), 'SubscriberList') and context['path'].split('/')[-1] == 'status' and \ self._model.get_card('name', self._parent._parent.component_name).product in ('isdn', 'analog'): text = self._render('subscriberList_top', *scopes, context=context) i = 0 for subscriber in self._model.get_subscribers( 'portgroupport_id', port.id): context['i'] = i context['spacer1'] = self.create_spacers( (63, ), (subscriber.number, ))[0] * ' ' context['spacer2'] = self.create_spacers( (63, ), (subscriber.registration_state, ))[0] * ' ' i += 1 text += self._render('subscriberList_item2', *scopes, context=dict(context, subscriber=subscriber)) text += self._render('subscriberList_bottom', *scopes, context=context) self._write(text) elif self._validate((args[0],), 'Isdnport') and context['path'].split('/')[-1] == 'cfgm' and \ port.type == 'ISDN': context['spacer1'] = self.create_spacers( (67, ), (port.enable, ))[0] * ' ' context['spacer2'] = self.create_spacers( (67, ), (port.register_as_global, ))[0] * ' ' context['spacer3'] = self.create_spacers( (67, ), (port.register_default_number_only, ))[0] * ' ' context['spacer4'] = self.create_spacers( (67, ), (port.sip_profile, ))[0] * ' ' context['spacer5'] = self.create_spacers( (67, ), (port.proxy_registrar_profile, ))[0] * ' ' context['spacer6'] = self.create_spacers( (67, ), (port.codec_sdp_profile, ))[0] * ' ' context['spacer7'] = self.create_spacers( (67, ), (port.isdnba_profile, ))[0] * ' ' context['spacer8'] = self.create_spacers( (67, ), (port.layer_1_permanently_activated, ))[0] * ' ' text = self._render('isdnport_top', *scopes, context=dict(context, port=port)) i = 0 for subscriber in self._model.get_subscribers( 'portgroupport_id', port.id): if subscriber.portgroupport_id == port.id: context['i'] = i context['spacer10'] = self.create_spacers( (63, ), (subscriber.number, ))[0] * ' ' context['spacer11'] = self.create_spacers( (63, ), (subscriber.autorisation_user_name, ))[0] * ' ' context['spacer12'] = self.create_spacers( (63, ), (subscriber.autorisation_password, ))[0] * ' ' context['spacer13'] = self.create_spacers( (63, ), (subscriber.display_name, ))[0] * ' ' context['spacer14'] = self.create_spacers( (65, ), (subscriber.privacy, ))[0] * ' ' i += 1 text += self._render('isdnport_middle', *scopes, context=dict( context, subscriber=subscriber)) text += self._render('isdnport_bottom', *scopes, context=dict(context, port=port)) self._write(text) elif self._validate((args[0],), 'pstnport') and context['path'].split('/')[-1] == 'cfgm' and \ port.type == 'PSTN': context['spacer1'] = self.create_spacers( (67, ), (port.enable, ))[0] * ' ' context['spacer2'] = self.create_spacers( (67, ), (port.register_as_global, ))[0] * ' ' context['spacer3'] = self.create_spacers( (67, ), (port.pay_phone, ))[0] * ' ' context['spacer4'] = self.create_spacers( (67, ), (port.sip_profile, ))[0] * ' ' context['spacer5'] = self.create_spacers( (67, ), (port.proxy_registrar_profile, ))[0] * ' ' context['spacer6'] = self.create_spacers( (67, ), (port.codec_sdp_profile, ))[0] * ' ' context['spacer7'] = self.create_spacers( (67, ), (port.pstn_profile, ))[0] * ' ' context['spacer8'] = self.create_spacers( (67, ), (port.enterprise_profile, ))[0] * ' ' text = self._render('pstnport_top', *scopes, context=dict(context, port=port)) i = 0 for subscriber in self._model.get_subscribers( 'portgroupport_id', port.id): if subscriber.portgroupport_id == port.id: context['i'] = i context['spacer10'] = self.create_spacers( (63, ), (subscriber.number, ))[0] * ' ' context['spacer11'] = self.create_spacers( (63, ), (subscriber.autorisation_user_name, ))[0] * ' ' context['spacer12'] = self.create_spacers( (63, ), (subscriber.autorisation_password, ))[0] * ' ' context['spacer13'] = self.create_spacers( (63, ), (subscriber.display_name, ))[0] * ' ' context['spacer14'] = self.create_spacers( (65, ), (subscriber.privacy, ))[0] * ' ' i += 1 text += self._render('pstnport_middle', *scopes, context=dict( context, subscriber=subscriber)) text += self._render('pstnport_bottom', *scopes, context=dict(context, port=port)) self._write(text) else: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors'))
def set(self, command, *args, context=None): scopes = ('login', 'base', 'set') try: super().set(command, *args, context=context) except exceptions.CommandSyntaxError: if self._validate(args, *()): exc = exceptions.CommandSyntaxError(command=command) exc.template = 'syntax_error' exc.template_scopes = ('login', 'base', 'syntax_errors') raise exc elif args[0] in ('pstnport', 'isdnport' ) and context['path'].split('/')[-1] == 'cfgm': enable = True if args[1].lower() == 'true' else False number = None username = '' password = '' displayname = '' privacy = 'None' index_end = 2 if args[2] != '{}': if args[2].startswith('{') and args[2].endswith('}'): number = args[2][1:-1] else: index_start = args.index('{') index_end = args.index('}') number = args[ index_start + 1] if index_start + 1 < index_end else None username = args[ index_start + 2] if index_start + 2 < index_end else '' password = args[ index_start + 3] if index_start + 3 < index_end else '' displayname = args[ index_start + 4] if index_start + 4 < index_end else '' privacy = args[ index_start + 5] if index_start + 5 < index_end else 'None' register = True if args[index_end + 1].lower() == 'true' else False try: port = self.get_component() if number is not None: try: subscriber = self._model.get_subscriber( 'number', int(number)) if username is not None: subscriber.set('autorisation_user_name', username) if password is not None: subscriber.set('autorisation_password', password) if displayname is not None: subscriber.set('display_name', displayname) if privacy is not None: subscriber.set('privacy', privacy) except exceptions.SoftboxenError: address = self.component_name self._model.add_subscriber( number=int(number), autorisation_user_name=username, address=address, privacy=privacy, display_name=displayname, autorisation_password=password, portgroupport_id=port.id) pass if args[0] == 'isdnport': regdefault = True if args[ index_end + 2].lower().lower() == 'true' else False layer1 = True if args[index_end + 3].lower() == 'true' else False sip = args[index_end + 4] proxy = args[index_end + 5] codec = args[index_end + 6] isdnba = args[index_end + 7] port.set_isdnport(enable, register, regdefault, layer1, sip, proxy, codec, isdnba) elif args[0] == 'pstnport': phone = True if args[index_end + 2].lower() == 'true' else False sip = args[index_end + 3] proxy = args[index_end + 4] codec = args[index_end + 5] pstn = args[index_end + 6] enterprise = args[index_end + 7] port.set_pstnport(enable, register, phone, sip, proxy, codec, pstn, enterprise) except exceptions.SoftboxenError: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) else: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors'))
def get_property(self, command, *args, context=None): try: card = self.get_component() except exceptions.InvalidInputError: if args[0] in ('CurrentStatus', 'EquipmentInventory'): card = None else: raise scopes = ('login', 'base', 'get') if self._validate(args, *()): exc = exceptions.CommandSyntaxError(command=command) exc.template = 'syntax_error' exc.template_scopes = ('login', 'base', 'syntax_errors') raise exc elif self._validate(args, 'SubscriberList') and context['path'].split('/')[-1] == 'status' and \ (card.product == 'isdn' or card.product == 'analog'): text = self._render('subscriberList_top', *scopes, context=context) i = 0 for subscriber in self._model.subscribers: if subscriber.registration_state == 'Unregistered': context['i'] = i context['spacer1'] = self.create_spacers( (63, ), (subscriber.number, ))[0] * ' ' context['spacer2'] = self.create_spacers( (63, ), (subscriber.registration_state, ))[0] * ' ' context['spacer3'] = self.create_spacers( (63, ), (subscriber.address, ))[0] * ' ' i += 1 text += self._render('subscriberList_item', *scopes, context=dict(context, subscriber=subscriber)) text += self._render('subscriberList_bottom', *scopes, context=context) self._write(text) elif self._validate(args, 'SIP') and context['path'].split('/')[-1] == 'cfgm' and \ (card.product == 'isdn' or card.product == 'analog'): context['spacer1'] = self.create_spacers( (67, ), (card.gateway_name, ))[0] * ' ' context['spacer2'] = self.create_spacers( (67, ), (card.home_domain, ))[0] * ' ' context['spacer3'] = self.create_spacers( (67, ), (card.sip_port_number, ))[0] * ' ' context['spacer4'] = self.create_spacers( (65, ), (card.country_code, ))[0] * ' ' context['spacer5'] = self.create_spacers( (65, ), (card.area_code, ))[0] * ' ' context['spacer6'] = self.create_spacers( (67, ), (card.retransmission_timer, ))[0] * ' ' context['spacer7'] = self.create_spacers( (67, ), (card.max_retransmission_interval, ))[0] * ' ' context['spacer8'] = self.create_spacers( (67, ), (card.sip_extension, ))[0] * ' ' context['spacer9'] = self.create_spacers( (67, ), (card.asserted_id_mode, ))[0] * ' ' context['spacer10'] = self.create_spacers( (67, ), (card.overlap_signalling, ))[0] * ' ' context['spacer11'] = self.create_spacers( (67, ), (card.overlap_timer, ))[0] * ' ' context['spacer12'] = self.create_spacers( (67, ), (card.uac_request_timer, ))[0] * ' ' context['spacer13'] = self.create_spacers( (67, ), (card.uas_request_timer, ))[0] * ' ' context['spacer14'] = self.create_spacers( (67, ), (card.session_expiration, ))[0] * ' ' text = self._render('sip', *scopes, context=dict(context, card=card)) self._write(text) elif self._validate(args, 'Proxy') and context['path'].split('/')[-1] == 'cfgm' and \ (card.product == 'isdn' or card.product == 'analog'): context['spacer1'] = self.create_spacers( (67, ), (card.proxy_mode, ))[0] * ' ' context['spacer2'] = self.create_spacers( (67, ), (card.proxy_address, ))[0] * ' ' context['spacer3'] = self.create_spacers( (67, ), (card.proxy_port, ))[0] * ' ' context['spacer4'] = self.create_spacers( (67, ), (card.proxy_address_sec, ))[0] * ' ' context['spacer5'] = self.create_spacers( (67, ), (card.proxy_port_sec, ))[0] * ' ' context['spacer6'] = self.create_spacers( (67, ), (card.proxy_enable, ))[0] * ' ' context['spacer7'] = self.create_spacers( (67, ), (card.proxy_method, ))[0] * ' ' context['spacer8'] = self.create_spacers( (67, ), (card.proxy_interval, ))[0] * ' ' text = self._render('proxy', *scopes, context=dict(context, card=card)) self._write(text) elif self._validate(args, 'IP') and context['path'].split('/')[-1] == 'cfgm' and \ (card.product == 'isdn' or card.product == 'analog'): context['spacer1'] = self.create_spacers( (67, ), (card.gateway_ipaddress, ))[0] * ' ' context['spacer2'] = self.create_spacers( (67, ), (card.subnet_mask, ))[0] * ' ' context['spacer3'] = self.create_spacers( (67, ), (card.default_gateway, ))[0] * ' ' text = self._render('ip', *scopes, context=dict(context, card=card)) self._write(text) elif self._validate( args, 'Labels') and context['path'].split('/')[-1] == 'main': context['spacer1'] = self.create_spacers((67, ), (card.label1, ))[0] * ' ' context['spacer2'] = self.create_spacers((67, ), (card.label2, ))[0] * ' ' context['spacer3'] = self.create_spacers( (67, ), (card.description, ))[0] * ' ' text = self._render('labels', *scopes, context=dict(context, port=card)) self._write(text) elif self._validate( args, 'Registrar') and context['path'].split('/')[-1] == 'cfgm': context['spacer1'] = self.create_spacers( (67, ), (card.registrar_adress, ))[0] * ' ' context['spacer2'] = self.create_spacers( (67, ), (card.registrar_port, ))[0] * ' ' context['spacer3'] = self.create_spacers( (67, ), (card.registration_mode, ))[0] * ' ' context['spacer4'] = self.create_spacers( (67, ), (card.registration_expiration_time, ))[0] * ' ' text = self._render('registrar', *scopes, context=dict(context, card=card)) self._write(text) elif self._validate(args, 'HardwareAndSoftware' ) and context['path'].split('/')[-1] == 'main': unit_hardware = '"' + card.board_name + '"' context['unit_hardware'] = unit_hardware context['spacer_1'] = self.create_spacers( (67, ), (unit_hardware, ))[0] * ' ' unit_supplier_build_state = '"' + card.supplier_build_state + '"' context['unit_supplier_build_state'] = unit_supplier_build_state context['spacer_2'] = self.create_spacers( (67, ), (unit_supplier_build_state, ))[0] * ' ' unit_board_id = card.board_id context['unit_board_id'] = unit_board_id context['spacer_3'] = self.create_spacers( (67, ), (unit_board_id, ))[0] * ' ' unit_hardware_key = card.hardware_key context['unit_hardware_key'] = unit_hardware_key context['spacer_4'] = self.create_spacers( (67, ), (unit_hardware_key, ))[0] * ' ' unit_software = '"' + card.software + '"' context['unit_software'] = unit_software context['spacer_5'] = self.create_spacers( (67, ), (unit_software, ))[0] * ' ' unit_software_name = '"' + card.software_name + '"' context['unit_software_name'] = unit_software_name context['spacer_6'] = self.create_spacers( (67, ), (unit_software_name, ))[0] * ' ' unit_software_revision = '"' + card.software_revision + '"' context['unit_software_revision'] = unit_software_revision context['spacer_7'] = self.create_spacers( (67, ), (unit_software_revision, ))[0] * ' ' text = self._render('hardware_and_software', *scopes, context=context) self._write(text) elif self._validate( args, 'CurrentStatus') and context['path'].split('/')[-1] == 'main': if card is None: text = self._render('current_status_empty', *scopes, context=context) else: unit_state = card.state context['unit_state'] = unit_state context['spacer_1'] = self.create_spacers( (67, ), (unit_state, ))[0] * ' ' unit_hardware = '"' + card.board_name + ' ' + card.supplier_build_state + '"' context['unit_hardware'] = unit_hardware context['spacer_2'] = self.create_spacers( (67, ), (unit_hardware, ))[0] * ' ' unit_software = '"' + card.software[:-4] + '"' context['unit_software'] = unit_software context['spacer_3'] = self.create_spacers( (67, ), (unit_software, ))[0] * ' ' unit_serial_number = '"' + card.serial_number + '"' context['unit_serial_number'] = unit_serial_number context['spacer_4'] = self.create_spacers( (67, ), (unit_serial_number, ))[0] * ' ' unit_manufacturer_name = '"' + card.manufacturer_name + '"' context['unit_manufacturer_name'] = unit_manufacturer_name context['spacer_5'] = self.create_spacers( (67, ), (unit_manufacturer_name, ))[0] * ' ' unit_model_name = '"' + card.model_name + '"' context['unit_model_name'] = unit_model_name context['spacer_6'] = self.create_spacers( (67, ), (unit_model_name, ))[0] * ' ' text = self._render('current_status', *scopes, context=context) self._write(text) elif self._validate(args, 'EquipmentInventory' ) and context['path'].split('/')[-1] == 'main': if card is None: text = self._render('equipment_inventory_empty', *scopes, context=context) else: unit_symbol = '"' + card.board_name + '"' context['unit_symbol'] = unit_symbol context['spacer_1'] = self.create_spacers( (67, ), (unit_symbol, ))[0] * ' ' unit_short_text = '"' + card.short_text + '"' context['unit_short_text'] = unit_short_text context['spacer_2'] = self.create_spacers( (67, ), (unit_short_text, ))[0] * ' ' unit_board_id = card.board_id context['unit_board_id'] = unit_board_id context['spacer_3'] = self.create_spacers( (67, ), (unit_board_id, ))[0] * ' ' unit_hardware_key = card.hardware_key context['unit_hardware_key'] = unit_hardware_key context['spacer_4'] = self.create_spacers( (67, ), (unit_hardware_key, ))[0] * ' ' unit_manufacturer_id = '"' + card.manufacturer_id + '"' context['unit_manufacturer_id'] = unit_manufacturer_id context['spacer_5'] = self.create_spacers( (67, ), (unit_manufacturer_id, ))[0] * ' ' unit_serial_number = '"' + card.serial_number + '"' context['unit_serial_number'] = unit_serial_number context['spacer_6'] = self.create_spacers( (67, ), (unit_serial_number, ))[0] * ' ' unit_manufacturer_part_number = '"' + card.manufacturer_part_number + '"' context[ 'unit_manufacturer_part_number'] = unit_manufacturer_part_number context['spacer_7'] = self.create_spacers( (67, ), (unit_manufacturer_part_number, ))[0] * ' ' unit_manufacturer_build_state = '"' + card.manufacturer_build_state + '"' context[ 'unit_manufacturer_build_state'] = unit_manufacturer_build_state context['spacer_8'] = self.create_spacers( (67, ), (unit_manufacturer_build_state, ))[0] * ' ' unit_supplier_part_number = '"' + card.model_name + '"' context[ 'unit_supplier_part_number'] = unit_supplier_part_number context['spacer_9'] = self.create_spacers( (67, ), (unit_supplier_part_number, ))[0] * ' ' unit_supplier_build_state = '"' + card.supplier_build_state + '"' context[ 'unit_supplier_build_state'] = unit_supplier_build_state context['spacer_10'] = self.create_spacers( (67, ), (unit_supplier_build_state, ))[0] * ' ' unit_customer_id = '"' + card.customer_id + '"' context['unit_customer_id'] = unit_customer_id context['spacer_11'] = self.create_spacers( (67, ), (unit_customer_id, ))[0] * ' ' unit_customer_product_id = '"' + card.customer_product_id + '"' context['unit_customer_product_id'] = unit_customer_product_id context['spacer_12'] = self.create_spacers( (67, ), (unit_customer_product_id, ))[0] * ' ' unit_boot_loader = '"' + card.boot_loader + '"' context['unit_boot_loader'] = unit_boot_loader context['spacer_13'] = self.create_spacers( (67, ), (unit_boot_loader, ))[0] * ' ' unit_processor = '"' + card.processor + '"' context['unit_processor'] = unit_processor context['spacer_14'] = self.create_spacers( (67, ), (unit_processor, ))[0] * ' ' text = self._render('equipment_inventory', *scopes, context=context) self._write(text) else: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors'))
def set(self, command, *args, context=None): try: card = self.get_component() except exceptions.SoftboxenError: raise exceptions.CommandSyntaxError(command=command) if self._validate(args, *()): exc = exceptions.CommandSyntaxError(command=command) exc.template = 'syntax_error' exc.template_scopes = ('login', 'base', 'syntax_errors') raise exc elif self._validate(args, 'Labels', str, str, str) and context['path'].split('/')[-1] == 'main': label1, label2, description = self._dissect( args, 'Labels', str, str, str) try: component = self.get_component() component.set_label(label1, label2, description) except exceptions.SoftboxenError(): raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) elif self._validate(args, 'Ip', str, str, str) and context['path'].split('/')[-1] == 'cfgm': ip1, ip2, ip3 = self._dissect(args, 'Ip', str, str, str) try: component = self.get_component() component.set_ip(ip1, ip2, ip3) except exceptions.SoftboxenError(): raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) elif self._validate(args, 'SIP', str, str, str, str, str, str, str, str, str, str, str, str, str, str) and \ context['path'].split('/')[-1] == 'cfgm' and (card.product == 'isdn' or card.product == 'analog'): gw, hd, spn, cc, ac, rt, mri, se, aim, os, ot, uac, uas, sessione = self._dissect( args, 'Sip', str, str, str, str, str, str, str, str, str, str, str, str, str, str) try: se = True if se.lower() == 'true' else False os = True if os.lower() == 'true' else False uac = True if uac.lower() == 'true' else False uas = True if uas.lower() == 'true' else False aim = None if aim.lower() == 'none' else aim card.set_sip(gw, hd, int(spn), cc, ac, int(rt), int(mri), se, aim, os, int(ot), uac, uas, int(sessione)) except exceptions.SoftboxenError: raise exceptions.CommandSyntaxError(command=command) elif self._validate((args[0],), 'Digitmap') and \ context['path'].split('/')[-1] == 'cfgm' and (card.product == 'isdn' or card.product == 'analog'): pass elif self._validate(args, 'Registrar', str, str, str, str) and \ context['path'].split('/')[-1] == 'cfgm' and (card.product == 'isdn' or card.product == 'analog'): ra, rp, rm, rt = self._dissect(args, 'Registrar', str, str, str, str) try: card.set_registrar(ra, int(rp), rm, int(rt)) except exceptions.SoftboxenError: raise exceptions.CommandSyntaxError(command=command) elif self._validate(args[:9], 'Proxy', str, str, str, str, str, str, str, str) and \ context['path'].split('/')[-1] == 'cfgm' and (card.product == 'isdn' or card.product == 'analog'): pm, pa1, pp1, pa2, pp2, pe, pmethod, pi = self._dissect( args, 'Proxy', str, str, str, str, str, str, str, str) try: pe = True if pe.lower() == 'true' else False card.set_proxy(pm, pa1, int(pp1), pa2, int(pp2), pe, pmethod, int(pi)) except exceptions.SoftboxenError: raise exceptions.CommandSyntaxError(command=command) else: raise exceptions.CommandSyntaxError(command=command)
def get_property(self, command, *args, context=None): card = self.get_component() scopes = ('login', 'base', 'get') if self._validate(args, *()): exc = exceptions.CommandSyntaxError(command=command) exc.template = 'syntax_error' exc.template_scopes = ('login', 'base', 'syntax_errors') raise exc elif self._validate( args, 'Labels') and context['path'].split('/')[-1] == 'main': context['spacer1'] = self.create_spacers((67, ), (card.label1, ))[0] * ' ' context['spacer2'] = self.create_spacers((67, ), (card.label2, ))[0] * ' ' context['spacer3'] = self.create_spacers( (67, ), (card.description, ))[0] * ' ' text = self._render('labels', *scopes, context=dict(context, port=card)) self._write(text) elif self._validate(args, 'EquipmentInventory' ) and context['path'].split('/')[-1] == 'main': unit_symbol = '"' + card.board_name + '"' context['unit_symbol'] = unit_symbol context['spacer_1'] = self.create_spacers((67, ), (unit_symbol, ))[0] * ' ' unit_short_text = '"' + card.short_text + '"' context['unit_short_text'] = unit_short_text context['spacer_2'] = self.create_spacers( (67, ), (unit_short_text, ))[0] * ' ' unit_board_id = card.board_id context['unit_board_id'] = unit_board_id context['spacer_3'] = self.create_spacers( (67, ), (unit_board_id, ))[0] * ' ' unit_hardware_key = card.hardware_key context['unit_hardware_key'] = unit_hardware_key context['spacer_4'] = self.create_spacers( (67, ), (unit_hardware_key, ))[0] * ' ' unit_manufacturer_id = '"' + card.manufacturer_id + '"' context['unit_manufacturer_id'] = unit_manufacturer_id context['spacer_5'] = self.create_spacers( (67, ), (unit_manufacturer_id, ))[0] * ' ' unit_serial_number = '"' + card.serial_number + '"' context['unit_serial_number'] = unit_serial_number context['spacer_6'] = self.create_spacers( (67, ), (unit_serial_number, ))[0] * ' ' unit_manufacturer_part_number = '"' + card.manufacturer_part_number + '"' context[ 'unit_manufacturer_part_number'] = unit_manufacturer_part_number context['spacer_7'] = self.create_spacers( (67, ), (unit_manufacturer_part_number, ))[0] * ' ' unit_manufacturer_build_state = '"' + card.manufacturer_build_state + '"' context[ 'unit_manufacturer_build_state'] = unit_manufacturer_build_state context['spacer_8'] = self.create_spacers( (67, ), (unit_manufacturer_build_state, ))[0] * ' ' unit_supplier_part_number = '"' + card.model_name + '"' context['unit_supplier_part_number'] = unit_supplier_part_number context['spacer_9'] = self.create_spacers( (67, ), (unit_supplier_part_number, ))[0] * ' ' unit_supplier_build_state = '"' + card.supplier_build_state + '"' context['unit_supplier_build_state'] = unit_supplier_build_state context['spacer_10'] = self.create_spacers( (67, ), (unit_supplier_build_state, ))[0] * ' ' unit_customer_id = '"' + card.customer_id + '"' context['unit_customer_id'] = unit_customer_id context['spacer_11'] = self.create_spacers( (67, ), (unit_customer_id, ))[0] * ' ' unit_customer_product_id = '"' + card.customer_product_id + '"' context['unit_customer_product_id'] = unit_customer_product_id context['spacer_12'] = self.create_spacers( (67, ), (unit_customer_product_id, ))[0] * ' ' unit_boot_loader = '"' + card.boot_loader + '"' context['unit_boot_loader'] = unit_boot_loader context['spacer_13'] = self.create_spacers( (67, ), (unit_boot_loader, ))[0] * ' ' unit_processor = '"' + card.processor + '"' context['unit_processor'] = unit_processor context['spacer_14'] = self.create_spacers( (67, ), (unit_processor, ))[0] * ' ' text = self._render('equipment_inventory', *scopes, context=context) self._write(text) elif self._validate( args, 'CurrentStatus') and context['path'].split('/')[-1] == 'main': unit_state = card.state context['unit_state'] = unit_state context['spacer_1'] = self.create_spacers((67, ), (unit_state, ))[0] * ' ' unit_hardware = '"' + card.board_name + ' ' + card.supplier_build_state + '"' context['unit_hardware'] = unit_hardware context['spacer_2'] = self.create_spacers( (67, ), (unit_hardware, ))[0] * ' ' unit_software = '"' + card.software[:-4] + '"' context['unit_software'] = unit_software context['spacer_3'] = self.create_spacers( (67, ), (unit_software, ))[0] * ' ' unit_serial_number = '"' + card.serial_number + '"' context['unit_serial_number'] = unit_serial_number context['spacer_4'] = self.create_spacers( (67, ), (unit_serial_number, ))[0] * ' ' unit_manufacturer_name = '"' + card.manufacturer_name + '"' context['unit_manufacturer_name'] = unit_manufacturer_name context['spacer_5'] = self.create_spacers( (67, ), (unit_manufacturer_name, ))[0] * ' ' unit_model_name = '"' + card.model_name + '"' context['unit_model_name'] = unit_model_name context['spacer_6'] = self.create_spacers( (67, ), (unit_model_name, ))[0] * ' ' text = self._render('current_status', *scopes, context=context) self._write(text) else: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors'))
def get_property(self, command, *args, context=None): raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors'))
def do_show(self, command, *args, context=None): if self._validate(args, 'interface', str, str): ftth_version, port_name = self._dissect(args, 'interface', str, str) if ftth_version == 'ePON': expected_product = 'ftth-pon' context['port_name_prefix'] = 'EPON' elif ftth_version == 'gigaEthernet': expected_product = 'ftth' context['port_name_prefix'] = 'GigaEthernet' else: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandSyntaxError(command=command) try: port = self._model.get_port('name', port_name) card = self._model.get_card('id', port.card_id) assert card.product == expected_product except exceptions.SoftboxenError: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandExecutionError( command=command, template='parameter_error', template_scopes=('login', 'mainloop', 'ena')) except AssertionError: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandSyntaxError(command=command) _, port_index = port.name.split('/') context['port_index'] = port_index self.map_states(port, 'port') text = self._render('show_interface_product_port', context=dict(context, port=port)) self._write(text) elif self._validate(args, 'running-config', 'interface', str, str): ftth_version, port_name = self._dissect(args, 'running-config', 'interface', str, str) if ftth_version == 'ePON': expected_product = 'ftth-pon' context['port_name_prefix'] = 'EPON' elif ftth_version == 'gigaEthernet': expected_product = 'ftth' context['port_name_prefix'] = 'GigaEthernet' else: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandSyntaxError(command=command) try: port = self._model.get_port('name', port_name) card = self._model.get_card('id', port.card_id) assert card.product == expected_product except exceptions.SoftboxenError: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandExecutionError( command=command, template='parameter_error', template_scopes=('login', 'mainloop', 'ena')) except AssertionError: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandSyntaxError(command=command) text = self._render( 'show_running-config_interface_product_port_top', context=dict(context, port=port)) mid_text = '' if expected_product == "ftth-pon": try: _ = self._model.get_ont("port_id", port.id) except exceptions.SoftboxenError: pass else: counter = 1 onts = self._model.get_onts("port_id", port.id) for ont in onts: if counter > 32: mid_text = '' break context['counter'] = counter mid_text = self._render( 'show_running-config_interface_product_port_mid', context=dict(context, ont=ont)) counter += 1 text += mid_text text += self._render( 'show_running-config_interface_product_port_bottom', context=dict(context, port=port)) self._write(text) elif self._validate(args, 'mac', 'address-table', 'interface', str, str): ftth_version, port_name = self._dissect(args, 'mac', 'address-table', 'interface', str, str) bottom_text = "" counter = 0 context['spacer_1'] = self.create_spacers((4, ), ('', ))[0] * ' ' context['spacer_2'] = self.create_spacers((4, ), ('', ))[0] * ' ' if ftth_version == 'ePON': expected_product = 'ftth-pon' elif ftth_version == 'gigaEthernet': expected_product = 'ftth' else: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandSyntaxError(command=command) try: port = self._model.get_port('name', port_name) card = self._model.get_card('id', port.card_id) assert card.product == expected_product except exceptions.SoftboxenError: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandExecutionError( command=command, template='parameter_error', template_scopes=('login', 'mainloop', 'ena')) except AssertionError: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandSyntaxError(command=command) try: params = dict(connected_type='port', connected_id=port.id) service_ports = self._model.get_service_ports_by_values(params) for s_p in service_ports: service_vlan = self._model.get_service_vlan( 'service_port_id', s_p.id) vlan = self._model.get_vlan('id', service_vlan.vlan_id) counter += 1 context['port_name'] = "g" + port.name context['spacer_3'] = self.create_spacers( (11, ), (vlan.type, ))[0] * ' ' bottom_text += self._render( "show_mac_address_table_interface_product_port_bottom", context=dict(context, vlan=vlan)) except exceptions.SoftboxenError: context['num_of_entries'] = counter text = self._render( 'show_mac_address_table_interface_product_port_top', context=context) else: context['num_of_entries'] = counter text = self._render( 'show_mac_address_table_interface_product_port_top', context=context) text += bottom_text self._write(text) elif self._validate(args, 'epon', 'interface', 'ePON', str, 'onu', 'port', str, 'state'): ont_name, ont_port_num = self._dissect(args, 'epon', 'interface', 'ePON', str, 'onu', 'port', str, 'state') ont_name = ont_name.replace(':', '/', 1) ont_port_name = ont_name + '/' + ont_port_num try: ont = self._model.get_ont('name', ont_name) except exceptions.SoftboxenError: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandExecutionError( command=command, template='parameter_error', template_scopes=('login', 'mainloop', 'ena')) ont_ports = self._model.get_ont_ports('ont_id', ont.id) if ont_ports is None: raise exceptions.CommandExecutionError( command=command, template='uni_port_error', template_scopes=('login', 'mainloop', 'ena')) try: ont_port = self._model.get_ont_port('name', ont_port_name) except exceptions.SoftboxenError: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandExecutionError( command=command, template='parameter_error', template_scopes=('login', 'mainloop', 'ena')) self.map_states(ont_port, 'ont_port') text = self._render( 'show_epon_interface_epon_ont_onu_port_ontport_state', context=dict(context, ont_port=ont_port)) self._write(text) else: full_command = command for arg in args: full_command += ' ' + arg context['full_command'] = full_command raise exceptions.CommandSyntaxError(command=command)
def change_directory(self, path, context=None): path = path.lower() if re.search('^(?:[^.]+/)+\.{1,2}$', path): raise exceptions.CommandExecutionError( template='invalid_management_function_error', template_scopes=('login', 'base', 'execution_errors'), command=None) if re.search('^(?:[^.]+/)+\.{1,2}(?:/.+)+$', path): raise exceptions.CommandExecutionError( template='invalid_address_error', template_scopes=('login', 'base', 'execution_errors'), command=None) allowed_path_components = ('unit-[0-9]+', 'port-[0-9]+', 'portgroup-[0-9]+', 'chan-[0-9]+', 'interface-[0-9]+', 'vcc-[0-9]+', 'alarm-[0-9]+', 'main', 'cfgm', 'fm', 'pm', 'status', 'eoam', 'fan', 'multicast', 'services', 'packet', 'srvc-[0-9]', 'macaccessctrl', 'tdmconnections', 'logports', 'logport-[0-9]', '1to1doubletag', '1to1singletag', 'mcast', 'nto1', 'pls', 'tls', '\.', '\.\.') components = [x for x in path.split('/') if x] if path.startswith('/'): if path == '/': if self.__name__ != 'root': return self._parent.change_directory(path, context=context) else: context['path'] = '/' return self if self.__name__ != 'root': subprocessor = self._parent.change_directory(path, context=context) else: context['path'] = '/' subprocessor = self.change_directory(path.lstrip('/'), context=context) elif path.startswith('.'): if path.startswith('...'): if '/' in path: raise exceptions.CommandExecutionError( template='invalid_address_error', template_scopes=('login', 'base', 'execution_errors'), command=None) else: raise exceptions.CommandExecutionError( command=None, template=None, template_scopes=() ) # TODO: fix exception to not require all fields as empty if path == '.': return self if path.startswith('./'): if path == './': return self return self.change_directory(path[2:], context=context) if path.startswith('..'): splitted_path = [x for x in context['path'].split('/') if x] exit_component = None if len(splitted_path) != 0: exit_component = splitted_path.pop() context['path'] = '/' + '/'.join(splitted_path) if exit_component in ('main', 'cfgm', 'fm', 'pm', 'status'): self.set_prompt_end_pos(context=context) if path != '..': return self.change_directory(path[3:], context=context) return self if path == '..' or path == '../': if self.__name__ == 'root': return self return self._parent if self.__name__ == 'root': return self.change_directory(path[3:], context=context) return self._parent.change_directory(path[3:], context=context) else: if not re.search('^(' + '|'.join(allowed_path_components) + ')$', components[0]): raise exceptions.CommandExecutionError( template='invalid_management_function_error', template_scopes=('login', 'base', 'execution_errors'), command=None) remaining_args = '/'.join(components[1:]) component_type = None component_id = None if '-' in components[0]: component_type = components[0].split('-')[0] component_id = components[0].split('-')[1] if component_type == 'port': if self.__name__ == 'portgroup': component_type = 'portgroupport' elif self.__name__ == 'mgmtunit': component_type = 'mgmtport' if component_type == 'unit': if component_id == '11': component_type = 'mgmtunit' if component_id == '13': try: self._model.get_mgmt_card('name', '13') except exceptions.InvalidInputError: component_type = 'unit' else: component_type = 'mgmtunit' if component_type == 'vcc': component_type = 'interface' command_processor = component_type.capitalize( ) + 'CommandProcessor' else: if components[0] in ('1to1doubletag', '1to1singletag', 'mcast', 'nto1', 'pls', 'tls'): if context['path'].split('/')[-1] in ('1to1doubletag', '1to1singletag', 'mcast', 'nto1', 'pls', 'tls'): raise exceptions.CommandExecutionError( command=None, template=None, template_scopes=() ) # TODO: fix exception to not require all fields as empty context['ServiceType'] = components[0] command_processor = 'SubpacketCommandProcessor' else: command_processor = components[0].capitalize( ) + 'CommandProcessor' if component_type: relation_is_valid = self._validate_layer_relation( component_type, self.__name__) else: relation_is_valid = self._validate_layer_relation( components[0], self.__name__) if components[0] not in ('main', 'cfgm', 'fm', 'pm', 'status'): if relation_is_valid is False: raise exceptions.CommandExecutionError( command=None, template=None, template_scopes=() ) # TODO: fix exception to not require all fields as empty if component_type == 'unit': if (self._model.version == '2200' and not 9 <= int(component_id) <= 12) or ( self._model.version == '2300' and not 7 <= int(component_id) <= 14) or ( self._model.version == '2500' and not 1 <= int(component_id) <= 21): raise exceptions.CommandExecutionError( command=None, template=None, template_scopes=() ) # TODO: fix exception to not require all fields as empty# if components[0] in ('main', 'cfgm', 'fm', 'pm', 'status'): if context['path'].split('/')[-1] in ('main', 'cfgm', 'fm', 'pm', 'status'): raise exceptions.CommandExecutionError( command=None, template='invalid_address_error', template_scopes=('login', 'base', 'execution_errors')) self._init_access_points( context=context ) # make sure all management_functions are loaded correctly if components[0] not in self.management_functions: raise exceptions.CommandExecutionError( command=None, template=None, template_scopes=() ) # TODO: fix exception to not require all fields as empty if context['path'] == '/': new_path = components[0] else: new_path = '/' + components[0] context['path'] += new_path self.set_prompt_end_pos(context=context) return self subprocessor = self._create_command_processor_obj( command_processor) if self.component_name: if components[0] == 'logports': component_name = self.component_name + '/L' elif component_type == 'portgroup': component_name = self.component_name + '/G' + component_id else: component_name = self.component_name + '/' + component_id subprocessor.set_component_name(component_name) else: if component_type == 'srvc': component_name = 'srvc-' + component_id else: component_name = component_id subprocessor.set_component_name(component_name) if component_type: component_exists = self._check_for_component(subprocessor) if component_exists is False: raise exceptions.CommandExecutionError( command=None, template=None, template_scopes=() ) # TODO: fix exception to not require all fields as empty if context['path'] == '/': new_path = components[0] else: new_path = '/' + components[0] context['path'] += new_path if len(remaining_args) > 0: subprocessor = subprocessor.change_directory(remaining_args, context=context) return subprocessor
def set(self, command, *args, context=None): scopes = ('login', 'base', 'set') card = self._model.get_card('name', self.component_name.split('/')[0]) if self._validate(args, *()): exc = exceptions.CommandSyntaxError(command=command) exc.template = 'syntax_error' exc.template_scopes = ('login', 'base', 'syntax_errors') raise exc elif self._validate(args, 'Portprofile', str) and context['path'].split('/')[-1] == 'cfgm' and 'SUVM'\ not in card.board_name and 'SUVD2' not in card.board_name and self.__name__ == 'port': profile, = self._dissect(args, 'Portprofile', str) try: port = self.get_component() port.set_profile(profile) except exceptions.SoftboxenError: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) elif self._validate(args, 'Portprofiles', str) and context['path'].split('/')[-1] == 'cfgm' and \ 'SUVD2' in card.board_name and self.__name__ == 'port': profile, = self._dissect(args, 'Portprofiles', str) try: port = self.get_component() port.set_profile(profile) except exceptions.SoftboxenError: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) elif self._validate(args, 'Portprofiles', str, str, str, str, str, str, str, str, str, str, str, str) and \ context['path'].split('/')[-1] == 'cfgm' and 'SUVM' in card.board_name and self.__name__ == 'port': en1, name1, elen1, en2, name2, elen2, en3, name3, elen3, en4, name4, mode = self._dissect( args, 'Portprofiles', str, str, str, str, str, str, str, str, str, str, str, str) try: port = self.get_component() en1 = True if en1.lower() == 'true' else False en2 = True if en2.lower() == 'true' else False en3 = True if en3.lower() == 'true' else False en4 = True if en4.lower() == 'true' else False port.set_profiles(en1, name1, int(elen1), en2, name2, int(elen2), en3, name3, int(elen3), en4, name4, mode) except exceptions.SoftboxenError: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) elif self._validate(args, 'AdministrativeStatus', str) and context['path'].split('/')[-1] == 'main': state, = self._dissect(args, 'AdministrativeStatus', str) try: port = self.get_component() if state == 'up': port.admin_up() elif state == 'down': port.admin_down() else: raise exceptions.SoftboxenError() except exceptions.SoftboxenError: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) elif self._validate(self.args_in_quotes_joiner(args=args), 'Labels', str, str, str) and context['path'].split('/')[-1] == 'main': label1, label2, description = self._dissect( self.args_in_quotes_joiner(args=args), 'Labels', str, str, str) try: port = self.get_component() port.set_label(label1, label2, description) except exceptions.SoftboxenError: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) elif self._validate(args, 'Mode', str) and context['path'].split('/')[-1] == 'cfgm' and "SUE" in \ card.board_name and self.__name__ == 'port' and card.product == 'ftth': if '"' in args[1]: _, mode = self.args_in_quotes_joiner(args=args) else: mode, = self._dissect(args, 'Mode', str) try: port = self.get_component() port.set_mode(mode) except exceptions.SoftboxenError: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) elif self._validate(args, 'Mode', str, str, str) and context['path'].split('/')[-1] == 'cfgm' and "SUE" in \ card.board_name and self.__name__ == 'port' and card.product == 'ftth': if '"' in args[1]: _, mode = self.args_in_quotes_joiner(args=args) else: mode, = self._dissect(args, 'Mode', str) try: port = self.get_component() port.set_mode(mode) except exceptions.SoftboxenError: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) elif self._validate(args, 'FlowControl', str) and context['path'].split('/')[-1] == 'cfgm' and "SUE" in \ card.board_name and self.__name__ == 'port' and card.product == 'ftth': ctrl, = self._dissect(args, 'FlowControl', str) try: port = self.get_component() port.set_flow_control(ctrl) except exceptions.SoftboxenError: raise exceptions.CommandExecutionError( command=command, template='invalid_property', template_scopes=('login', 'base', 'execution_errors')) else: raise exceptions.CommandSyntaxError(command=command)