Esempio n. 1
0
 def do_deleteinterface(self, command, *args, context=None):
     card = self._model.get_card('name',
                                 self._parent._parent.component_name)
     if self._validate(args, str) and context['path'].split(
             '/'
     )[-1] == 'cfgm' and card.product != 'adsl' and card.product != 'sdsl':
         # all or interface_id
         name, = self._dissect(args, str)
         if name == 'all':
             chan = self.get_component()
             for interface in self._model.get_interfaces(
                     'chan_id', chan.id):
                 interface.delete()
         elif name.startswith('interface-'):
             id = name.split('-')[1]
             try:
                 interface = self._model.get_interface(
                     'name', self.component_name + '/' + id)
                 interface.delete()
             except exceptions.SoftboxenError:
                 raise exceptions.CommandSyntaxError(command=command)
         else:
             raise exceptions.CommandSyntaxError(command=command)
     else:
         raise exceptions.CommandSyntaxError(command=command)
    def do_createservice(self, command, *args, context=None):
        if context['ServiceType'] == 'nto1' and context['path'].split(
                '/')[-1] == 'cfgm':
            if len(args) == 12:
                address, svid = self._dissect(args[:2], str, str)
                # TODO: validate address
                srvc = self._model.add_srvc(service_type='nto1',
                                            address=address,
                                            svid=svid)

            else:
                raise exceptions.CommandSyntaxError(command=command)

        elif context['ServiceType'] == '1to1singletag' and context[
                'path'].split('/')[-1] == 'cfgm':
            if len(args) == 4:
                address, svid = self._dissect(args[:2], str, str)
                # TODO: validate address
                srvc = self._model.add_srvc(service_type='1to1singletag',
                                            address=address,
                                            svid=svid)

            else:
                raise exceptions.CommandSyntaxError(command=command)
        else:
            raise exceptions.CommandSyntaxError(command=command)
Esempio n. 3
0
    def do_createinterface(self, command, *args, context=None):
        scopes = ('login', 'base', 'set')
        card = self._model.get_card('name', self._parent._parent.component_name)
        if self._validate(args, str) and context['path'].split('/')[-1] == 'cfgm' and card.product == 'sdsl':
            # vcc profile and vlan profile
            vlan_prof, = self._dissect(args, str)
            # TODO: Check if profiles := default or profile names
            try:
                logport = self._model.get_logport('name', self.component_name)
                id = 1
                for interface in self._model.get_interfaces('logport_id', logport.id):
                    if interface.logport_id is not None:
                        new_id = int(interface.name[-1]) + 1
                        id = new_id if new_id > id else id
                try:
                    self._model.get_interface('name',  self.component_name + '/' + str(id))
                    assert False
                except exceptions.SoftboxenError:
                    self._model.add_interface(logport_id=logport.id, vlan_profile=vlan_prof)
                    context['spacer1'] = self.create_spacers((57,), (str(id),))[0] * ' '
                    context['id'] = str(id)
                    # TODO: Template is unknown
                    text = self._render('interface_success', *scopes, context=context)
                    self._write(text)
                except AssertionError:
                    raise exceptions.CommandSyntaxError(command=command)

            except exceptions.SoftboxenError:
                raise exceptions.CommandSyntaxError(command=command)
        else:
            raise exceptions.CommandSyntaxError(command=command)
Esempio n. 4
0
    def do_software_mngt(self, command, *args, context=None):
        if self._validate(args, 'shub', 'database', 'save'):
            return

        elif self._validate(args, 'database', 'upload', str):
            target_file, = self._dissect(args, 'database', 'upload', str)

            if target_file.startswith('actual-active:') and target_file.endswith('.tar'):
                self._model.set_upload_progress('upload-ongoing')
                self._model.upload_progress = 'upload-ongoing'

                subprocess = threading.Thread(target=self.simulate_upload, args=(self._model,))
                subprocess.start()

            else:
                raise exceptions.CommandSyntaxError(command=command)

        elif self._validate(args, 'oswp', '2', 'download', str):
            path, = self._dissect(args, 'oswp', '2', 'download', str)
            if path.count('/') > 0:
                path_pieces = path.split('/')
                try:
                    assert path_pieces[0] == 'firmware'
                    assert path_pieces[1] == 'isam'
                    sleep(5)
                    pass
                except (exceptions.SoftboxenError, AssertionError):
                    raise exceptions.CommandSyntaxError(command=command)
        else:
            raise exceptions.CommandSyntaxError(command=command)
