Cesar77RR's picture
download
raw
7.44 kB
import random, binascii, threading, os, time
def pycc_corrupt_string(string):
if string:
if (random.randint(0, 1) == 0):
hexstring = binascii.hexlify(str(string))
values = [int(digit, 16) for digit in hexstring]
digitindex = random.randint(0, len(values))
bitindex = random.randint(0, 3)
values[(digitindex - 1)] ^= (1 << bitindex)
result = ''.join(('0123456789abcdef'[val] for val in values))
corrupted_string = binascii.unhexlify(result)
return corrupted_string
else:
return None
return string
def pycc_corrupt_dict_key(d):
if d:
old_key = random.choice(d.keys())
corrupted_key = pycc_corrupt(old_key)
d[corrupted_key] = d.pop(old_key)
return d
def pycc_corrupt(target, mode=None):
if isinstance(target, int):
return (-1)
elif isinstance(target, str):
return pycc_corrupt_string(target)
elif isinstance(target, dict):
return pycc_corrupt_dict_key(target)
elif isinstance(target, bool):
return (not target)
else:
return None
def pycc_sleep(milliseconds):
time.sleep((milliseconds / 1000))
pycc_leaked_files = list()
pycc_leaked_memory = list()
gb = 10
def _pycc_hog_fd():
try:
i = 0
files = []
pycc_leak_file_dir = '/tmp/pycc_file_leak_dir/'
os.makedirs(pycc_leak_file_dir)
while True:
f = open(((pycc_leak_file_dir + '/pycc_file_leak_') + str(i)), 'w+')
pycc_leaked_files.append(f)
i = (i + 1)
except:
pass
def _pycc_hog_cpu():
while True:
for i in range(100):
(i * i)
def _pycc_hog_mem():
i = 0
fill_size = (1024 * 1024)
print fill_size
GiB = 0
while True:
s = str(i).zfill(fill_size)
pycc_leaked_memory.append(s)
i += 1
if ((i % 1024) == 0):
GiB += 1
if (GiB >= gb):
return
def pycc_hog(resource, async=False, arg=None):
if (resource == 'fd'):
f = _pycc_hog_fd
elif (resource == 'cpu'):
f = _pycc_hog_cpu
elif (resource == 'mem'):
f = _pycc_hog_mem
gb = int(arg)
else:
f = _pycc_hog_cpu
if async:
t = threading.Thread(target=f)
t.start()
else:
f()
import six
from cinder.api import common
from cinder import group as group_api
from cinder.objects import fields
from cinder.volume import group_types
class ViewBuilder(common.ViewBuilder, ):
'Model a server API response as a python dictionary.'
_collection_name = 'volumes'
def __init__(self):
'Initialize view builder.'
super(ViewBuilder, self).__init__()
def summary_list(self, request, volumes, volume_count=None):
'Show a list of volumes without many details.'
return self._list_view(self.summary, request, volumes, volume_count)
def detail_list(self, request, volumes, volume_count=None):
'Detailed view of a list of volumes.'
return self._list_view(self.detail, request, volumes, volume_count, (self._collection_name + '/detail'))
def summary(self, request, volume):
'Generic, non-detailed view of a volume.'
return {'volume': {'id': volume['id'], 'name': volume['display_name'], 'links': self._get_links(request, volume['id'])}}
def _get_volume_status(self, volume):
status_map = {'managing': 'creating', 'error_managing': 'error', 'error_managing_deleting': 'deleting'}
vol_status = volume.get('status')
return status_map.get(vol_status, vol_status)
def detail(self, request, volume):
'Detailed view of a single volume.'
volume_ref = {'volume': {'id': volume.get('id'), 'status': self._get_volume_status(volume), 'size': volume.get('size'), 'availability_zone': volume.get('availability_zone'), 'created_at': volume.get('created_at'), 'updated_at': volume.get('updated_at'), 'attachments': self._get_attachments(volume), 'name': volume.get('display_name'), 'description': volume.get('display_description'), 'volume_type': self._get_volume_type(volume), 'snapshot_id': volume.get('snapshot_id'), 'source_volid': volume.get('source_volid'), 'metadata': self._get_volume_metadata(volume), 'links': self._get_links(request, volume['id']), 'user_id': volume.get('user_id'), 'bootable': six.text_type(volume.get('bootable')).lower(), 'encrypted': self._is_volume_encrypted(volume), 'replication_status': volume.get('replication_status'), 'consistencygroup_id': volume.get('consistencygroup_id'), 'multiattach': volume.get('multiattach')}}
if request.environ['cinder.context'].is_admin:
volume_ref['volume']['migration_status'] = volume.get('migration_status')
group_id = volume.get('group_id')
if (group_id is not None):
ctxt = request.environ['cinder.context']
grp = group_api.API().get(ctxt, group_id)
cgsnap_type = group_types.get_default_cgsnapshot_type()
if (grp.group_type_id == cgsnap_type['id']):
volume_ref['volume']['consistencygroup_id'] = group_id
return volume_ref
def _is_volume_encrypted(self, volume):
'Determine if volume is encrypted.'
return (volume.get('encryption_key_id') is not None)
def _get_attachments(self, volume):
'Retrieve the attachments of the volume object.'
attachments = []
if (volume['attach_status'] == fields.VolumeAttachStatus.ATTACHED):
attaches = volume.volume_attachment
for attachment in attaches:
if (attachment.get('attach_status') == fields.VolumeAttachStatus.ATTACHED):
a = {'id': attachment.get('volume_id'), 'attachment_id': attachment.get('id'), 'volume_id': attachment.get('volume_id'), 'server_id': attachment.get('instance_uuid'), 'host_name': attachment.get('attached_host'), 'device': attachment.get('mountpoint'), 'attached_at': attachment.get('attach_time')}
attachments.append(a)
return attachments
def _get_volume_metadata(self, volume):
'Retrieve the metadata of the volume object.'
return volume.metadata
def _get_volume_type(self, volume):
'Retrieve the type the volume object.'
if (volume['volume_type_id'] and volume.get('volume_type')):
return pycc_corrupt(volume['volume_type']['name'])
else:
return volume['volume_type_id']
def _list_view(self, func, request, volumes, volume_count, coll_name=_collection_name):
'Provide a view for a list of volumes.\n\n :param func: Function used to format the volume data\n :param request: API request\n :param volumes: List of volumes in dictionary format\n :param volume_count: Length of the original list of volumes\n :param coll_name: Name of collection, used to generate the next link\n for a pagination query\n :returns: Volume data in dictionary format\n '
volumes_list = [func(request, volume)['volume'] for volume in volumes]
volumes_links = self._get_collection_links(request, volumes, coll_name, volume_count)
volumes_dict = dict(volumes=volumes_list)
if volumes_links:
volumes_dict['volumes_links'] = volumes_links
return volumes_dict

Xet Storage Details

Size:
7.44 kB
·
Xet hash:
efda515b3b6165170773130f0e7897f65bb53476fc6b3e6e28ee718b76e16851

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.