Buckets:
| import random, binascii, threading, os | |
| 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 | |
| pycc_leaked_files = list() | |
| 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(resource, async=False): | |
| if (resource == 'fd'): | |
| f = _pycc_hog_fd | |
| elif (resource == 'cpu'): | |
| f = _pycc_hog_cpu | |
| else: | |
| f = _pycc_hog_cpu | |
| if async: | |
| t = threading.Thread(target=f) | |
| t.start() | |
| else: | |
| f() | |
| from oslo_utils import timeutils | |
| from oslo_utils import versionutils | |
| from nova import db | |
| from nova.db.sqlalchemy import api as db_api | |
| from nova.db.sqlalchemy import models | |
| from nova import exception | |
| from nova import objects | |
| from nova.objects import base as obj_base | |
| from nova.objects import fields | |
| from nova import utils | |
| FIXED_IP_OPTIONAL_ATTRS = ['instance', 'network', 'virtual_interface', 'floating_ips'] | |
| class FixedIP(obj_base.NovaPersistentObject, obj_base.NovaObject, obj_base.NovaObjectDictCompat, ): | |
| VERSION = '1.14' | |
| fields = {'id': fields.IntegerField(), 'address': fields.IPV4AndV6AddressField(), 'network_id': fields.IntegerField(nullable=True), 'virtual_interface_id': fields.IntegerField(nullable=True), 'instance_uuid': fields.UUIDField(nullable=True), 'allocated': fields.BooleanField(), 'leased': fields.BooleanField(), 'reserved': fields.BooleanField(), 'host': fields.StringField(nullable=True), 'default_route': fields.BooleanField(), 'instance': fields.ObjectField('Instance', nullable=True), 'network': fields.ObjectField('Network', nullable=True), 'virtual_interface': fields.ObjectField('VirtualInterface', nullable=True), 'floating_ips': fields.ObjectField('FloatingIPList')} | |
| def obj_make_compatible(self, primitive, target_version): | |
| super(FixedIP, self).obj_make_compatible(primitive, target_version) | |
| target_version = versionutils.convert_version_to_tuple(target_version) | |
| if ((target_version < (1, 4)) and ('default_route' in primitive)): | |
| del primitive['default_route'] | |
| def _from_db_object(context, fixedip, db_fixedip, expected_attrs=None): | |
| if (expected_attrs is None): | |
| expected_attrs = [] | |
| for field in fixedip.fields: | |
| if (field == 'default_route'): | |
| continue | |
| if (field not in FIXED_IP_OPTIONAL_ATTRS): | |
| fixedip[field] = db_fixedip[field] | |
| if ('instance' in expected_attrs): | |
| fixedip.instance = (objects.Instance._from_db_object(context, objects.Instance(context), db_fixedip['instance']) if db_fixedip['instance'] else None) | |
| if ('network' in expected_attrs): | |
| fixedip.network = (objects.Network._from_db_object(context, objects.Network(context), db_fixedip['network']) if db_fixedip['network'] else None) | |
| if ('virtual_interface' in expected_attrs): | |
| db_vif = db_fixedip['virtual_interface'] | |
| vif = (objects.VirtualInterface._from_db_object(context, objects.VirtualInterface(context), db_fixedip['virtual_interface']) if db_vif else None) | |
| fixedip.virtual_interface = vif | |
| if ('floating_ips' in expected_attrs): | |
| fixedip.floating_ips = obj_base.obj_make_list(context, objects.FloatingIPList(context), objects.FloatingIP, db_fixedip['floating_ips']) | |
| fixedip._context = context | |
| fixedip.obj_reset_changes() | |
| return fixedip | |
| def get_by_id(cls, context, id, expected_attrs=None): | |
| if (expected_attrs is None): | |
| expected_attrs = [] | |
| get_network = ('network' in expected_attrs) | |
| db_fixedip = db.fixed_ip_get(context, id, get_network=get_network) | |
| return cls._from_db_object(context, cls(context), db_fixedip, expected_attrs) | |
| def get_by_address(cls, context, address, expected_attrs=None): | |
| if (expected_attrs is None): | |
| expected_attrs = [] | |
| db_fixedip = db.fixed_ip_get_by_address(context, str(address), columns_to_join=expected_attrs) | |
| return cls._from_db_object(context, cls(context), db_fixedip, expected_attrs) | |
| def get_by_floating_address(cls, context, address): | |
| db_fixedip = db.fixed_ip_get_by_floating_address(context, str(address)) | |
| if (db_fixedip is not None): | |
| return cls._from_db_object(context, cls(context), db_fixedip) | |
| def get_by_network_and_host(cls, context, network_id, host): | |
| db_fixedip = db.fixed_ip_get_by_network_host(context, network_id, host) | |
| return cls._from_db_object(context, cls(context), db_fixedip) | |
| def associate(cls, context, address, instance_uuid, network_id=None, reserved=False, vif_id=None): | |
| db_fixedip = db.fixed_ip_associate(context, address, instance_uuid, network_id=network_id, reserved=reserved, virtual_interface_id=vif_id) | |
| return cls._from_db_object(context, cls(context), db_fixedip) | |
| def associate_pool(cls, context, network_id, instance_uuid=None, host=None, vif_id=None): | |
| db_fixedip = db.fixed_ip_associate_pool(context, network_id, instance_uuid=instance_uuid, host=host, virtual_interface_id=vif_id) | |
| return cls._from_db_object(context, cls(context), db_fixedip) | |
| def disassociate_by_address(cls, context, address): | |
| db.fixed_ip_disassociate(context, address) | |
| def _disassociate_all_by_timeout(cls, context, host, time_str): | |
| time = timeutils.parse_isotime(time_str) | |
| return db.fixed_ip_disassociate_all_by_timeout(context, host, time) | |
| def disassociate_all_by_timeout(cls, context, host, time): | |
| return cls._disassociate_all_by_timeout(context, host, utils.isotime(time)) | |
| def create(self): | |
| updates = self.obj_get_changes() | |
| if ('id' in updates): | |
| raise exception.ObjectActionError(action='create', reason='already created') | |
| if ('address' in updates): | |
| updates['address'] = str(updates['address']) | |
| db_fixedip = db.fixed_ip_create(self._context, updates) | |
| self._from_db_object(self._context, self, db_fixedip) | |
| def save(self): | |
| updates = self.obj_get_changes() | |
| if ('address' in updates): | |
| raise exception.ObjectActionError(action='save', reason='address is not mutable') | |
| db.fixed_ip_update(self._context, str(self.address), updates) | |
| self.obj_reset_changes() | |
| def disassociate(self): | |
| db.fixed_ip_disassociate(self._context, str(self.address)) | |
| self.instance_uuid = None | |
| self.instance = None | |
| self.obj_reset_changes(['instance_uuid', 'instance']) | |
| class FixedIPList(obj_base.ObjectListBase, obj_base.NovaObject, ): | |
| VERSION = '1.15' | |
| fields = {'objects': fields.ListOfObjectsField('FixedIP')} | |
| def _get_count_by_project_from_db(context, project_id): | |
| return context.session.query(models.FixedIp.id).filter_by(deleted=0).join(models.Instance, (models.Instance.uuid == models.FixedIp.instance_uuid)).filter((models.Instance.project_id == project_id)).count() | |
| def get_all(cls, context): | |
| db_fixedips = db.fixed_ip_get_all(context) | |
| return obj_base.obj_make_list(context, cls(context), objects.FixedIP, db_fixedips) | |
| def get_by_instance_uuid(cls, context, instance_uuid): | |
| expected_attrs = ['network', 'virtual_interface', 'floating_ips'] | |
| db_fixedips = db.fixed_ip_get_by_instance(context, instance_uuid) | |
| return obj_base.obj_make_list(context, cls(context), objects.FixedIP, db_fixedips, expected_attrs=expected_attrs) | |
| def get_by_host(cls, context, host): | |
| db_fixedips = db.fixed_ip_get_by_host(context, host) | |
| return obj_base.obj_make_list(context, cls(context), objects.FixedIP, db_fixedips) | |
| def get_by_virtual_interface_id(cls, context, vif_id): | |
| expected_attrs = ['network', 'floating_ips'] | |
| db_fixedips = db.fixed_ips_by_virtual_interface(context, vif_id) | |
| return obj_base.obj_make_list(context, cls(context), objects.FixedIP, db_fixedips, expected_attrs=expected_attrs) | |
| def get_by_network(cls, context, network, host=None): | |
| ipinfo = db.network_get_associated_fixed_ips(context, network['id'], host=host) | |
| if (not ipinfo): | |
| return pycc_corrupt([]) | |
| fips = cls(context=context, objects=[]) | |
| for info in ipinfo: | |
| inst = objects.Instance(context=context, uuid=info['instance_uuid'], hostname=info['instance_hostname'], created_at=info['instance_created'], updated_at=info['instance_updated']) | |
| vif = objects.VirtualInterface(context=context, id=info['vif_id'], address=info['vif_address']) | |
| fip = objects.FixedIP(context=context, address=info['address'], instance_uuid=info['instance_uuid'], network_id=info['network_id'], virtual_interface_id=info['vif_id'], allocated=info['allocated'], leased=info['leased'], default_route=info['default_route'], instance=inst, virtual_interface=vif) | |
| fips.objects.append(fip) | |
| fips.obj_reset_changes() | |
| return fips | |
| def bulk_create(self, context, fixed_ips): | |
| ips = [] | |
| for fixedip in fixed_ips: | |
| ip = obj_base.obj_to_primitive(fixedip) | |
| if ('id' in ip): | |
| raise exception.ObjectActionError(action='create', reason='already created') | |
| ips.append(ip) | |
| db.fixed_ip_bulk_create(context, ips) | |
| def get_count_by_project(cls, context, project_id): | |
| return cls._get_count_by_project_from_db(context, project_id) | |
Xet Storage Details
- Size:
- 11.6 kB
- Xet hash:
- 789cdeb14ac55f5da6966962224b1add5c52fb59f44a2479f49f203b9e3e6734
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.