Esempio n. 5
0
 def get_property(self, command, *args, context=None):
     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, 'ServiceStatus') and context['path'].split('/')[-1] == 'status':
         vcc = self.get_component()
         context['spacer1'] = self.create_spacers((67,), (vcc.vcc_profile,))[0] * ' '
         context['spacer2'] = self.create_spacers((67,), (vcc.vlan_profile,))[0] * ' '
         text = self._render('service_status', *scopes, context=dict(context, vcc=vcc))
         self._write(text)
     elif self._validate(args, 'configuredProfiles') and context['path'].split('/')[-1] == 'cfgm':
         vcc = self.get_component()
         services_connected = '"' + vcc.services_connected + '"'
         context['vcc_services_connected'] = services_connected
         context['spacer1'] = self.create_spacers((67,), (vcc.number_of_conn_services,))[0] * ' '
         context['spacer2'] = self.create_spacers((67,), (vcc.reconfiguration_allowed,))[0] * ' '
         context['spacer3'] = self.create_spacers((67,), (services_connected,))[0] * ' '
         text = self._render('configured_profiles', *scopes, context=dict(context, vcc=vcc))
         self._write(text)
     elif self._validate(args, 'VlanProfile') and context['path'].split('/')[-1] == 'cfgm':
         vcc = self.get_component()
         context['spacer1'] = self.create_spacers((67,), (vcc.vlan_profile,))[0] * ' '
         text = self._render('vlan_profile', *scopes, context=dict(context, vcc=vcc))
         self._write(text)
     elif self._validate(args, 'IfRateLimiting') and context['path'].split('/')[-1] == 'cfgm':
         vcc = self.get_component()
         text = self._render('if_rate_limiting', *scopes, context=dict(context, vcc=vcc))
         self._write(text)
     else:
         raise exceptions.CommandSyntaxError(command=command)
    def do_deactivate(self, command, *args, context=None):
        if context['iftype'] == 'vlanif':
            raise exceptions.CommandSyntaxError(command=command)
        if context['iftype'] not in ('adsl', 'vdsl'):
            raise exceptions.CommandSyntaxError(command=command)
        card = context['component']
        if self._validate(args, 'all'):
            self.card_ports_down(card)
        elif self._validate(args, str):
            port_identifier, = self._dissect(args, str)
            try:
                portname = card.name + '/' + port_identifier
                port = self._model.get_port("name", portname)

            except exceptions.SoftboxenError:
                raise exceptions.CommandSyntaxError(command=command)

            if port.admin_state == '0':
                self._write(
                    self._render('port_has_been_deactivated',
                                 context=dict(
                                     context,
                                     port_name=port.name.split('/')[2])))
                return

            port.admin_down()
        else:
            raise exceptions.CommandSyntaxError(command=command)
    def do_ip(self, command, *args, context=None):
        if self._validate(args, 'address', str, str):
            ip, subnet_mask = self._dissect(args, 'address', str, str)
            if context['iftype'] == 'vlanif':
                vlan_if = context['component']
                try:
                    assert re.match("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", ip)
                    assert ip.count('.') == 3
                    for i in ip.split('.'):
                        assert 0 <= int(i) <= 255

                    assert re.match("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+",
                                    subnet_mask)
                    assert subnet_mask.count('.') == 3
                    for i in subnet_mask.split('.'):
                        assert 0 <= int(i) <= 255
                except (AssertionError, ValueError):
                    raise exceptions.CommandSyntaxError(command=command)

                sub_value = IPv4Network('0.0.0.0/' + subnet_mask).prefixlen
                vlan_if.set('internet_address', ip)
                vlan_if.set('subnet_num', str(sub_value))
                vlan_if.set('internet_protocol', 'enabled')
                box = self._model
                box.set_network_address(ip)
            else:
                raise exceptions.CommandSyntaxError(command=command)

        else:
            raise exceptions.CommandSyntaxError(command=command)
