def verify(self, id, updated_fields, force=False): ntp = self.datastore.get_by_id('ntpservers', id) if ntp is None: raise VerifyException(errno.ENOENT, 'NTP Server with given ID does not exist') errors = ValidationException() try: if 'address' in updated_fields: system('ntpdate', '-q', updated_fields['address']) except SubprocessException: if not force: errors.append(( 'address', errno.EINVAL, 'Server could not be reached. Check "Force" to continue regardless.')) minpoll = updated_fields.get('minpoll', ntp.get('minpoll')) maxpoll = updated_fields.get('maxpoll', ntp.get('maxpoll')) if minpoll is not None and maxpoll is not None and not maxpoll > minpoll: errors.append(('maxpoll', errno.EINVAL, 'Max Poll should be higher than Min Poll')) if errors: raise ValidationException(errors) return ['system']
def verify(self, params): errors = ValidationException() if self.datastore.get_one('users', ('username', '=', params.get('user'))) is None: raise VerifyException( errno.ENOENT, 'User {0} does not exist'.format(params.get('user')) ) path = params.get('path') rmode = params.get('rsync_mode') remote_path = params.get('remote_path') remote_host = params.get('remote_host') remote_module = params.get('remote_module') if path in [None, ''] or path.isspace(): errors.append(('path', errno.EINVAL, 'The Path is required')) elif not os.path.exists(path): raise VerifyException( errno.ENOENT, "The specified path: '{0}'' does not exist".format(params.get('path')) ) if ( params.get('remote_host') in ['127.0.0.1', 'localhost'] and rmode == 'SSH' and remote_path is not None and not os.path.exists(remote_path) ): raise VerifyException( errno.ENOENT, "The specified path: '{0}'' does not exist".format(remote_path) ) if rmode == 'SSH' and (remote_path in [None, ''] or remote_path.isspace()): errors.append(('remote_path', errno.EINVAL, 'The Remote Path is required')) elif rmode == 'MODULE' and (remote_module in [None, ''] or remote_module.isspace()): errors.append(('remote_module', errno.EINVAL, 'The Remote Module is required')) if remote_host in [None, ''] or remote_host.isspace(): errors.append(('remote_host', errno.EINVAL, 'A Remote Host needs to be specified')) if errors: raise ValidationException(errors) return []