gid = None for i in range(start_gid, end_gid): if not self.datastore.exists('groups', ('id', '=', i)): gid = i break if not gid: raise RpcException(errno.ENOSPC, 'No free GIDs available') return gid @description("Create an user in the system") @accepts(h.all_of( h.ref('user'), h.required('username', 'group'), h.forbidden('builtin', 'logged-in', 'sessions'), h.object({'password': {'type': 'string'}}), h.any_of( h.required('password'), h.required('unixhash', 'smbhash'), h.required('password_disabled')), )) class UserCreateTask(Task): def describe(self, user): return "Adding user {0}".format(user['username']) def verify(self, user): errors = []
# sysctl module compatibility raise OSError(str(e.err)) @description("Provides access to OS tunables") class TunablesProvider(Provider): @query('tunable') def query(self, filter=None, params=None): return self.datastore.query('tunables', *(filter or []), **(params or {})) @description("Adds Tunable") @accepts(h.all_of( h.ref('tunable'), h.required('var', 'value', 'type'), )) class TunableCreateTask(Task): def describe(self, tunable): return "Creating Tunable {0}".format(tunable['var']) 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'))
from lib.system import system, SubprocessException logger = logging.getLogger('NTPPlugin') @description("Provides access to NTP Servers configuration") class NTPServersProvider(Provider): @query('ntp-server') def query(self, filter=None, params=None): return self.datastore.query('ntpservers', *(filter or []), **(params or {})) @description("Adds new NTP Server") @accepts(h.all_of( h.ref('ntp-server'), h.required('address'), ), bool) class NTPServerCreateTask(Task): def describe(self, ntp): return "Creating NTP Server {0}".format(ntp['address']) def verify(self, ntp, force=False): errors = [] try: system('ntpdate', '-q', ntp['address']) except SubprocessException: if not force: errors.append(( 'address',
fd.close() generate_disk_cache(self.dispatcher, disk) def get_status(self): if not self.started: return TaskStatus(0, 'Erasing disk...') return TaskStatus(self.remaining / self.mediasize, 'Erasing disk...') @description("Configures online disk parameters") @accepts(str, h.all_of( h.ref('disk'), h.no( h.required('name', 'serial', 'path', 'id', 'mediasize', 'status')))) class DiskConfigureTask(Task): def verify(self, id, updated_fields): disk = self.datastore.get_by_id('disks', id) if not disk: raise VerifyException(errno.ENOENT, 'Disk {0} not found'.format(id)) if not self.dispatcher.call_sync('disks.is_online', disk['path']): raise VerifyException(errno.EINVAL, 'Cannot configure offline disk') return ['disk:{0}'.format(disk['path'])] def run(self, id, updated_fields):
return result @description("Returns list of clients connected to particular share") def get_connected_clients(self, share_name): share = self.datastore.get_by_id('shares', share_name) if not share: raise RpcException(errno.ENOENT, 'Share not found') return self.dispatcher.call_sync('shares.{0}.get_connected_clients'.format(share['type']), share_name) @description("Creates new share") @accepts(h.all_of( h.ref('share'), h.required('id', 'type', 'target') )) class CreateShareTask(Task): def verify(self, share): return ['system'] def run(self, share): self.join_subtasks(self.run_subtask('share.{0}.create'.format(share['type']), share)) @description("Updates existing share") @accepts(str, h.ref('share')) class UpdateShareTask(Task): def verify(self, name, updated_fields): share = self.datastore.get_by_id('shares', name) if not share:
if certificate.get('csr'): certificate['csr_path'] = os.path.join( cert_path, '{0}.csr'.format(certificate['name'])) return certificate return self.datastore.query('crypto.certificates', *(filter or []), callback=extend, **(params or {})) @accepts( h.all_of( h.ref('crypto-certificate'), h.required('signedby', 'name', 'country', 'state', 'city', 'organization', 'email', 'common'), )) class CertificateInternalCreateTask(Task): def verify(self, certificate): errors = [] if self.datastore.exists('crypto.certificates', ('name', '=', certificate['name'])): errors.append(('name', errno.EEXIST, 'Certificate with given name already exists')) if not self.datastore.exists('crypto.certificates', ('id', '=', certificate['signedby'])): errors.append(('signedby', errno.EEXIST, 'Signing certificate does not exists'))
for i in range(start_gid, end_gid): if not self.datastore.exists('groups', ('id', '=', i)): gid = i break if not gid: raise RpcException(errno.ENOSPC, 'No free GIDs available') return gid @description("Create an user in the system") @accepts( h.all_of( h.ref('user'), h.required('username', 'group'), h.forbidden('builtin', 'logged-in', 'sessions'), h.object({'password': { 'type': 'string' }}), h.any_of(h.required('password'), h.required('unixhash', 'smbhash'), h.required('password_disabled')), )) class UserCreateTask(Task): def describe(self, user): return "Adding user {0}".format(user['username']) def verify(self, user): errors = []
fd.close() generate_disk_cache(self.dispatcher, disk) def get_status(self): if not self.started: return TaskStatus(0, 'Erasing disk...') return TaskStatus(self.remaining / self.mediasize, 'Erasing disk...') @description("Configures online disk parameters") @accepts( str, h.all_of( h.ref('disk'), h.no(h.required('name', 'serial', 'path', 'id', 'mediasize', 'status')) ) ) class DiskConfigureTask(Task): def verify(self, id, updated_fields): disk = self.datastore.get_by_id('disks', id) if not disk: raise VerifyException(errno.ENOENT, 'Disk {0} not found'.format(id)) if not self.dispatcher.call_sync('disks.is_online', disk['path']): raise VerifyException(errno.EINVAL, 'Cannot configure offline disk') return ['disk:{0}'.format(disk['path'])] def run(self, id, updated_fields):
# Load and dump private key to make sure its in desired format # This is code ported from 9.3 and must be reviewed as it may very well be useless certificate['privatekey'] = export_privatekey(certificate['privatekey']) if certificate.get('csr'): certificate['csr_path'] = os.path.join( cert_path, '{0}.csr'.format(certificate['name'])) return certificate return self.datastore.query('crypto.certificates', *(filter or []), callback=extend, **(params or {})) @accepts(h.all_of( h.ref('crypto-certificate'), h.required('signedby', 'name', 'country', 'state', 'city', 'organization', 'email', 'common'), )) class CertificateInternalCreateTask(Task): def verify(self, certificate): errors = [] if self.datastore.exists('crypto.certificates', ('name', '=', certificate['name'])): errors.append(('name', errno.EEXIST, 'Certificate with given name already exists')) if not self.datastore.exists('crypto.certificates', ('id', '=', certificate['signedby'])): errors.append(('signedby', errno.EEXIST, 'Signing certificate does not exists')) if '"' in certificate['name']: errors.append( ('name', errno.EINVAL, 'You cannot issue a certificate with a `"` in its name'))
except SubprocessException as e: # sysctl module compatibility raise OSError(str(e.err)) @description("Provides access to OS tunables") class TunablesProvider(Provider): @query('tunable') def query(self, filter=None, params=None): return self.datastore.query('tunables', *(filter or []), **(params or {})) @description("Adds Tunable") @accepts(h.all_of( h.ref('tunable'), h.required('var', 'value', 'type'), )) class TunableCreateTask(Task): def describe(self, tunable): return "Creating Tunable {0}".format(tunable['var']) 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']):