Пример #1
0
    def verify(self, tunable):

        errors = []
        if self.datastore.exists('tunables', ('var', '=', tunable['var'])):
            errors.append(
                ('var', errno.EEXIST, 'This variable already exists.'))

        if '"' in tunable['value'] or "'" in tunable['value']:
            errors.append(('value', errno.EINVAL, 'Quotes are not allowed'))

        if tunable['type'] in ('LOADER', 'RC') and not VAR_LOADER_RC_RE.match(
                tunable['var']):
            errors.append(('var', errno.EINVAL, VAR_SYSCTL_FORMAT))
        elif tunable['type'] == 'SYSCTL':
            if not VAR_SYSCTL_RE.match(tunable['var']):
                errors.append(('var', errno.EINVAL, VAR_LOADER_RC_FORMAT))
            try:
                sysctl.sysctlnametomib(tunable['var'])
            except OSError:
                errors.append(
                    ('var', errno.EINVAL, 'Sysctl variable does not exist'))

        if errors:
            raise ValidationException(errors)

        return ['system']
    def verify(self, id, updated_fields):

        tunable = self.datastore.get_by_id('tunables', id)
        if tunable is None:
            raise VerifyException(errno.ENOENT, 'Tunable with given ID does not exist')

        errors = ValidationException()

        if 'var' in updated_fields and self.datastore.exists(
            'tunables', ('and', [('var', '=', updated_fields['var']), ('id', '!=', id)])
        ):
            errors.add((1, 'var'), 'This variable already exists.', code=errno.EEXIST)

        if 'value' in updated_fields and '"' in updated_fields['value'] or "'" in updated_fields['value']:
            errors.add((1, 'value'), 'Quotes are not allowed')

        if 'type' in updated_fields:
            if updated_fields['type'] in ('LOADER', 'RC') and not VAR_LOADER_RC_RE.match(tunable['var']):
                errors.add((1, 'var'), VAR_SYSCTL_FORMAT)
            elif updated_fields['type'] == 'SYSCTL':
                if not VAR_SYSCTL_RE.match(tunable['var']):
                    errors.add((1, 'var'), VAR_LOADER_RC_FORMAT)
                try:
                    sysctl.sysctlnametomib(tunable['var'])
                except OSError:
                    errors.add((1, 'var'), 'Sysctl variable does not exist')

        if errors:
            raise errors

        return ['system']
def sysctl_set(name, value):
    # Make sure sysctl name exists
    sysctl.sysctlnametomib(name)

    # FIXME: sysctl module doesn't handle types very well
    # sysctl.sysctl(mib, new=value)
    try:
        system('sysctl', '{0}={1}'.format(name, str(value)))
    except SubprocessException as e:
        # sysctl module compatibility
        raise OSError(str(e.err))
Пример #4
0
def sysctl_set(name, value):
    # Make sure sysctl name exists
    sysctl.sysctlnametomib(name)

    # FIXME: sysctl module doesn't handle types very well
    # sysctl.sysctl(mib, new=value)
    try:
        system('sysctl', '{0}={1}'.format(name, str(value)))
    except SubprocessException as e:
        # sysctl module compatibility
        raise OSError(str(e.err))
Пример #5
0
    def run(self, id, updated_fields):
        tunable = self.datastore.get_by_id('tunables', id)
        if tunable is None:
            raise TaskException(errno.ENOENT,
                                'Tunable with given ID does not exist')

        if 'type' in updated_fields:
            if updated_fields['type'] in ('LOADER',
                                          'RC') and not VAR_LOADER_RC_RE.match(
                                              tunable['var']):
                raise TaskException(errno.EINVAL, VAR_SYSCTL_FORMAT)
            elif updated_fields['type'] == 'SYSCTL':
                if not VAR_SYSCTL_RE.match(tunable['var']):
                    raise TaskException(errno.EINVAL, VAR_LOADER_RC_FORMAT)
                try:
                    sysctl.sysctlnametomib(tunable['var'])
                except OSError:
                    raise TaskException(errno.ENOENT,
                                        'Sysctl variable does not exist')

        try:
            tunable.update(updated_fields)

            if tunable.get('enabled') and tunable['type'] == 'SYSCTL':
                sysctl_set(tunable['var'], tunable['value'])

            self.datastore.update('tunables', id, tunable)
            self.dispatcher.dispatch_event('tunable.changed', {
                'operation': 'update',
                'ids': [id]
            })

            # Could be enabled and now disabled, so generate either way
            if tunable['type'] == 'LOADER':
                self.dispatcher.call_sync('etcd.generation.generate_group',
                                          'loader',
                                          timeout=600)
            elif tunable['type'] == 'RC':
                self.dispatcher.call_sync('etcd.generation.generate_group',
                                          'services')
        except DatastoreException as e:
            raise TaskException(errno.EBADMSG,
                                'Cannot update Tunable: {0}'.format(str(e)))
        except RpcException as e:
            raise TaskException(errno.ENXIO,
                                'Cannot generate tunable: {0}'.format(str(e)))
        except OSError as e:
            raise TaskException(errno.ENXIO,
                                'Failed to set sysctl: {0}'.format(str(e)))
Пример #6
0
    def verify(self, tunable):

        errors = ValidationException()

        if '"' in tunable['value'] or "'" in tunable['value']:
            errors.add((1, 'value'), 'Quotes are not allowed')

        if tunable['type'] in ('LOADER', 'RC') and not VAR_LOADER_RC_RE.match(tunable['var']):
            errors.add((1, 'var'), VAR_SYSCTL_FORMAT)
        elif tunable['type'] == 'SYSCTL':
            if not VAR_SYSCTL_RE.match(tunable['var']):
                errors.add((1, 'var'), VAR_LOADER_RC_FORMAT)
            try:
                sysctl.sysctlnametomib(tunable['var'])
            except OSError:
                errors.add((1, 'var'), 'Sysctl variable does not exist')

        if errors:
            raise errors

        return ['system']
