def report_local_storage(): # TODO # if customers folder placed outside of BaseDir() # need to add: total = total + customers r = {} r['backups'] = bpio.getDirectorySize(settings.getLocalBackupsDir()) # r['backups_str'] = diskspace.MakeStringFromBytes(r['backups']) r['temp'] = bpio.getDirectorySize(settings.getTempDir()) # r['temp_str'] = diskspace.MakeStringFromBytes(r['temp']) r['customers'] = bpio.getDirectorySize(settings.getCustomersFilesDir()) # r['customers_str'] = diskspace.MakeStringFromBytes(r['customers']) r['total'] = bpio.getDirectorySize(settings.BaseDir()) # r['total_str'] = diskspace.MakeStringFromBytes(r['total']) dataDriveFreeSpace, dataDriveTotalSpace = diskusage.GetDriveSpace( settings.getCustomersFilesDir()) if dataDriveFreeSpace is None: dataDriveFreeSpace = 0 r['disktotal'] = int(dataDriveTotalSpace) # r['disktotal_str'] = diskspace.MakeStringFromBytes(r['disktotal']) r['diskfree'] = int(dataDriveFreeSpace) # r['diskfree_str'] = diskspace.MakeStringFromBytes(r['diskfree']) try: r['total_percent'] = misc.value2percent(float(r['total']), float(r['disktotal']), 5) except: r['total_percent'] = '' try: r['diskfree_percent'] = misc.value2percent(float(r['diskfree']), float(r['disktotal']), 5) except: r['diskfree_percent'] = '' return r
def _list_active_streams(params): result = [] if not driver.is_started('service_gateway'): return {'result': result, } from transport import gateway result = [] wanted_protos = params.get('protos', []) if not wanted_protos: wanted_protos = gateway.list_active_transports() for proto in wanted_protos: for stream in gateway.list_active_streams(proto): item = { 'proto': proto, 'id': '', 'type': '', 'bytes_current': -1, 'bytes_total': -1, 'progress': '0%', } if proto == 'tcp': if hasattr(stream, 'bytes_received'): item.update({ 'id': stream.file_id, 'type': 'in', 'bytes_current': stream.bytes_received, 'bytes_total': stream.size, 'progress': misc.value2percent(stream.bytes_received, stream.size, 0) }) elif hasattr(stream, 'bytes_sent'): item.update({ 'id': stream.file_id, 'type': 'out', 'bytes_current': stream.bytes_sent, 'bytes_total': stream.size, 'progress': misc.value2percent(stream.bytes_sent, stream.size, 0) }) elif proto == 'udp': if hasattr(stream.consumer, 'bytes_received'): item.update({ 'id': stream.stream_id, 'type': 'in', 'bytes_current': stream.consumer.bytes_received, 'bytes_total': stream.consumer.size, 'progress': misc.value2percent(stream.consumer.bytes_received, stream.consumer.size, 0) }) elif hasattr(stream.consumer, 'bytes_sent'): item.update({ 'id': stream.stream_id, 'type': 'out', 'bytes_current': stream.consumer.bytes_sent, 'bytes_total': stream.consumer.size, 'progress': misc.value2percent(stream.consumer.bytes_sent, stream.consumer.size, 0) }) result.append(item) return {'result': result, }
def _list_active_streams(params): result = [] if not driver.is_on('service_gateway'): return {'result': result, } from transport import gateway result = [] wanted_protos = params.get('protos', []) if not wanted_protos: wanted_protos = gateway.list_active_transports() for proto in wanted_protos: for stream in gateway.list_active_streams(proto): item = { 'proto': proto, 'id': '', 'type': '', 'bytes_current': -1, 'bytes_total': -1, 'progress': '0%', } if proto == 'tcp': if hasattr(stream, 'bytes_received'): item.update({ 'id': stream.file_id, 'type': 'in', 'bytes_current': stream.bytes_received, 'bytes_total': stream.size, 'progress': misc.value2percent(stream.bytes_received, stream.size, 0) }) elif hasattr(stream, 'bytes_sent'): item.update({ 'id': stream.file_id, 'type': 'out', 'bytes_current': stream.bytes_sent, 'bytes_total': stream.size, 'progress': misc.value2percent(stream.bytes_sent, stream.size, 0) }) elif proto == 'udp': if hasattr(stream.consumer, 'bytes_received'): item.update({ 'id': stream.stream_id, 'type': 'in', 'bytes_current': stream.consumer.bytes_received, 'bytes_total': stream.consumer.size, 'progress': misc.value2percent(stream.consumer.bytes_received, stream.consumer.size, 0) }) elif hasattr(stream.consumer, 'bytes_sent'): item.update({ 'id': stream.stream_id, 'type': 'out', 'bytes_current': stream.consumer.bytes_sent, 'bytes_total': stream.consumer.size, 'progress': misc.value2percent(stream.consumer.bytes_sent, stream.consumer.size, 0) }) result.append(item) return {'result': result, }
def report_consumed_storage(): result = {} result['suppliers_num'] = contactsdb.num_suppliers() result['needed'] = settings.getNeededBytes() # result['needed_str'] = diskspace.MakeStringFromBytes(result['needed']) result['used'] = int(backup_fs.sizebackups() / 2) # result['used_str'] = diskspace.MakeStringFromBytes(result['used']) result['available'] = result['needed'] - result['used'] # result['available_str'] = diskspace.MakeStringFromBytes(result['available']) result['needed_per_supplier'] = 0 result['used_per_supplier'] = 0 result['available_per_supplier'] = 0 if result['suppliers_num'] > 0: result['needed_per_supplier'] = int( math.ceil(2.0 * result['needed'] / result['suppliers_num'])) result['used_per_supplier'] = int( math.ceil(2.0 * result['used'] / result['suppliers_num'])) result['available_per_supplier'] = result[ 'needed_per_supplier'] - result['used_per_supplier'] # result['needed_per_supplier_str'] = diskspace.MakeStringFromBytes(result['needed_per_supplier']) # result['used_per_supplier_str'] = diskspace.MakeStringFromBytes(result['used_per_supplier']) # result['available_per_supplier_str'] = diskspace.MakeStringFromBytes(result['available_per_supplier']) try: result['used_percent'] = misc.value2percent(float(result['used']), float(result['needed'])) except: result['used_percent'] = '0%' return result
def report_donated_storage(): space_dict, free_space = read_customers_quotas() used_space_dict = read_customers_usage() r = {} r['customers_num'] = contactsdb.num_customers() r['customers'] = [] r['old_customers'] = [] r['errors'] = [] r['consumed'] = 0 r['donated'] = settings.getDonatedBytes() # r['donated_str'] = diskspace.MakeStringFromBytes(r['donated']) r['real'] = bpio.getDirectorySize(settings.getCustomersFilesDir()) try: r['free'] = int(free_space) except: r['free'] = 0 used = 0 for idurl in id_url.to_bin_list(contactsdb.customers()): consumed_by_customer = 0 used_by_customer = 0 if idurl not in list(space_dict.keys()): r['errors'].append('space consumed by customer %r is unknown' % idurl) else: try: consumed_by_customer = int(space_dict.pop(idurl)) r['consumed'] += consumed_by_customer except: r['errors'].append( 'incorrect value of consumed space for customer %r' % idurl) continue if idurl in list(used_space_dict.keys()): try: used_by_customer = int(used_space_dict.pop(idurl)) used += used_by_customer except: r['errors'].append( 'incorrect value of used space for customer %r' % idurl) continue if consumed_by_customer < used_by_customer: r['errors'].append( 'customer %r currently using more space than requested' % idurl) c = {} c['idurl'] = strng.to_text(idurl) c['used'] = used_by_customer # c['used_str'] = diskspace.MakeStringFromBytes(c['used']) c['consumed'] = consumed_by_customer # c['consumed_str'] = diskspace.MakeStringFromBytes(c['consumed']) c['real'] = bpio.getDirectorySize(settings.getCustomerFilesDir(idurl)) # c['real_str'] = diskspace.MakeStringFromBytes(c['real']) r['customers'].append(c) r['used'] = used # r['used_str'] = diskspace.MakeStringFromBytes(r['used']) # r['consumed_str'] = diskspace.MakeStringFromBytes(r['consumed']) if r['donated'] != r['free'] + r['consumed']: r['errors'].append( 'total consumed %d and known free %d (%d total) bytes not match with donated %d bytes' % (r['consumed'], r['free'], r['consumed'] + r['free'], r['donated'])) if r['used'] > r['donated']: r['errors'].append( 'total space used by customers exceed the donated limit') if len(space_dict) > 0: r['errors'].append('found %d incorrect records of consumed space' % len(space_dict)) if r['real'] != r['used']: r['errors'].append( 'current info needs update, known size is %d bytes but real is %d bytes' % (r['used'], r['real'])) old_customers_used = 0 old_customers_real = 0 for idurl in used_space_dict.keys(): real = bpio.getDirectorySize(settings.getCustomerFilesDir(idurl)) try: used = int(used_space_dict[idurl]) except: r['errors'].append( 'incorrect value of used space for customer %r' % idurl) continue r['old_customers'].append({ 'idurl': strng.to_text(idurl), 'used': used, # 'used_str': diskspace.MakeStringFromBytes(used_space_dict[idurl]), 'real': real, # 'real_str': diskspace.MakeStringFromBytes(real), }) old_customers_used += used old_customers_real += real r['old_customers_used'] = old_customers_used r['old_customers_real'] = old_customers_real try: r['used_percent'] = misc.value2percent(float(r['used']), float(r['donated']), 5) except: r['used_percent'] = '' try: r['consumed_percent'] = misc.value2percent(float(r['consumed']), float(r['donated']), 5) except: r['consumed_percent'] = '' return r