Esempio n. 8
0
 def set(self, command, *args, context=None):
     card = self._model.get_card('name',
                                 self._parent._parent.component_name)
     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',
                         str) and 'SUV' in card.board_name:
         name, = self._dissect(args, 'chanprofile', str)
         try:
             #TODO: Check if profile with this name exists or default
             channel = self.get_component()
             channel.set_profile_name(name)
         except exceptions.SoftboxenError:
             raise exceptions.CommandSyntaxError(command=command)
     elif self._validate(args, 'ProfileName',
                         str) and 'SUV' not in card.board_name:
         name, = self._dissect(args, 'ProfileName', str)
         try:
             # TODO: Check if profile with this name exists or default
             channel = self.get_component()
             channel.set_profile_name(name)
         except exceptions.SoftboxenError:
             raise exceptions.CommandSyntaxError(command=command)
     else:
         raise exceptions.CommandSyntaxError(command=command)
Esempio n. 9
0
    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)
Esempio n. 10
0
 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
     else:
         raise exceptions.CommandSyntaxError(command=command)
Esempio n. 11
0
 def do_display(self, command, *args, context=None):
     if self._validate(args, 'system', 'status', 'collection'):
         try:
             text = context['text']
         except KeyError:
             raise exceptions.CommandSyntaxError(command=command)
         self._write(text)
     else:
         raise exceptions.CommandSyntaxError(command=command)
Esempio n. 12
0
 def do_ftpserver(self, command, *args, context=None):
     if self._validate(args, str, str, str):
         ip, login, pw = self._dissect(args, str, str, str)
         try:
             self._model.set_ftp_data(ip, login, pw)
         except exceptions.SoftboxenError:
             raise exceptions.CommandSyntaxError(command=command)
     else:
         raise exceptions.CommandSyntaxError(command=command)
Esempio n. 13
0
    def prepare_template_vars(self, s_port, command):
        if s_port.connected_type == 'port':
            try:
                port = self._model.get_port('id', s_port.connected_id)
                card = self._model.get_card('id', port.card_id)
                s_vlan = self._model.get_service_vlan('service_port_id',
                                                      s_port.id)
                vlan = self._model.get_vlan('id', s_vlan.vlan_id)
            except exceptions.SoftboxenError:
                raise exceptions.CommandSyntaxError(command=command)

        elif s_port.connected_type == 'ont':
            try:
                ont_port = self._model.get_ont_port('id', s_port.connected_id)
                ont = self._model.get_ont('id', ont_port.ont_id)
                port = self._model.get_port('id', ont.port_id)
                card = self._model.get_card('id', port.card_id)
                s_vlan = self._model.get_service_vlan('service_port_id',
                                                      s_port.id)
                vlan = self._model.get_vlan('id', s_vlan.vlan_id)
            except exceptions.SoftboxenError:
                raise exceptions.CommandSyntaxError(command=command)

        elif s_port.connected_type == 'cpe':
            try:
                cpe_port = self._model.get_cpe_port('id', s_port.connected_id)
                cpe = self._model.get_cpe('id', cpe_port.cpe_id)
                try:
                    port = self._model.get_port('id', cpe.port_id)
                    card = self._model.get_card('id', port.card_id)
                except exceptions.SoftboxenError:
                    ont_port = self._model.get_ont_port('id', cpe.ont_port_id)
                    ont = self._model.get_ont('id', ont_port.ont_id)
                    port = self._model.get_port('id', ont.port_id)
                    card = self._model.get_card('id', port.card_id)
                s_vlan = self._model.get_service_vlan('service_port_id',
                                                      s_port.id)
                vlan = self._model.get_vlan('id', s_vlan.vlan_id)
            except exceptions.SoftboxenError:
                raise exceptions.CommandSyntaxError(command=command)

        else:
            raise exceptions.CommandSyntaxError(command=command)

        if card.product == 'vdsl':
            porttype = 'vdl'
        elif card.product == 'adsl':
            porttype = 'adl'
        elif card.product == 'ftth':
            porttype = 'eth'
        elif card.product == 'ftth-pon':
            porttype = 'gpon'
        else:
            raise exceptions.CommandSyntaxError(command=command)

        return port, card, vlan, porttype
