本文整理汇总了Python中middlewared.service.ValidationErrors类的典型用法代码示例。如果您正苦于以下问题:Python ValidationErrors类的具体用法?Python ValidationErrors怎么用?Python ValidationErrors使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ValidationErrors类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: do_update
async def do_update(self, job, data):
config = await self.config()
new = config.copy()
new.update(data)
verrors = ValidationErrors()
if not await self.middleware.call('zfs.pool.query', [('name', '=', data['pool'])]):
verrors.add('sysdataset_update.pool', f'Pool "{data["pool"]}" not found', errno.ENOENT)
if verrors:
raise verrors
new['syslog_usedataset'] = new['syslog']
new['rrd_usedataset'] = new['rrd']
await self.middleware.call('datastore.update', 'system.systemdataset', config['id'], new, {'prefix': 'sys_'})
if 'pool' in data and config['pool'] and data['pool'] != config['pool']:
await self.migrate(config['pool'], data['pool'])
if config['rrd'] != new['rrd']:
# Stop collectd to flush data
await self.middleware.call('service.stop', 'collectd')
await self.setup()
if config['syslog'] != new['syslog']:
await self.middleware.call('service.restart', 'syslogd')
if config['rrd'] != new['rrd']:
await self.rrd_toggle()
await self.middleware.call('service.restart', 'collectd')
return config
开发者ID:razzfazz,项目名称:freenas,代码行数:32,代码来源:sysdataset.py
示例2: validate_data
async def validate_data(self, data, schema):
verrors = ValidationErrors()
user = data.get('user')
if user:
# Windows users can have spaces in their usernames
# http://www.freebsd.org/cgi/query-pr.cgi?pr=164808
if ' ' in user:
verrors.add(
f'{schema}.user',
'Usernames cannot have spaces'
)
elif not (
await self.middleware.call(
'notifier.get_user_object',
user
)
):
verrors.add(
f'{schema}.user',
'Specified user does not exist'
)
return verrors, data
开发者ID:razzfazz,项目名称:freenas,代码行数:25,代码来源:cron.py
示例3: do_update
async def do_update(self, id, data):
"""
Update a kerberos realm by id. This will be automatically populated during the
domain join process in an Active Directory environment. Kerberos realm names
are case-sensitive, but convention is to only use upper-case.
"""
old = await self._get_instance(id)
new = old.copy()
new.update(data)
verrors = ValidationErrors()
verrors.add_child('kerberos_realm_update', await self._validate(new))
if verrors:
raise verrors
data = await self.kerberos_compress(new)
await self.middleware.call(
'datastore.update',
self._config.datastore,
id,
new,
{'prefix': self._config.datastore_prefix}
)
await self.middleware.call('etc.generate', 'kerberos')
return await self._get_instance(id)
开发者ID:freenas,项目名称:freenas,代码行数:28,代码来源:kerberos.py
示例4: __rquery_to_start_end
def __rquery_to_start_end(self, query):
unit = query.get('unit')
if unit:
verrors = ValidationErrors()
for i in ('start', 'end'):
if i in query:
verrors.add(
f'reporting_query.{i}',
f'{i!r} should only be used if "unit" attribute is not provided.',
)
verrors.check()
else:
if 'start' not in query:
unit = 'HOURLY'
else:
starttime = query['start']
endtime = query.get('end') or 'now'
if unit:
unit = unit[0].lower()
page = query['page']
starttime = f'end-{page + 1}{unit}'
if not page:
endtime = 'now'
else:
endtime = f'now-{page}{unit}'
return starttime, endtime
开发者ID:freenas,项目名称:freenas,代码行数:27,代码来源:reporting.py
示例5: do_update
async def do_update(self, data):
old = await self.config()
new = old.copy()
new.update(data)
verrors = ValidationErrors()
if not new["v4"] and new["v4_v3owner"]:
verrors.add("nfs_update.v4_v3owner", "This option requires enabling NFSv4")
if new["v4_v3owner"] and new["userd_manage_gids"]:
verrors.add(
"nfs_update.userd_manage_gids", "This option is incompatible with NFSv3 ownership model for NFSv4")
if verrors:
raise verrors
self.nfs_compress(new)
await self._update_service(old, new)
self.nfs_extend(new)
return new
开发者ID:razzfazz,项目名称:freenas,代码行数:25,代码来源:nfs.py
示例6: validate_data
async def validate_data(self, data, schema):
verrors = ValidationErrors()
smart_tests = await self.query(filters=[('type', '=', data['type'])])
configured_disks = [d for test in smart_tests for d in test['disks']]
disks_dict = {disk['identifier']: disk['name'] for disk in (await self.middleware.call('disk.query'))}
disks = data.get('disks')
used_disks = []
invalid_disks = []
for disk in disks:
if disk in configured_disks:
used_disks.append(disks_dict[disk])
if disk not in disks_dict.keys():
invalid_disks.append(disk)
if used_disks:
verrors.add(
f'{schema}.disks',
f'The following disks already have tests for this type: {", ".join(used_disks)}'
)
if invalid_disks:
verrors.add(
f'{schema}.disks',
f'The following disks are invalid: {", ".join(invalid_disks)}'
)
return verrors
开发者ID:razzfazz,项目名称:freenas,代码行数:29,代码来源:smart.py
示例7: do_update
async def do_update(self, data):
"""
Update AFP service settings.
`bindip` is a list of IPs to bind AFP to. Leave blank (empty list) to bind to all
available IPs.
`map_acls` defines how to map the effective permissions of authenticated users.
RIGHTS - Unix-style permissions
MODE - ACLs
NONE - Do not map
`chmod_request` defines advanced permission control that deals with ACLs.
PRESERVE - Preserve ZFS ACEs for named users and groups or POSIX ACL group mask
SIMPLE - Change permission as requested without any extra steps
IGNORE - Permission change requests are ignored
"""
old = await self.config()
new = old.copy()
new.update(data)
verrors = ValidationErrors()
if new['dbpath']:
await check_path_resides_within_volume(
verrors, self.middleware, 'afp_update.dbpath', new['dbpath'],
)
verrors.check()
new = await self.compress(new)
await self._update_service(old, new)
return await self.config()
开发者ID:freenas,项目名称:freenas,代码行数:35,代码来源:afp.py
示例8: common_validation
async def common_validation(self, data, schema_name):
verrors = ValidationErrors()
ip = data.get('ip')
if ip:
await resolve_hostname(self.middleware, verrors, f'{schema_name}.ip', ip)
management_ip = data.get('management_ip')
if management_ip and management_ip not in (await self.get_management_ip_choices()):
verrors.add(
f'{schema_name}.management_ip',
'Please select a valid IP for your TrueNAS system'
)
action = data.get('action')
if action and action != 'UNINSTALL':
if (
not (await self.middleware.call('vcenteraux.config'))['enable_https'] and
(await self.middleware.call('system.general.config'))['ui_protocol'].upper() == 'HTTPS'
):
verrors.add(
f'{schema_name}.action',
'Please enable vCenter plugin over HTTPS'
)
return verrors
开发者ID:razzfazz,项目名称:freenas,代码行数:26,代码来源:vcenter.py
示例9: do_create
async def do_create(self, data):
"""
Create an entry in the idmap backend table.
`unix_primary_group` If True, the primary group membership is fetched from the LDAP attributes (gidNumber).
If False, the primary group membership is calculated via the "primaryGroupID" LDAP attribute.
`unix_nss_info` if True winbind will retrieve the login shell and home directory from the LDAP attributes.
If False or if the AD LDAP entry lacks the SFU attributes the smb4.conf parameters `template shell` and `template homedir` are used.
`schema_mode` Defines the schema that idmap_ad should use when querying Active Directory regarding user and group information.
This can be either the RFC2307 schema support included in Windows 2003 R2 or the Service for Unix (SFU) schema.
For SFU 3.0 or 3.5 please choose "SFU", for SFU 2.0 please choose "SFU20". The behavior of primary group membership is
controlled by the unix_primary_group option.
"""
verrors = ValidationErrors()
data = await self.middleware.call('idmap.common_backend_compress', data)
verrors.add_child('idmap_ad_create', await self.middleware.call('idmap._common_validate', data))
if verrors:
raise verrors
data["id"] = await self.middleware.call(
"datastore.insert", self._config.datastore, data,
{
"prefix": self._config.datastore_prefix
},
)
return await self._get_instance(data['id'])
开发者ID:freenas,项目名称:freenas,代码行数:27,代码来源:idmap.py
示例10: do_create
async def do_create(self, data):
"""
Create AFP share.
`allow`, `deny`, `ro`, and `rw` are lists of users and groups. Groups are designated by
an @ prefix.
`hostsallow` and `hostsdeny` are lists of hosts and/or networks.
"""
verrors = ValidationErrors()
path = data['path']
await self.clean(data, 'sharingafp_create', verrors)
await self.validate(data, 'sharingafp_create', verrors)
await check_path_resides_within_volume(
verrors, self.middleware, 'sharingafp_create.path', path)
verrors.check()
if path and not os.path.exists(path):
try:
os.makedirs(path)
except OSError as e:
raise CallError(f'Failed to create {path}: {e}')
await self.compress(data)
data['id'] = await self.middleware.call(
'datastore.insert', self._config.datastore, data,
{'prefix': self._config.datastore_prefix})
await self.extend(data)
await self._service_change('afp', 'reload')
return data
开发者ID:freenas,项目名称:freenas,代码行数:35,代码来源:afp.py
示例11: do_update
async def do_update(self, data):
"""
Update Mail Service Configuration.
`fromemail` is used as a sending address which the mail server will use for sending emails.
`outgoingserver` is the hostname or IP address of SMTP server used for sending an email.
`security` is type of encryption desired.
`smtp` is a boolean value which when set indicates that SMTP authentication has been enabled and `user`/`pass`
are required attributes now.
"""
config = await self.config()
new = config.copy()
new.update(data)
new['security'] = new['security'].lower() # Django Model compatibility
verrors = ValidationErrors()
if new['smtp'] and new['user'] == '':
verrors.add(
'mail_update.user',
'This field is required when SMTP authentication is enabled',
)
self.__password_verify(new['pass'], 'mail_update.pass', verrors)
if verrors:
raise verrors
await self.middleware.call('datastore.update', 'system.email', config['id'], new, {'prefix': 'em_'})
return await self.config()
开发者ID:freenas,项目名称:freenas,代码行数:34,代码来源:mail.py
示例12: do_update
async def do_update(self, id, data):
"""
Update idmap to backend mapping by id.
"""
old = await self._get_instance(id)
new = old.copy()
new.update(data)
new = await self.middleware.call('idmap.common_backend_compress', new)
verrors = ValidationErrors()
if new['domain'] in [dstype.DS_TYPE_LDAP.value, dstype.DS_TYPE_DEFAULT_DOMAIN.value]:
if new['idmap_backend'] not in ['ldap', 'tdb']:
verrors.add(
'domaintobackend_create.idmap_backend',
f'idmap backend [{new["idmap_backend"]}] is not appropriate for the system domain type {dstype[new["domain"]]}'
)
if verrors:
raise verrors
await self.middleware.call(
'datastore.update',
self._config.datastore,
id,
new,
{'prefix': self._config.datastore_prefix}
)
updated_entry = await self._get_instance(id)
try:
await self.middleware.call('idmap.get_or_create_idmap_by_domain', updated_entry['domain']['domain_name'])
except Exception as e:
self.logger.debug('Failed to generate new idmap backend: %s', e)
return updated_entry
开发者ID:freenas,项目名称:freenas,代码行数:33,代码来源:idmap.py
示例13: do_create
async def do_create(self, data):
"""
Create a kerberos keytab. Uploaded keytab files will be merged with the system
keytab under /etc/krb5.keytab.
`file` b64encoded kerberos keytab
`name` name for kerberos keytab
"""
verrors = ValidationErrors()
verrors.add_child('kerberos_principal_create', await self._validate(data))
if verrors:
raise verrors
data = await self.kerberos_keytab_compress(data)
data["id"] = await self.middleware.call(
"datastore.insert", self._config.datastore, data,
{
"prefix": self._config.datastore_prefix
},
)
await self.middleware.call('etc.generate', 'kerberos')
return await self._get_instance(data['id'])
开发者ID:freenas,项目名称:freenas,代码行数:25,代码来源:kerberos.py
示例14: do_create
async def do_create(self, data):
"""
Create a new group.
If `gid` is not provided it is automatically filled with the next one available.
`allow_duplicate_gid` allows distinct group names to share the same gid.
`users` is a list of user ids (`id` attribute from `user.query`).
"""
verrors = ValidationErrors()
await self.__common_validation(verrors, data, 'group_create')
verrors.check()
if not data.get('gid'):
data['gid'] = await self.get_next_gid()
group = data.copy()
group['group'] = group.pop('name')
users = group.pop('users', [])
pk = await self.middleware.call('datastore.insert', 'account.bsdgroups', group, {'prefix': 'bsdgrp_'})
for user in users:
await self.middleware.call('datastore.insert', 'account.bsdgroupmembership', {'bsdgrpmember_group': pk, 'bsdgrpmember_user': user})
await self.middleware.call('service.reload', 'user')
await self.middleware.call('smb.groupmap_add', data['name'])
return pk
开发者ID:freenas,项目名称:freenas,代码行数:33,代码来源:account.py
示例15: do_create
def do_create(self, data):
"""
Creates a ZFS dataset.
"""
verrors = ValidationErrors()
if '/' not in data['name']:
verrors.add('name', 'You need a full name, e.g. pool/newdataset')
if verrors:
raise verrors
properties = data.get('properties') or {}
sparse = properties.pop('sparse', False)
params = {}
for k, v in data['properties'].items():
params[k] = v
try:
with libzfs.ZFS() as zfs:
pool = zfs.get(data['name'].split('/')[0])
pool.create(data['name'], params, fstype=getattr(libzfs.DatasetType, data['type']), sparse_vol=sparse)
except libzfs.ZFSException as e:
self.logger.error('Failed to create dataset', exc_info=True)
raise CallError(f'Failed to create dataset: {e}')
开发者ID:razzfazz,项目名称:freenas,代码行数:27,代码来源:zfs.py
示例16: _validate
async def _validate(self, data):
verrors = ValidationErrors()
realms = await self.query()
for realm in realms:
if realm['realm'].upper() == data['realm'].upper():
verrors.add(f'kerberos_realm', f'kerberos realm with name {realm["realm"]} already exists.')
return verrors
开发者ID:freenas,项目名称:freenas,代码行数:7,代码来源:kerberos.py
示例17: validate_data
async def validate_data(self, data, schema):
verrors = ValidationErrors()
pool_pk = data.get('pool')
if pool_pk:
pool_obj = await self.middleware.call(
'datastore.query',
'storage.volume',
[('id', '=', pool_pk)]
)
if len(pool_obj) == 0:
verrors.add(
f'{schema}.pool',
'The specified volume does not exist'
)
elif (
'id' not in data.keys() or
(
'id' in data.keys() and
'original_pool_id' in data.keys() and
pool_pk != data['original_pool_id']
)
):
scrub_obj = await self.query(filters=[('pool', '=', pool_pk)])
if len(scrub_obj) != 0:
verrors.add(
f'{schema}.pool',
'A scrub with this pool already exists'
)
return verrors, data
开发者ID:razzfazz,项目名称:freenas,代码行数:32,代码来源:pool.py
示例18: do_create
async def do_create(self, data):
"""
Creates a dataset/zvol.
`volsize` is required for type=VOLUME and is supposed to be a multiple of the block size.
"""
verrors = ValidationErrors()
if '/' not in data['name']:
verrors.add('pool_dataset_create.name', 'You need a full name, e.g. pool/newdataset')
else:
await self.__common_validation(verrors, 'pool_dataset_create', data, 'CREATE')
if verrors:
raise verrors
props = {}
for i, real_name, transform in (
('atime', None, str.lower),
('casesensitivity', None, str.lower),
('comments', 'org.freenas:description', None),
('compression', None, str.lower),
('copies', None, lambda x: str(x)),
('deduplication', 'dedup', str.lower),
('exec', None, str.lower),
('quota', None, _none),
('readonly', None, str.lower),
('recordsize', None, None),
('refquota', None, _none),
('refreservation', None, _none),
('reservation', None, _none),
('snapdir', None, str.lower),
('sparse', None, None),
('sync', None, str.lower),
('volblocksize', None, None),
('volsize', None, lambda x: str(x)),
):
if i not in data:
continue
name = real_name or i
props[name] = data[i] if not transform else transform(data[i])
await self.middleware.call('zfs.dataset.create', {
'name': data['name'],
'type': data['type'],
'properties': props,
})
data['id'] = data['name']
await self.middleware.call('zfs.dataset.mount', data['name'])
if data['type'] == 'FILESYSTEM':
await self.middleware.call(
'notifier.change_dataset_share_type', data['name'], data.get('share_type', 'UNIX').lower()
)
return await self._get_instance(data['id'])
开发者ID:razzfazz,项目名称:freenas,代码行数:59,代码来源:pool.py
示例19: add_admin_group
async def add_admin_group(self, admin_group=None, check_deferred=False):
"""
Add a local or directory service group to BUILTIN\\Administrators (S-1-5-32-544)
Members of this group have elevated privileges to the Samba server (ability to
take ownership of files, override ACLs, view and modify user quotas, and administer
the server via the Computer Management MMC Snap-In. Unfortuntely, group membership
must be managed via "net groupmap listmem|addmem|delmem", which requires that
winbind be running when the commands are executed. In this situation, net command
will fail with WBC_ERR_WINBIND_NOT_AVAILABLE. If this error message is returned, then
flag for a deferred command retry when service starts.
@param-in (admin_group): This is the group to add to BUILTIN\\Administrators. If unset, then
look up the value in the config db.
@param-in (check_deferred): If this is True, then only perform the group mapping if this has
been flagged as in need of deferred setup (i.e. Samba wasn't running when it was initially
called). This is to avoid unecessarily calling during service start.
"""
verrors = ValidationErrors()
if check_deferred:
is_deferred = await self.middleware.call('cache.has_key', 'SMB_SET_ADMIN')
if not is_deferred:
self.logger.debug("No cache entry indicating delayed action to add admin_group was found.")
return True
else:
await self.middleware.call('cache.pop', 'SMB_SET_ADMIN')
if not admin_group:
smb = await self.middleware.call('smb.config')
admin_group = smb['admin_group']
# We must use GIDs because wbinfo --name-to-sid expects a domain prefix "FREENAS\user"
group = await self.middleware.call("notifier.get_group_object", admin_group)
if not group:
verrors.add('smb_update.admin_group', f"Failed to validate group: {admin_group}")
raise verrors
sid = await self.wbinfo_gidtosid(group[2])
if sid == "WBC_ERR_WINBIND_NOT_AVAILABLE":
self.logger.debug("Delaying admin group add until winbind starts")
await self.middleware.call('cache.put', 'SMB_SET_ADMIN', True)
return True
must_add_sid = await self.validate_admin_groups(sid)
if not must_add_sid:
return True
proc = await Popen(
['/usr/local/bin/net', 'groupmap', 'addmem', 'S-1-5-32-544', sid],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
output = await proc.communicate()
if proc.returncode != 0:
raise CallError(f'net groupmap addmem failed: {output[1].decode()}')
self.logger.debug(f"Successfully added {admin_group} to BUILTIN\\Administrators")
return True
开发者ID:freenas,项目名称:freenas,代码行数:57,代码来源:smb.py
示例20: do_update
async def do_update(self, id, data):
"""
Updates a dataset/zvol `id`.
"""
verrors = ValidationErrors()
dataset = await self.middleware.call('pool.dataset.query', [('id', '=', id)])
if not dataset:
verrors.add('id', f'{id} does not exist', errno.ENOENT)
else:
data['type'] = dataset[0]['type']
data['name'] = dataset[0]['name']
if data['type'] == 'VOLUME':
data['volblocksize'] = dataset[0]['volblocksize']['value']
await self.__common_validation(verrors, 'pool_dataset_update', data, 'UPDATE')
if verrors:
raise verrors
props = {}
for i, real_name, transform, inheritable in (
('atime', None, str.lower, True),
('comments', 'org.freenas:description', None, False),
('sync', None, str.lower, True),
('compression', None, str.lower, True),
('deduplication', 'dedup', str.lower, True),
('exec', None, str.lower, True),
('quota', None, _none, False),
('refquota', None, _none, False),
('reservation', None, _none, False),
('refreservation', None, _none, False),
('copies', None, None, False),
('snapdir', None, str.lower, True),
('readonly', None, str.lower, True),
('recordsize', None, None, True),
('volsize', None, lambda x: str(x), False),
):
if i not in data:
continue
name = real_name or i
if inheritable and data[i] == 'INHERIT':
props[name] = {'source': 'INHERIT'}
else:
props[name] = {'value': data[i] if not transform else transform(data[i])}
rv = await self.middleware.call('zfs.dataset.update', id, {'properties': props})
if data['type'] == 'FILESYSTEM' and 'share_type' in data:
await self.middleware.call(
'notifier.change_dataset_share_type', id, data['share_type'].lower()
)
elif data['type'] == 'VOLUME' and 'volsize' in data:
if await self.middleware.call('iscsi.extent.query', [('path', '=', f'zvol/{id}')]):
await self.middleware.call('service.reload', 'iscsitarget')
return rv
开发者ID:razzfazz,项目名称:freenas,代码行数:56,代码来源:pool.py
注:本文中的middlewared.service.ValidationErrors类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论