本文整理汇总了Python中datastore.config.ConfigNode类的典型用法代码示例。如果您正苦于以下问题:Python ConfigNode类的具体用法?Python ConfigNode怎么用?Python ConfigNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: verify
def verify(self, ftp):
errors = ValidationException()
node = ConfigNode('service.ftp', self.configstore).__getstate__()
node.update(ftp)
pmin = node['passive_ports_min']
if 'passive_ports_min' in ftp:
if pmin and (pmin < 1024 or pmin > 65535):
errors.add((0, 'passive_ports_min'), 'This value must be between 1024 and 65535, inclusive.')
pmax = node['passive_ports_max']
if 'passive_ports_max' in ftp:
if pmax and (pmax < 1024 or pmax > 65535):
errors.add((0, 'passive_ports_max'), 'This value must be between 1024 and 65535, inclusive.')
elif pmax and pmin and pmin >= pmax:
errors.add((0, 'passive_ports_max'), 'This value must be higher than minimum passive port.')
if node['only_anonymous'] and not node['anonymous_path']:
errors.add(
((0, 'anonymous_path'), errno.EINVAL, 'This field is required for anonymous login.')
)
if node['tls'] is True and not node['tls_ssl_certificate']:
errors.add((0, 'tls_ssl_certificate'), 'TLS specified without certificate.')
if node['tls_ssl_certificate']:
cert = self.dispatcher.call_sync('crypto.certificate.query', [('id', '=', node['tls_ssl_certificate'])])
if not cert:
errors.add((0, 'tls_ssl_certificate'), 'SSL Certificate not found.')
if errors:
raise errors
return ['system']
示例2: run
def run(self, ftp):
if ftp.get('filemask'):
ftp['filemask'] = get_integer(ftp['filemask'])
if ftp.get('dirmask'):
ftp['dirmask'] = get_integer(ftp['dirmask'])
if ftp.get('anonymous_path'):
if not os.path.exists(ftp['anonymous_path']):
raise TaskException(errno.ENOENT,
'Directory {0} does not exists'.format(ftp['anonymous_path']))
try:
node = ConfigNode('service.ftp', self.configstore)
node.update(ftp)
self.dispatcher.call_sync('etcd.generation.generate_group', 'ftp')
self.dispatcher.dispatch_event('service.ftp.changed', {
'operation': 'updated',
'ids': None,
})
except RpcException as e:
raise TaskException(
errno.ENXIO, 'Cannot reconfigure FTP: {0}'.format(str(e))
)
return 'RESTART'
示例3: verify
def verify(self, snmp):
errors = []
node = ConfigNode('service.snmp', self.configstore).__getstate__()
node.update(snmp)
if node['contact']:
if '@' in node['contact']:
if not jsonschema._format.is_email(node['contact']):
errors.append(('contact', errno.EINVAL, 'Invalid e-mail address'))
elif not re.match(r'^[-_a-zA-Z0-9\s]+$', node['contact']):
errors.append(('contact', errno.EINVAL, (
'Must contain only alphanumeric characters, _, - or a valid e-mail address')
))
if not node['community']:
if not node['v3']:
errors.append(('community', errno.ENOENT, 'This field is required'))
elif not re.match(r'^[-_a-zA-Z0-9\s]+$', node['community']):
errors.append(('community', errno.EINVAL, (
'The community must contain only alphanumeric characters, _ or -')
))
if node['v3_password'] and len(node['v3_password']) < 8:
errors.append(('v3_password', errno.EINVAL, 'Password must contain at least 8 characters'))
if node['v3_privacy_passphrase'] and len(node['v3_privacy_passphrase']) < 8:
errors.append(('v3_password', errno.EINVAL, 'Passphrase must contain at least 8 characters'))
if errors:
raise ValidationException(errors)
return ['system']
示例4: verify
def verify(self, openvpn):
interface_pattern = '(tap|tun)[0-9]'
node = ConfigNode('service.openvpn', self.configstore).__getstate__()
node.update(openvpn)
if not re.search(interface_pattern, node['dev']):
raise VerifyException(errno.EINVAL,
'{0} Bad interface name. Allowed values tap/tun[0-9].'.format(node['dev']))
if node['server_bridge_extended']:
try:
bridge_ip = ipaddress.ip_address(node['server_bridge_ip'])
netmask = node['server_bridge_netmask']
ip_range_begin = ipaddress.ip_address(node['server_bridge_range_begin'])
ip_range_end = ipaddress.ip_address(node['server_bridge_range_end'])
subnet = ipaddress.ip_network('{0}/{1}'.format(bridge_ip, netmask), strict=False)
except ValueError as e:
raise VerifyException(errno.EINVAL, str(e))
if (ip_range_begin not in subnet) or (ip_range_end not in subnet):
raise VerifyException(errno.EINVAL,
'Provided range of remote client IP adresses is invalid.')
if (bridge_ip >= ip_range_begin) and (bridge_ip <= ip_range_end):
raise VerifyException(errno.EINVAL,
'Provided bridge IP address is in the client ip range.')
if (node['keepalive_ping_interval'] * 2) >= node['keepalive_peer_down']:
raise VerifyException(errno.EINVAL, 'The second parameter to keepalive must be'
'at least twice the value of the first parameter.'
'Recommended setting is keepalive 10 60.')
return ['system']
示例5: run
def run(self, ipfs):
try:
node = ConfigNode('service.ipfs', self.configstore)
old_path = node['path'].value
if 'path' in ipfs and ipfs['path'] != old_path:
if not os.path.exists(ipfs['path']):
os.makedirs(ipfs['path'])
# jkh says that the ipfs path should be owned by root
os.chown(ipfs['path'], 0, 0)
# Only move the contents and not the entire folder
# there could be other stuff in that folder
# (a careless user might have merged this with his other files)
# also this folder could be a dataset in which case a simple move will fail
# so lets just move the internal contents of this folder over
if old_path is not None and os.path.exists(old_path):
try:
for item in os.listdir(old_path):
shutil.move(old_path + '/' + item, ipfs['path'])
except shutil.Error as serr:
raise TaskException(
errno.EIO,
"Migrating ipfs path resulted in error: {0}".format(serr))
node.update(ipfs)
self.dispatcher.call_sync('etcd.generation.generate_group', 'services')
self.dispatcher.dispatch_event('service.ipfs.changed', {
'operation': 'updated',
'ids': None,
})
except RpcException as e:
raise TaskException(
errno.ENXIO, 'Cannot reconfigure IPFS: {0}'.format(str(e))
)
return 'RELOAD'
示例6: run
def run(self, afp):
paths = [PosixPath(afp.get(y)) if afp.get(y) else None for y in ('dbpath', 'homedir_path')]
for p in paths:
if p and not p.exists():
raise TaskException(errno.ENOENT, 'Path : {0} does not exist'.format(p.as_posix()))
if p and not p.is_dir():
raise TaskException(errno.ENOTDIR, 'Path : {0} is not a directory'.format(p.as_posix()))
if afp.get('guest_user'):
if not self.dispatcher.call_sync('user.query', [('username', '=', afp['guest_user'])], {'single': True}):
raise TaskException(errno.EINVAL, 'User: {0} does not exist'.format(afp['guest_user']))
try:
node = ConfigNode('service.afp', self.configstore)
node.update(afp)
self.dispatcher.call_sync('etcd.generation.generate_group', 'services')
self.dispatcher.call_sync('etcd.generation.generate_group', 'afp')
self.dispatcher.dispatch_event('service.afp.changed', {
'operation': 'updated',
'ids': None,
})
except RpcException as e:
raise TaskException(
errno.ENXIO, 'Cannot reconfigure AFP: {0}'.format(str(e))
)
return 'RELOAD'
示例7: run
def run(self, smb):
try:
action = 'NONE'
node = ConfigNode('service.smb', self.configstore)
if smb.get('filemask'):
smb['filemask'] = get_integer(smb['filemask'])
if smb.get('dirmask'):
smb['dirmask'] = get_integer(smb['dirmask'])
node.update(smb)
configure_params(node.__getstate__(), self.dispatcher.call_sync('service.smb.ad_enabled'))
try:
rpc = smbconf.SambaMessagingContext()
rpc.reload_config()
except OSError:
action = 'RESTART'
# XXX: Is restart to change netbios name/workgroup *really* needed?
if 'netbiosname' in smb or 'workgroup' in smb:
action = 'RESTART'
self.dispatcher.dispatch_event('service.smb.changed', {
'operation': 'updated',
'ids': None,
})
except RpcException as e:
raise TaskException(
errno.ENXIO, 'Cannot reconfigure SMB: {0}'.format(str(e))
)
return action
示例8: run
def run(self, id, updated_fields):
service_def = self.datastore.get_by_id('service_definitions', id)
node = ConfigNode('service.{0}'.format(service_def['name']), self.configstore)
restart = False
reload = False
updated_config = updated_fields.get('config')
if updated_config is None:
return
del updated_config['type']
if service_def.get('task'):
enable = updated_config.pop('enable', None)
try:
self.verify_subtask(service_def['task'], updated_config)
except RpcException as err:
new_err = ValidationException()
new_err.propagate(err, [0], [1, 'config'])
raise new_err
result = self.join_subtasks(self.run_subtask(service_def['task'], updated_config))
restart = result[0] == 'RESTART'
reload = result[0] == 'RELOAD'
if enable is not None:
node['enable'] = enable
else:
node.update(updated_config)
if service_def.get('etcd-group'):
self.dispatcher.call_sync('etcd.generation.generate_group', service_def.get('etcd-group'))
if 'enable' in updated_config:
# Propagate to dependent services
for i in service_def.get('dependencies', []):
svc_dep = self.datastore.get_by_id('service_definitions', i)
self.join_subtasks(self.run_subtask('service.update', i, {
'config': {
'type': 'service-{0}'.format(svc_dep['name']),
'enable': updated_config['enable']
}
}))
if service_def.get('auto_enable'):
# Consult state of services dependent on us
for i in self.datastore.query('service_definitions', ('dependencies', 'in', service_def['name'])):
enb = self.configstore.get('service.{0}.enable', i['name'])
if enb != updated_config['enable']:
del updated_config['enable']
break
self.dispatcher.call_sync('etcd.generation.generate_group', 'services')
self.dispatcher.call_sync('service.apply_state', service_def['name'], restart, reload, timeout=30)
self.dispatcher.dispatch_event('service.changed', {
'operation': 'update',
'ids': [service_def['id']]
})
示例9: get_config
def get_config(self):
node = ConfigNode('network', self.configstore).__getstate__()
node.update({
'gateway': self.dispatcher.call_sync('networkd.configuration.get_default_routes'),
'dns': self.dispatcher.call_sync('networkd.configuration.get_dns_config')
})
return node
示例10: run
def run(self, updated_params):
node = ConfigNode('directory', self.configstore)
node.update(updated_params)
try:
self.dispatcher.call_sync('dscached.management.reload_config')
except RpcException as e:
raise TaskException(errno.ENXIO, 'Cannot reconfigure directory services: {0}'.format(str(e)))
示例11: verify
def verify(self, openvpn_updated):
node = ConfigNode('service.openvpn', self.configstore).__getstate__()
node.update(openvpn_updated)
if node['dev'] not in ['tap', 'tun']:
raise VerifyException(errno.EINVAL,
'{0} Bad interface name. Allowed values tap/tun.'.format(node['dev']))
if ((node['mode'] == 'pki' and node['dev'].startswith('tun'))
or (node['mode'] == 'psk' and node['dev'].startswith('tap'))):
raise VerifyException(errno.EINVAL,
'tap interfaces can be used with pki scenario and tun with psk mode')
if node['mode'] == 'pki' and (not node['ca'] or not node['cert']):
raise VerifyException(errno.EINVAL,
'For pki VPN mode ca and certyficate values are required')
if node['mode'] == 'psk':
try:
ipaddress.ip_address(node['psk_server_ip'])
ipaddress.ip_address(node['psk_remote_ip'])
except ValueError as e:
raise VerifyException(errno.EINVAL, str(e))
if (node['server_bridge_extended']
and not (node['server_bridge_ip'] or node['server_bridge_netmask']
or node['server_bridge_range_begin'] or node['server_bridge_range_end'])):
raise VerifyException(errno.EINVAL,
'For pki server_bridge_extended mode all server_bridge values are required')
if node['mode'] == 'pki' and node['server_bridge_extended']:
try:
bridge_ip = ipaddress.ip_address(node['server_bridge_ip'])
netmask = node['server_bridge_netmask']
ip_range_begin = ipaddress.ip_address(node['server_bridge_range_begin'])
ip_range_end = ipaddress.ip_address(node['server_bridge_range_end'])
subnet = ipaddress.ip_network('{0}/{1}'.format(bridge_ip, netmask), strict=False)
except ValueError as e:
raise VerifyException(errno.EINVAL, str(e))
if (ip_range_begin not in subnet) or (ip_range_end not in subnet):
raise VerifyException(errno.EINVAL,
'Provided range of remote client IP adresses is invalid.')
if (bridge_ip >= ip_range_begin) and (bridge_ip <= ip_range_end):
raise VerifyException(errno.EINVAL,
'Provided bridge IP address is in the client ip range.')
if node['mode'] == 'pki':
if (node['keepalive_ping_interval'] * 2) >= node['keepalive_peer_down']:
raise VerifyException(errno.EINVAL, 'The second parameter to keepalive must be'
'at least twice the value of the first parameter.'
'Recommended setting is keepalive 10 60.')
return ['system']
示例12: run
def run(self, iscsi):
try:
node = ConfigNode('service.iscsi', self.configstore)
node.update(iscsi)
self.dispatcher.call_sync('etcd.generation.generate_group', 'ctl')
except RpcException as e:
raise TaskException(errno.ENXIO, 'Cannot reconfigure iSCSI: {0}'.format(str(e)))
return 'RELOAD'
示例13: run
def run(self, settings):
node = ConfigNode('network', self.configstore)
node.update(settings)
try:
self.dispatcher.call_sync('networkd.configuration.configure_network')
self.dispatcher.call_sync('etcd.generation.generate_group', 'network')
except RpcException as e:
raise TaskException(errno.ENXIO, 'Cannot reconfigure interface: {0}'.format(str(e)))
示例14: run
def run(self, service, updated_fields):
service_def = self.datastore.get_one('service_definitions', ('name', '=', service))
node = ConfigNode('service.{0}'.format(service), self.dispatcher.configstore)
node.update(updated_fields)
self.dispatcher.dispatch_event('service.changed', {
'operation': 'update',
'ids': [service_def['id']]
})
示例15: run
def run(self, smb):
node = ConfigNode('service.smb', self.configstore).__getstate__()
netbiosname = smb.get('netbiosname')
if netbiosname is not None:
for n in netbiosname:
if not validate_netbios_name(n):
raise TaskException(errno.EINVAL, 'Invalid name {0}'.format(n))
else:
netbiosname = node['netbiosname']
workgroup = smb.get('workgroup')
if workgroup is not None:
if not validate_netbios_name(workgroup):
raise TaskException(errno.EINVAL, 'Invalid name')
else:
workgroup = node['workgroup']
if workgroup.lower() in [i.lower() for i in netbiosname]:
raise TaskException(errno.EINVAL, 'NetBIOS and Workgroup must be unique')
if smb.get('guest_user'):
if not self.dispatcher.call_sync('user.query', [('username', '=', smb['guest_user'])], {'single': True}):
raise TaskException(errno.EINVAL, 'User: {0} does not exist'.format(smb['guest_user']))
try:
action = 'NONE'
node = ConfigNode('service.smb', self.configstore)
if smb.get('filemask'):
smb['filemask'] = get_integer(smb['filemask'])
if smb.get('dirmask'):
smb['dirmask'] = get_integer(smb['dirmask'])
node.update(smb)
configure_params(node.__getstate__(), self.dispatcher.call_sync('service.smb.ad_enabled'))
try:
rpc = smbconf.SambaMessagingContext()
rpc.reload_config()
except OSError:
action = 'RESTART'
# XXX: Is restart to change netbios name/workgroup *really* needed?
if 'netbiosname' in smb or 'workgroup' in smb:
action = 'RESTART'
self.dispatcher.dispatch_event('service.smb.changed', {
'operation': 'updated',
'ids': None,
})
except RpcException as e:
raise TaskException(
errno.ENXIO, 'Cannot reconfigure SMB: {0}'.format(str(e))
)
return action