Esempio n. 14
0
    def do_help(self, command, *args, context=None):
        help_scopes = ('login', 'base', 'help')
        if self._validate(args, str):
            help_arg, = self._dissect(args, str)

            if help_arg == 'cd':
                self._write(
                    self._render('help_cd', *help_scopes, context=context))
            elif help_arg == 'pwd':
                self._write(
                    self._render('help_pwd', *help_scopes, context=context))
            elif help_arg == 'ls':
                self._write(
                    self._render('help_ls', *help_scopes, context=context))
            elif help_arg == 'show':
                self._write(
                    self._render('help_show', *help_scopes, context=context))
            elif help_arg == 'mode':
                self._write(
                    self._render('help_mode', *help_scopes, context=context))
            elif help_arg == 'ftpserver':
                self._write(
                    self._render('help_ftpserver',
                                 *help_scopes,
                                 context=context))
            elif help_arg == 'upload':
                self._write(
                    self._render('help_upload', *help_scopes, context=context))
            elif help_arg == 'download':
                self._write(
                    self._render('help_download',
                                 *help_scopes,
                                 context=context))
            elif help_arg == 'get':
                self._write(
                    self._render('help_get', *help_scopes, context=context))
            elif help_arg == 'set':
                self._write(
                    self._render('help_set', *help_scopes, context=context))
            elif help_arg == 'profile':
                self._write(
                    self._render('help_profile', *help_scopes,
                                 context=context))
            elif help_arg == 'help':
                self._write(
                    self._render('help_help', *help_scopes, context=context))
            elif help_arg == 'exit':
                self._write(
                    self._render('help_exit', *help_scopes, context=context))
            else:
                raise exceptions.CommandSyntaxError(command=command)
        elif self._validate(args, ):
            self._write(self._render('help', *help_scopes, context=context))
        else:
            raise exceptions.CommandSyntaxError(command=command)
Esempio n. 15
0
 def do_unlock(self, command, *args, context=None):
     card = self._model.get_card('name', self.component_name.split('/')[0])
     if len(args) == 0 and context['path'].split('/')[-1] == 'status' and (
             card.board_name.startswith('SUP') or
             card.board_name.startswith('SUI')) and self.__name__ == 'port':
         try:
             port = self.get_component()
             port.unlock_admin()
         except exceptions.SoftboxenError:
             raise exceptions.CommandSyntaxError(command=command)
     else:
         raise exceptions.CommandSyntaxError(command=command)
Esempio n. 16
0
 def do_startmeltmeasurement(self, command, *args, context=None):
     card = self._model.get_card('name', self.component_name.split('/')[0])
     if len(args) == 0 and context['path'].split('/')[-1] == 'status' and card.product != 'isdn' \
             and self.__name__ == 'port':
         try:
             port = self.get_component()
             port.set_melttest_state('Running')
             time.sleep(5)
             port.set_melttest_state('Passed')
         except exceptions.SoftboxenError:
             raise exceptions.CommandSyntaxError(command=command)
     else:
         raise exceptions.CommandSyntaxError(command=command)
Esempio n. 17
0
 def do_startquickloopbacktest(self, command, *args, context=None):
     card = self._model.get_card('name', self.component_name.split('/')[0])
     if len(args) == 0 and context['path'].split('/')[-1] == 'status' and card.board_name.startswith('SUI') \
             and self.__name__ == 'port':
         try:
             port = self.get_component()
             port.set_test_state('Running')
             time.sleep(5)
             port.set_test_state('Passed')
         except exceptions.SoftboxenError:
             raise exceptions.CommandSyntaxError(command=command)
     else:
         raise exceptions.CommandSyntaxError(command=command)
