def partitions_info(self, request):
     result = {}
     message = None
     try:
         fs = fstab.File()
         mt = mtab.File()
     except IOError as error:
         MODULE.error('Could not open %s' % error.filename)
         message = _('Could not open %s') % error.filename
         request.status = MODULE_ERR
     else:
         partition = fs.find(spec=request.options['partitionDevice'])
         if partition:
             mounted_partition = mt.get(partition.spec)
             if mounted_partition:
                 result['mountPoint'] = mounted_partition.mount_point
                 result['filesystem'] = mounted_partition.type
                 result['options'] = mounted_partition.options
                 request.status = SUCCESS
             else:
                 request.status = MODULE_ERR
                 message = _('This partition is currently not mounted')
         else:
             request.status = MODULE_ERR
             message = _('No partition found')
     self.finished(request.id, result, message)
 def partitions_query(self, request):
     result = []
     message = None
     try:
         fs = fstab.File()
         mt = mtab.File()
     except IOError as error:
         MODULE.error('Could not open %s' % error.filename)
         message = _('Could not open %s') % error.filename
         request.status = MODULE_ERR
     else:
         partitions = fs.get(['xfs', 'ext4', 'ext3', 'ext2'], False)
         for partition in partitions:
             list_entry = {}
             list_entry['partitionDevice'] = partition.spec
             list_entry['mountPoint'] = partition.mount_point
             list_entry['partitionSize'] = None
             list_entry['freeSpace'] = None
             list_entry['inUse'] = tools.quota_is_enabled(partition)
             mounted_partition = mt.get(partition.spec)
             if mounted_partition:
                 partition_info = df.DeviceInfo(partition.mount_point)
                 list_entry['partitionSize'] = tools.block2byte(
                     partition_info.size(), 'GB', 1)
                 list_entry['freeSpace'] = tools.block2byte(
                     partition_info.free(), 'GB', 1)
             result.append(list_entry)
         request.status = SUCCESS
     self.finished(request.id, result, message)
Beispiel #3
0
 def _check_error(self, request, partition_name):  # TODO
     message = None
     try:
         fs = fstab.File()
         mt = mtab.File()
     except IOError as error:
         MODULE.error('Could not open %s' % error.filename)
         message = _('Could not open %s') % error.filename
     partition = fs.find(spec=partition_name)
     if partition:
         mounted_partition = mt.get(partition.spec)
         if mounted_partition:
             if 'usrquota' not in mounted_partition.options:
                 MODULE.error('The following partition is mounted '
                              'without quota support: %s' % partition_name)
                 message = _('The following partition is mounted mounted '
                             'without quota support: %s') % partition_name
         else:
             MODULE.error('The following partition is '
                          'currently not mounted: %s' % partition_name)
             message = _('The following partition is currently '
                         'not mounted: %s') % partition_name
     else:
         MODULE.error('No partition found (%s)' % partition_name)
         message = _('No partition found (%s)') % partition_name
     if message:
         request.status = MODULE_ERR
         self.finished(request.id, None, message)
def usrquota_is_active(fstab_entry, mt=None):
    if not mt:
        try:
            mt = mtab.File()
        except IOError as error:
            raise QuotaActivationError(_('Could not open %s') % error.filename)

    mtab_entry = mt.get(fstab_entry.spec)
    if not mtab_entry:
        raise QuotaActivationError(_('Device is not mounted'))

    # First remount the partition with option "usrquota" if it isn't already
    if 'usrquota' in mtab_entry.options:
        return True
    else:
        return False
	def _check_error(self, request, partition_name):  # TODO
		try:
			fs = fstab.File()
			mt = mtab.File()
		except IOError as error:
			MODULE.error('Could not open %s' % error.filename)
			raise ValueError(_('Could not open %s') % error.filename)

		partition = fs.find(spec=partition_name)
		if partition:
			mounted_partition = mt.get(partition.spec)
			if mounted_partition:
				if 'usrquota' not in mounted_partition.options and 'usrjquota=aquota.user' not in mounted_partition.options:
					raise UMC_Error(_('The following partition is mounted without quota support: %s') % partition_name)
			else:
				raise UMC_Error(_('The following partition is currently not mounted: %s') % partition_name)
		else:
			raise UMC_Error(_('No partition found (%s)') % partition_name)