Пример #7
0
    def verify(self, tunable):

        errors = ValidationException()

        if '"' in tunable['value'] or "'" in tunable['value']:
            errors.add((1, 'value'), 'Quotes are not allowed')

        if tunable['type'] in ('LOADER', 'RC') and not VAR_LOADER_RC_RE.match(
                tunable['var']):
            errors.add((1, 'var'), VAR_SYSCTL_FORMAT)
        elif tunable['type'] == 'SYSCTL':
            if not VAR_SYSCTL_RE.match(tunable['var']):
                errors.add((1, 'var'), VAR_LOADER_RC_FORMAT)
            try:
                sysctl.sysctlnametomib(tunable['var'])
            except OSError:
                errors.add((1, 'var'), 'Sysctl variable does not exist')

        if errors:
            raise errors

        return ['system']
Пример #8
0
    def run(self, id, updated_fields):
        tunable = self.datastore.get_by_id('tunables', id)
        if tunable is None:
            raise TaskException(errno.ENOENT, 'Tunable with given ID does not exist')

        if 'type' in updated_fields:
            if updated_fields['type'] in ('LOADER', 'RC') and not VAR_LOADER_RC_RE.match(tunable['var']):
                raise TaskException(errno.EINVAL, VAR_SYSCTL_FORMAT)
            elif updated_fields['type'] == 'SYSCTL':
                if not VAR_SYSCTL_RE.match(tunable['var']):
                    raise TaskException(errno.EINVAL, VAR_LOADER_RC_FORMAT)
                try:
                    sysctl.sysctlnametomib(tunable['var'])
                except OSError:
                    raise TaskException(errno.ENOENT, 'Sysctl variable does not exist')

        try:
            tunable.update(updated_fields)

            if tunable.get('enabled') and tunable['type'] == 'SYSCTL':
                sysctl_set(tunable['var'], tunable['value'])

            self.datastore.update('tunables', id, tunable)
            self.dispatcher.dispatch_event('tunable.changed', {
                'operation': 'update',
                'ids': [id]
            })

            # Could be enabled and now disabled, so generate either way
            if tunable['type'] == 'LOADER':
                self.dispatcher.call_sync('etcd.generation.generate_group', 'loader', timeout=600)
            elif tunable['type'] == 'RC':
                self.dispatcher.call_sync('etcd.generation.generate_group', 'services')
        except DatastoreException as e:
            raise TaskException(errno.EBADMSG, 'Cannot update Tunable: {0}'.format(str(e)))
        except RpcException as e:
            raise TaskException(errno.ENXIO, 'Cannot generate tunable: {0}'.format(str(e)))
        except OSError as e:
            raise TaskException(errno.ENXIO, 'Failed to set sysctl: {0}'.format(str(e)))
Пример #9
0
    def verify(self, tunable):

        errors = []
        if self.datastore.exists('tunables', ('var', '=', tunable['var'])):
            errors.append(('var', errno.EEXIST, 'This variable already exists.'))

        if '"' in tunable['value'] or "'" in tunable['value']:
            errors.append(('value', errno.EINVAL, 'Quotes are not allowed'))

        if tunable['type'] in ('LOADER', 'RC') and not VAR_LOADER_RC_RE.match(tunable['var']):
            errors.append(('var', errno.EINVAL, VAR_SYSCTL_FORMAT))
        elif tunable['type'] == 'SYSCTL':
            if not VAR_SYSCTL_RE.match(tunable['var']):
                errors.append(('var', errno.EINVAL, VAR_LOADER_RC_FORMAT))
            try:
                sysctl.sysctlnametomib(tunable['var'])
            except OSError:
                errors.append(('var', errno.EINVAL, 'Sysctl variable does not exist'))

        if errors:
            raise ValidationException(errors)

        return ['system']
Пример #10
0
    def verify(self, id, updated_fields):

        tunable = self.datastore.get_by_id('tunables', id)
        if tunable is None:
            raise VerifyException(errno.ENOENT,
                                  'Tunable with given ID does not exists')

        errors = []

        if 'var' in updated_fields and self.datastore.exists(
                'tunables', ('and', [('var', '=', updated_fields['var']),
                                     ('id', '!=', id)])):
            errors.append(
                ('var', errno.EEXIST, 'This variable already exists.'))

        if 'value' in updated_fields and '"' in updated_fields[
                'value'] or "'" in updated_fields['value']:
            errors.append(('value', errno.EINVAL, 'Quotes are not allowed'))

        if 'type' in updated_fields:
            if updated_fields['type'] in ('LOADER',
                                          'RC') and not VAR_LOADER_RC_RE.match(
                                              tunable['var']):
                errors.append(('var', errno.EINVAL, VAR_SYSCTL_FORMAT))
            elif updated_fields['type'] == 'SYSCTL':
                if not VAR_SYSCTL_RE.match(tunable['var']):
                    errors.append(('var', errno.EINVAL, VAR_LOADER_RC_FORMAT))
                try:
                    sysctl.sysctlnametomib(tunable['var'])
                except OSError:
                    errors.append(('var', errno.EINVAL,
                                   'Sysctl variable does not exist'))

        if errors:
            raise ValidationException(errors)

        return ['system']