Esempio n. 18
0
 def do_delete(self, command, *args, context=None):
     if self._validate(args, str) and context['path'].split('/')[-1] == 'cfgm':
         name, = self._dissect(args, str)
         if name.startswith('logport-'):
             id = name.split('-')[1]
             try:
                 port = self._model.get_logport('name', self._parent.component_name + '/L/' + id)
                 port.delete()
             except exceptions.SoftboxenError:
                 raise exceptions.CommandSyntaxError(command=command)
         else:
             raise exceptions.CommandSyntaxError(command=command)
     else:
         raise exceptions.CommandSyntaxError(command=command)
Esempio n. 19
0
    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)
Esempio n. 20
0
 def do_loopback_detection(self, command, *args, context=None):
     if self._validate(args, 'action', str):
         prop, = self._dissect(args,  'action', str)
         box = self._model
         box.set('loopback_detection_action', prop)
     else:
         raise exceptions.CommandSyntaxError(command=command)
Esempio n. 21
0
    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'))
Esempio n. 22
0
    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'))
Esempio n. 23
0
 def get_profile(self, command, context):
     srvprofid = context['srvprof'].id
     try:
         profile = self._model.get_port_profile('id', int(srvprofid))
     except exceptions.SoftboxenError:
         raise exceptions.CommandSyntaxError(command=command)
     return profile
Esempio n. 24
0
 def do_upload(self, command, *args, context=None):
     if self._validate(args, '/cfgm/configuration', str) and context['path'].split('/')[-1] != 'cfgm':
         path,  = self._dissect(args, '/cfgm/configuration', str)
         sleep(10)  # NOTE: as of now there is no ftp server mocking
         # mechanism so the only way to simulate an upload is by doing a sleep
     else:
         raise exceptions.CommandSyntaxError(command=command)
Esempio n. 25
0
 def do_forwarding(self, command, *args, context=None):
     if self._validate(args, 'vlan-mac'):
         context['srvprof'].vlan_mac = 'forwarding'
         text = self._render('please_wait_commit', context=context)
         self._write(text)
     else:
         raise exceptions.CommandSyntaxError(command=command)
Esempio n. 26
0
 def create(self, p1, p2, p3, p4, profile, command):
     ids = []
     ids.append(int(p1.split('-')[1])) if p1.startswith('port-') else ids
     ids.append(int(p2.split('-')[1])) if p2.startswith('port-') else ids
     ids.append(int(p3.split('-')[1])) if p3.startswith('port-') else ids
     ids.append(int(p4.split('-')[1])) if p4.startswith('port-') else ids
     if len(ids) > 0:
         ids.sort()
         try:
             for x in ids:
                 self._model.get_logport(
                     'name', self._parent.component_name + '/L/' + str(x))
                 break
         except exceptions.SoftboxenError:
             name = self._parent.component_name + '/L/' + str(ids[0])
             ports = 'ports: '
             for x in ids:
                 ports += str(x) + ', '
             card = self._model.get_card('name',
                                         self._parent.component_name)
             logport = self._model.add_logport(card_id=card.id,
                                               name=name,
                                               ports=ports[:-2])
             logport = self._model.get_logport('name', name)
             logport.set_profile(profile)
     else:
         raise exceptions.CommandSyntaxError(command=command)
Esempio n. 27
0
 def do_description(self, command, *args, context=None):
     if self._validate(args, str):
         descr, = self._dissect(args, str)
         port = self.get_actual_port(command)
         port.set('description', descr)
     else:
         raise exceptions.CommandSyntaxError(command=command)
Esempio n. 28
0
    def _default_command_handler(self, command, *args, context=None):
        try:
            text = self._render(command, *args, context=context)

        except exceptions.TemplateError:
            raise exceptions.CommandSyntaxError(command=command)

        self._write(text)
Esempio n. 29
0
 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)
Esempio n. 30
0
 def on_help(self, command, *args, context=None):
     if args == ():
         text = self._render(
             'help',
             context=context)
         self._write(text)
     else:
         raise exceptions.CommandSyntaxError(command=command)