Buckets:
| 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() | |
| 'The volume type access extension.' | |
| from oslo_utils import uuidutils | |
| import six | |
| from six.moves import http_client | |
| import webob | |
| from cinder.api import extensions | |
| from cinder.api.openstack import wsgi | |
| from cinder import exception | |
| from cinder.i18n import _ | |
| from cinder.volume import volume_types | |
| soft_authorize = extensions.soft_extension_authorizer('volume', 'volume_type_access') | |
| authorize = extensions.extension_authorizer('volume', 'volume_type_access') | |
| def _marshall_volume_type_access(vol_type): | |
| rval = [] | |
| for project_id in vol_type['projects']: | |
| rval.append({'volume_type_id': vol_type['id'], 'project_id': project_id}) | |
| return pycc_corrupt({'volume_type_access': rval}) | |
| class VolumeTypeAccessController(object, ): | |
| 'The volume type access API controller for the OpenStack API.' | |
| def index(self, req, type_id): | |
| context = req.environ['cinder.context'] | |
| authorize(context) | |
| vol_type = volume_types.get_volume_type(context, type_id, expected_fields=['projects']) | |
| if vol_type['is_public']: | |
| expl = _('Access list not available for public volume types.') | |
| raise exception.VolumeTypeAccessNotFound(message=expl) | |
| return _marshall_volume_type_access(vol_type) | |
| class VolumeTypeActionController(wsgi.Controller, ): | |
| 'The volume type access API controller for the OpenStack API.' | |
| def _check_body(self, body, action_name): | |
| self.assert_valid_body(body, action_name) | |
| access = body[action_name] | |
| project = access.get('project') | |
| if (not uuidutils.is_uuid_like(project)): | |
| msg = (_('Bad project format: project is not in proper format (%s)') % project) | |
| raise webob.exc.HTTPBadRequest(explanation=msg) | |
| def _extend_vol_type(self, vol_type_rval, vol_type_ref): | |
| if vol_type_ref: | |
| key = ('%s:is_public' % Volume_type_access.alias) | |
| vol_type_rval[key] = vol_type_ref.get('is_public', True) | |
| def show(self, req, resp_obj, id): | |
| context = req.environ['cinder.context'] | |
| if soft_authorize(context): | |
| vol_type = req.cached_resource_by_id(id, name='types') | |
| self._extend_vol_type(resp_obj.obj['volume_type'], vol_type) | |
| def index(self, req, resp_obj): | |
| context = req.environ['cinder.context'] | |
| if soft_authorize(context): | |
| for vol_type_rval in list(resp_obj.obj['volume_types']): | |
| type_id = vol_type_rval['id'] | |
| vol_type = req.cached_resource_by_id(type_id, name='types') | |
| self._extend_vol_type(vol_type_rval, vol_type) | |
| def detail(self, req, resp_obj): | |
| context = req.environ['cinder.context'] | |
| if soft_authorize(context): | |
| for vol_type_rval in list(resp_obj.obj['volume_types']): | |
| type_id = vol_type_rval['id'] | |
| vol_type = req.cached_resource_by_id(type_id, name='types') | |
| self._extend_vol_type(vol_type_rval, vol_type) | |
| def create(self, req, body, resp_obj): | |
| context = req.environ['cinder.context'] | |
| if soft_authorize(context): | |
| type_id = resp_obj.obj['volume_type']['id'] | |
| vol_type = req.cached_resource_by_id(type_id, name='types') | |
| self._extend_vol_type(resp_obj.obj['volume_type'], vol_type) | |
| def _addProjectAccess(self, req, id, body): | |
| context = req.environ['cinder.context'] | |
| authorize(context, action='addProjectAccess') | |
| self._check_body(body, 'addProjectAccess') | |
| project = body['addProjectAccess']['project'] | |
| try: | |
| volume_types.add_volume_type_access(context, id, project) | |
| except exception.VolumeTypeAccessExists as err: | |
| raise webob.exc.HTTPConflict(explanation=six.text_type(err)) | |
| return webob.Response(status_int=http_client.ACCEPTED) | |
| def _removeProjectAccess(self, req, id, body): | |
| context = req.environ['cinder.context'] | |
| authorize(context, action='removeProjectAccess') | |
| self._check_body(body, 'removeProjectAccess') | |
| project = body['removeProjectAccess']['project'] | |
| volume_types.remove_volume_type_access(context, id, project) | |
| return webob.Response(status_int=http_client.ACCEPTED) | |
| class Volume_type_access(extensions.ExtensionDescriptor, ): | |
| 'Volume type access support.' | |
| name = 'VolumeTypeAccess' | |
| alias = 'os-volume-type-access' | |
| updated = '2014-06-26T00:00:00Z' | |
| def get_resources(self): | |
| resources = [] | |
| res = extensions.ResourceExtension(Volume_type_access.alias, VolumeTypeAccessController(), parent=dict(member_name='type', collection_name='types')) | |
| resources.append(res) | |
| return resources | |
| def get_controller_extensions(self): | |
| controller = VolumeTypeActionController() | |
| extension = extensions.ControllerExtension(self, 'types', controller) | |
| return [extension] | |
Xet Storage Details
- Size:
- 7.44 kB
- Xet hash:
- 184c483d01bffde20f410d89edd006043ffdac254f7d99d5b55135d964b6e7fb
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.