예제 #1
0
    def start(self):
        if self._iVerbose: self._INFO('Starting')
        lsErrors = list()

        # Be idempotent
        if self.status(
                True,
                KiscRuntime.STATUS_STARTED) == KiscRuntime.STATUS_STARTED:
            if self._iVerbose: self._INFO('Already started')
            return lsErrors

        # Start the resource
        try:

            # ... add device
            lsCommand = [
                'ip',
                'link',
                'add',
                'name',
                self._dsConfig['name'],
            ]
            for sSetting in [
                    'address', 'mtu', 'txqueuelen', 'numtxqueues',
                    'numrxqueues'
            ]:
                if sSetting in self._dsConfig:
                    lsCommand.extend([sSetting, self._dsConfig[sSetting]])
            lsCommand.extend(['type', 'bridge'])
            KiscRuntime.shell(
                lsCommand, _bTrace=self._iVerbose >= KiscRuntime.VERBOSE_TRACE)

            # ... options
            for sSetting in [
                    'ageing_time', 'stp_state', 'priority', 'hello_time',
                    'forward_delay', 'max_age'
            ]:
                if sSetting in self._dsConfig:
                    KiscRuntime.echo(
                        self._dsConfig[sSetting],
                        '/sys/class/net/%s/bridge/%s' %
                        (self._dsConfig['name'], sSetting),
                        _bTrace=self._iVerbose >= KiscRuntime.VERBOSE_TRACE)

            # ... attach slaves
            for sDevice in self._dsConfig['devices'].split(','):
                KiscRuntime.shell(
                    [
                        'ip', 'link', 'set', sDevice, 'master',
                        self._dsConfig['name'], 'up'
                    ],
                    _bTrace=self._iVerbose >= KiscRuntime.VERBOSE_TRACE)

            # ... UP!
            KiscRuntime.shell(
                ['ip', 'link', 'set', self._dsConfig['name'], 'up'],
                _bTrace=self._iVerbose >= KiscRuntime.VERBOSE_TRACE)
            self._iStatus = KiscRuntime.STATUS_STARTED
            if self._iVerbose: self._INFO('Started')

        except OSError as e:
            if self._iVerbose: self._ERROR(str(e))
            self._iStatus = KiscRuntime.STATUS_ERROR
            lsErrors.append(str(e))

        # Done
        return lsErrors
예제 #2
0
파일: network_bond.py 프로젝트: idiap/KiSC
    def start(self):
        if self._iVerbose: self._INFO('Starting')
        lsErrors = list()

        # Be idempotent
        if self.status(
                True,
                KiscRuntime.STATUS_STARTED) == KiscRuntime.STATUS_STARTED:
            if self._iVerbose: self._INFO('Already started')
            return lsErrors

        # Start the resource
        try:

            # ... load bonding driver (but do not create any default device)
            KiscRuntime.shell(
                ['modprobe', 'bonding', 'max_bonds=0'],
                _bTrace=self._iVerbose >= KiscRuntime.VERBOSE_TRACE)

            # ... add device
            lsCommand = [
                'ip',
                'link',
                'add',
                'name',
                self._dsConfig['name'],
            ]
            for sSetting in [
                    'address', 'mtu', 'txqueuelen', 'numtxqueues',
                    'numrxqueues'
            ]:
                if sSetting in self._dsConfig:
                    lsCommand.extend([sSetting, self._dsConfig[sSetting]])
            lsCommand.extend(['type', 'bond', 'mode', self._dsConfig['mode']])
            KiscRuntime.shell(
                lsCommand, _bTrace=self._iVerbose >= KiscRuntime.VERBOSE_TRACE)

            # ... options
            for sSetting in [
                    'miimon', 'updelay', 'downdelay', 'use_carrier',
                    'arp_interval', 'arp_ip_target', 'arp_all_targets',
                    'arp_validate', 'primary_reselect', 'all_slaves_active',
                    'fail_over_mac', 'xmit_hash_policy', 'packets_per_slave',
                    'tlb_dynamic_lb', 'lacp_rate', 'ad_select', 'num_grat_arp',
                    'num_unsol_na', 'lp_interval', 'resend_igmp'
            ]:
                if sSetting in self._dsConfig:
                    KiscRuntime.echo(
                        self._dsConfig[sSetting],
                        '/sys/class/net/%s/bonding/%s' %
                        (self._dsConfig['name'], sSetting),
                        _bTrace=self._iVerbose >= KiscRuntime.VERBOSE_TRACE)

            # ... attach slaves
            for sDevice in self._dsConfig['devices'].split(','):
                KiscRuntime.shell(
                    [
                        'ip', 'link', 'set', sDevice, 'master',
                        self._dsConfig['name'], 'up'
                    ],
                    _bTrace=self._iVerbose >= KiscRuntime.VERBOSE_TRACE)

            # ... default/active slave
            for sSetting in ['active_slave', 'primary']:
                if sSetting in self._dsConfig:
                    KiscRuntime.echo(
                        self._dsConfig[sSetting],
                        '/sys/class/net/%s/bonding/%s' %
                        (self._dsConfig['name'], sSetting),
                        _bTrace=self._iVerbose >= KiscRuntime.VERBOSE_TRACE)

            # ... UP!
            KiscRuntime.shell(
                ['ip', 'link', 'set', self._dsConfig['name'], 'up'],
                _bTrace=self._iVerbose >= KiscRuntime.VERBOSE_TRACE)
            self._iStatus = KiscRuntime.STATUS_STARTED
            if self._iVerbose: self._INFO('Started')

        except OSError as e:
            if self._iVerbose: self._ERROR(str(e))
            self._iStatus = KiscRuntime.STATUS_ERROR
            lsErrors.append(str(e))

        # Done
        return lsErrors