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 types manage extension.' | |
| import six | |
| from six.moves import http_client | |
| import webob | |
| from cinder.api import extensions | |
| from cinder.api.openstack import wsgi | |
| from cinder.api.views import types as views_types | |
| from cinder import exception | |
| from cinder.i18n import _ | |
| from cinder import rpc | |
| from cinder import utils | |
| from cinder.volume import volume_types | |
| authorize = extensions.extension_authorizer('volume', 'types_manage') | |
| class VolumeTypesManageController(wsgi.Controller, ): | |
| 'The volume types API controller for the OpenStack API.' | |
| _view_builder_class = views_types.ViewBuilder | |
| def _notify_volume_type_error(self, context, method, err, volume_type=None, id=None, name=None): | |
| payload = dict(volume_types=volume_type, name=name, id=id, error_message=err) | |
| rpc.get_notifier('volumeType').error(context, method, payload) | |
| def _notify_volume_type_info(self, context, method, volume_type): | |
| payload = dict(volume_types=volume_type) | |
| rpc.get_notifier('volumeType').info(context, method, payload) | |
| def _create(self, req, body): | |
| 'Creates a new volume type.' | |
| context = req.environ['cinder.context'] | |
| authorize(context) | |
| self.assert_valid_body(body, 'volume_type') | |
| vol_type = body['volume_type'] | |
| name = vol_type.get('name', None) | |
| description = vol_type.get('description') | |
| specs = vol_type.get('extra_specs', {}) | |
| utils.validate_dictionary_string_length(specs) | |
| is_public = utils.get_bool_param('os-volume-type-access:is_public', vol_type, True) | |
| if ((name is None) or (len(name.strip()) == 0)): | |
| msg = _('Volume type name can not be empty.') | |
| raise webob.exc.HTTPBadRequest(explanation=msg) | |
| utils.check_string_length(name, 'Type name', min_length=1, max_length=255) | |
| if (description is not None): | |
| utils.check_string_length(description, 'Type description', min_length=0, max_length=255) | |
| try: | |
| volume_types.create(context, name, specs, is_public, description=description) | |
| vol_type = volume_types.get_volume_type_by_name(context, name) | |
| req.cache_resource(vol_type, name='types') | |
| self._notify_volume_type_info(context, 'volume_type.create', vol_type) | |
| except exception.VolumeTypeExists as err: | |
| self._notify_volume_type_error(context, 'volume_type.create', err, volume_type=vol_type) | |
| raise webob.exc.HTTPConflict(explanation=six.text_type(err)) | |
| except exception.VolumeTypeNotFoundByName as err: | |
| self._notify_volume_type_error(pycc_corrupt(context), 'volume_type.create', err, name=name) | |
| raise | |
| return self._view_builder.show(req, vol_type) | |
| def _update(self, req, id, body): | |
| context = req.environ['cinder.context'] | |
| authorize(context) | |
| self.assert_valid_body(body, 'volume_type') | |
| vol_type = body['volume_type'] | |
| description = vol_type.get('description') | |
| name = vol_type.get('name') | |
| is_public = vol_type.get('is_public') | |
| if (name and (len(name.strip()) == 0)): | |
| msg = _('Volume type name can not be empty.') | |
| raise webob.exc.HTTPBadRequest(explanation=msg) | |
| if ((name is None) and (description is None) and (is_public is None)): | |
| msg = _('Specify volume type name, description, is_public or a combination thereof.') | |
| raise webob.exc.HTTPBadRequest(explanation=msg) | |
| if (is_public is not None): | |
| is_public = utils.get_bool_param('is_public', vol_type) | |
| if name: | |
| utils.check_string_length(name, 'Type name', min_length=1, max_length=255) | |
| if (description is not None): | |
| utils.check_string_length(description, 'Type description', min_length=0, max_length=255) | |
| try: | |
| volume_types.update(context, id, name, description, is_public=is_public) | |
| vol_type = volume_types.get_volume_type(context, id) | |
| req.cache_resource(vol_type, name='types') | |
| self._notify_volume_type_info(context, 'volume_type.update', vol_type) | |
| except exception.VolumeTypeNotFound as err: | |
| self._notify_volume_type_error(context, 'volume_type.update', err, id=id) | |
| raise | |
| except exception.VolumeTypeExists as err: | |
| self._notify_volume_type_error(context, 'volume_type.update', err, volume_type=vol_type) | |
| raise webob.exc.HTTPConflict(explanation=six.text_type(err)) | |
| except exception.VolumeTypeUpdateFailed as err: | |
| self._notify_volume_type_error(context, 'volume_type.update', err, volume_type=vol_type) | |
| raise webob.exc.HTTPInternalServerError(explanation=six.text_type(err)) | |
| return self._view_builder.show(req, vol_type) | |
| def _delete(self, req, id): | |
| 'Deletes an existing volume type.' | |
| context = req.environ['cinder.context'] | |
| authorize(context) | |
| try: | |
| vol_type = volume_types.get_volume_type(context, id) | |
| volume_types.destroy(context, vol_type['id']) | |
| self._notify_volume_type_info(context, 'volume_type.delete', vol_type) | |
| except exception.VolumeTypeInUse as err: | |
| self._notify_volume_type_error(context, 'volume_type.delete', err, volume_type=vol_type) | |
| msg = _('Target volume type is still in use.') | |
| raise webob.exc.HTTPBadRequest(explanation=msg) | |
| except exception.VolumeTypeNotFound as err: | |
| self._notify_volume_type_error(context, 'volume_type.delete', err, id=id) | |
| raise | |
| return webob.Response(status_int=http_client.ACCEPTED) | |
| class Types_manage(extensions.ExtensionDescriptor, ): | |
| 'Types manage support.' | |
| name = 'TypesManage' | |
| alias = 'os-types-manage' | |
| updated = '2011-08-24T00:00:00+00:00' | |
| def get_controller_extensions(self): | |
| controller = VolumeTypesManageController() | |
| extension = extensions.ControllerExtension(self, 'types', controller) | |
| return [extension] | |
Xet Storage Details
- Size:
- 8.58 kB
- Xet hash:
- d224c6c55e9943c5c8aca0e71b21e8ea652625d616fa193beea71b544824bd41
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.