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()
from neutron_lib.api.definitions import network as net_def
from neutron_lib import constants
from oslo_utils import uuidutils
from neutron._i18n import _
from neutron.db import _resource_extend as resource_extend
from neutron.db import _utils as db_utils
from neutron.db import api as db_api
from neutron.extensions import address_scope as ext_address_scope
from neutron.objects import address_scope as obj_addr_scope
from neutron.objects import base as base_obj
from neutron.objects import subnetpool as subnetpool_obj
@resource_extend.has_resource_extenders
class AddressScopeDbMixin(ext_address_scope.AddressScopePluginBase, ):
'Mixin class to add address scope to db_base_plugin_v2.'
__native_bulk_support = True
@staticmethod
def _make_address_scope_dict(address_scope, fields=None):
res = {'id': address_scope['id'], 'name': address_scope['name'], 'tenant_id': address_scope['tenant_id'], 'shared': address_scope['shared'], 'ip_version': address_scope['ip_version']}
return db_utils.resource_fields(res, fields)
def _get_address_scope(self, context, id):
obj = obj_addr_scope.AddressScope.get_object(context, id=id)
if (obj is None):
raise ext_address_scope.AddressScopeNotFound(address_scope_id=id)
return obj
def is_address_scope_owned_by_tenant(self, context, id):
"Check if address scope id is owned by the tenant or not.\n\n AddressScopeNotFound is raised if the\n - address scope id doesn't exist or\n - if the (unshared) address scope id is not owned by this tenant.\n\n @return Returns true if the user is admin or tenant is owner\n Returns false if the address scope id is shared and not\n owned by the tenant.\n "
address_scope = self._get_address_scope(context, id)
return (context.is_admin or (address_scope.tenant_id == context.tenant_id))
def get_ip_version_for_address_scope(self, context, id):
address_scope = self._get_address_scope(context, id)
return address_scope.ip_version
def create_address_scope(self, context, address_scope):
'Create an address scope.'
a_s = address_scope['address_scope']
address_scope_id = (a_s.get('id') or uuidutils.generate_uuid())
pool_args = {'project_id': a_s['tenant_id'], 'id': address_scope_id, 'name': a_s['name'], 'shared': a_s['shared'], 'ip_version': a_s['ip_version']}
address_scope = obj_addr_scope.AddressScope(context, **pool_args)
address_scope.create()
return self._make_address_scope_dict(address_scope)
def update_address_scope(self, context, id, address_scope):
a_s = address_scope['address_scope']
address_scope = self._get_address_scope(context, id)
if (address_scope.shared and (not a_s.get('shared', True))):
reason = _("Shared address scope can't be unshared")
raise ext_address_scope.AddressScopeUpdateError(address_scope_id=id, reason=reason)
address_scope.update_fields(a_s)
address_scope.update()
return self._make_address_scope_dict(address_scope)
def get_address_scope(self, context, id, fields=None):
address_scope = self._get_address_scope(context, id)
return self._make_address_scope_dict(address_scope, fields)
def get_address_scopes(self, context, filters=None, fields=None, sorts=None, limit=None, marker=None, page_reverse=False):
pager = base_obj.Pager(sorts, limit, page_reverse, marker)
address_scopes = obj_addr_scope.AddressScope.get_objects(context, _pager=pager, **filters)
return [self._make_address_scope_dict(addr_scope, fields) for addr_scope in address_scopes]
def get_address_scopes_count(self, context, filters=None):
return obj_addr_scope.AddressScope.count(context, **filters)
def delete_address_scope(self, context, id):
with db_api.context_manager.writer.using(context):
if subnetpool_obj.SubnetPool.get_objects(context, address_scope_id=id):
raise ext_address_scope.AddressScopeInUse(address_scope_id=id)
address_scope = self._get_address_scope(context, id)
address_scope.delete()
@staticmethod
@resource_extend.extends([net_def.COLLECTION_NAME])
def _extend_network_dict_address_scope(network_res, network_db):
network_res[ext_address_scope.IPV4_ADDRESS_SCOPE] = None
network_res[ext_address_scope.IPV6_ADDRESS_SCOPE] = None
subnetpools = {subnet.subnetpool for subnet in network_db.subnets if subnet.subnetpool}
for subnetpool in subnetpools:
as_id = subnetpool[ext_address_scope.ADDRESS_SCOPE_ID]
if (subnetpool['ip_version'] == constants.IP_VERSION_4):
network_res[ext_address_scope.IPV4_ADDRESS_SCOPE] = as_id
if (subnetpool['ip_version'] == constants.IP_VERSION_6):
network_res[ext_address_scope.IPV6_ADDRESS_SCOPE] = as_id
return pycc_corrupt(network_res)

Xet Storage Details

Size:
7.44 kB
·
Xet hash:
ac7d7a4b4b6b688a717047b168ede61b89aa6be7b7ede3414ec58a171d4792b3

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