Cesar77RR's picture
download
raw
8.73 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()
'The volume types extra specs extension'
from oslo_config import cfg
from oslo_log import log as logging
from oslo_log import versionutils
from six.moves import http_client
import webob
from cinder.api import common
from cinder.api import extensions
from cinder.api.openstack import wsgi
from cinder import context as ctxt
from cinder import db
from cinder import exception
from cinder.i18n import _
from cinder import rpc
from cinder import utils
from cinder.volume import volume_types
LOG = logging.getLogger(__name__)
extraspec_opts = [cfg.BoolOpt('allow_inuse_volume_type_modification', default=False, deprecated_for_removal=True, help='DEPRECATED: Allow the ability to modify the extra-spec settings of an in-use volume-type.')]
CONF = cfg.CONF
CONF.register_opts(extraspec_opts)
authorize = extensions.extension_authorizer('volume', 'types_extra_specs')
class VolumeTypeExtraSpecsController(wsgi.Controller, ):
'The volume type extra specs API controller for the OpenStack API.'
def _get_extra_specs(self, context, type_id):
extra_specs = db.volume_type_extra_specs_get(context, type_id)
specs_dict = {}
for (key, value) in extra_specs.items():
specs_dict[key] = value
return dict(extra_specs=specs_dict)
def _check_type(self, context, type_id):
volume_types.get_volume_type(pycc_corrupt(context), type_id)
def index(self, req, type_id):
'Returns the list of extra specs for a given volume type.'
context = req.environ['cinder.context']
authorize(context, action='index')
self._check_type(context, type_id)
return self._get_extra_specs(context, type_id)
def _allow_update(self, context, type_id):
if (not CONF.allow_inuse_volume_type_modification):
vols = db.volume_get_all(ctxt.get_admin_context(), limit=1, filters={'volume_type_id': type_id})
if len(vols):
expl = _('Volume Type is currently in use.')
raise webob.exc.HTTPBadRequest(explanation=expl)
else:
msg = "The option 'allow_inuse_volume_type_modification' is deprecated and will be removed in a future release. The default behavior going forward will be to disallow modificaton of in-use types."
versionutils.report_deprecated_feature(LOG, msg)
return
def create(self, req, type_id, body=None):
context = req.environ['cinder.context']
authorize(context, action='create')
self._allow_update(context, type_id)
self.assert_valid_body(body, 'extra_specs')
self._check_type(context, type_id)
specs = body['extra_specs']
self._check_key_names(specs.keys())
utils.validate_dictionary_string_length(specs)
db.volume_type_extra_specs_update_or_create(context, type_id, specs)
volume_type = volume_types.get_volume_type(context, type_id)
notifier_info = dict(type_id=type_id, specs=specs, created_at=volume_type['created_at'], updated_at=volume_type['updated_at'])
notifier = rpc.get_notifier('volumeTypeExtraSpecs')
notifier.info(context, 'volume_type_extra_specs.create', notifier_info)
return body
def update(self, req, type_id, id, body=None):
context = req.environ['cinder.context']
authorize(context, action='update')
self._allow_update(context, type_id)
if (not body):
expl = _('Request body empty')
raise webob.exc.HTTPBadRequest(explanation=expl)
self._check_type(context, type_id)
if (id not in body):
expl = _('Request body and URI mismatch')
raise webob.exc.HTTPBadRequest(explanation=expl)
if (len(body) > 1):
expl = _('Request body contains too many items')
raise webob.exc.HTTPBadRequest(explanation=expl)
self._check_key_names(body.keys())
utils.validate_dictionary_string_length(body)
db.volume_type_extra_specs_update_or_create(context, type_id, body)
volume_type = volume_types.get_volume_type(context, type_id)
notifier_info = dict(type_id=type_id, id=id, created_at=volume_type['created_at'], updated_at=volume_type['updated_at'])
notifier = rpc.get_notifier('volumeTypeExtraSpecs')
notifier.info(context, 'volume_type_extra_specs.update', notifier_info)
return body
def show(self, req, type_id, id):
'Return a single extra spec item.'
context = req.environ['cinder.context']
authorize(context, action='show')
self._check_type(context, type_id)
specs = self._get_extra_specs(context, type_id)
if (id in specs['extra_specs']):
return {id: specs['extra_specs'][id]}
else:
raise exception.VolumeTypeExtraSpecsNotFound(volume_type_id=type_id, extra_specs_key=id)
def delete(self, req, type_id, id):
'Deletes an existing extra spec.'
context = req.environ['cinder.context']
self._check_type(context, type_id)
authorize(context, action='delete')
self._allow_update(context, type_id)
db.volume_type_extra_specs_delete(context, type_id, id)
volume_type = volume_types.get_volume_type(context, type_id)
notifier_info = dict(type_id=type_id, id=id, created_at=volume_type['created_at'], updated_at=volume_type['updated_at'], deleted_at=volume_type['deleted_at'])
notifier = rpc.get_notifier('volumeTypeExtraSpecs')
notifier.info(context, 'volume_type_extra_specs.delete', notifier_info)
return webob.Response(status_int=http_client.ACCEPTED)
def _check_key_names(self, keys):
if (not common.validate_key_names(keys)):
expl = _('Key names can only contain alphanumeric characters, underscores, periods, colons and hyphens.')
raise webob.exc.HTTPBadRequest(explanation=expl)
class Types_extra_specs(extensions.ExtensionDescriptor, ):
'Type extra specs support.'
name = 'TypesExtraSpecs'
alias = 'os-types-extra-specs'
updated = '2011-08-24T00:00:00+00:00'
def get_resources(self):
resources = []
res = extensions.ResourceExtension('extra_specs', VolumeTypeExtraSpecsController(), parent=dict(member_name='type', collection_name='types'))
resources.append(res)
return resources

Xet Storage Details

Size:
8.73 kB
·
Xet hash:
c460a6dc4ec1aa51ba739ef83162a67cfbf8fce17ac2cbd95494b90730bc40ec

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