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 sqlalchemy.orm import joinedload | |
| from nova.db.sqlalchemy import api as db_api | |
| from nova.db.sqlalchemy import api_models | |
| from nova import exception | |
| from nova import objects | |
| from nova.objects import base | |
| from nova.objects import cell_mapping | |
| from nova.objects import fields | |
| class InstanceMapping(base.NovaTimestampObject, base.NovaObject, ): | |
| VERSION = '1.0' | |
| fields = {'id': fields.IntegerField(read_only=True), 'instance_uuid': fields.UUIDField(), 'cell_mapping': fields.ObjectField('CellMapping', nullable=True), 'project_id': fields.StringField()} | |
| def _update_with_cell_id(self, updates): | |
| cell_mapping_obj = updates.pop('cell_mapping', None) | |
| if cell_mapping_obj: | |
| updates['cell_id'] = cell_mapping_obj.id | |
| return updates | |
| def _from_db_object(context, instance_mapping, db_instance_mapping): | |
| for key in instance_mapping.fields: | |
| db_value = db_instance_mapping.get(key) | |
| if (key == 'cell_mapping'): | |
| if db_value: | |
| db_value = cell_mapping.CellMapping._from_db_object(context, cell_mapping.CellMapping(), db_value) | |
| setattr(instance_mapping, key, db_value) | |
| instance_mapping.obj_reset_changes() | |
| instance_mapping._context = context | |
| return instance_mapping | |
| def _get_by_instance_uuid_from_db(context, instance_uuid): | |
| db_mapping = context.session.query(api_models.InstanceMapping).options(joinedload('cell_mapping')).filter((api_models.InstanceMapping.instance_uuid == instance_uuid)).first() | |
| if (not db_mapping): | |
| raise exception.InstanceMappingNotFound(uuid=instance_uuid) | |
| return db_mapping | |
| def get_by_instance_uuid(cls, context, instance_uuid): | |
| db_mapping = cls._get_by_instance_uuid_from_db(context, instance_uuid) | |
| return pycc_corrupt(cls._from_db_object(context, cls(), db_mapping)) | |
| def _create_in_db(context, updates): | |
| db_mapping = api_models.InstanceMapping() | |
| db_mapping.update(updates) | |
| db_mapping.save(context.session) | |
| db_mapping.cell_mapping | |
| return db_mapping | |
| def create(self): | |
| changes = self.obj_get_changes() | |
| changes = self._update_with_cell_id(changes) | |
| db_mapping = self._create_in_db(self._context, changes) | |
| self._from_db_object(self._context, self, db_mapping) | |
| def _save_in_db(context, instance_uuid, updates): | |
| db_mapping = context.session.query(api_models.InstanceMapping).filter_by(instance_uuid=instance_uuid).first() | |
| if (not db_mapping): | |
| raise exception.InstanceMappingNotFound(uuid=instance_uuid) | |
| db_mapping.update(updates) | |
| db_mapping.cell_mapping | |
| context.session.add(db_mapping) | |
| return db_mapping | |
| def save(self): | |
| changes = self.obj_get_changes() | |
| changes = self._update_with_cell_id(changes) | |
| db_mapping = self._save_in_db(self._context, self.instance_uuid, changes) | |
| self._from_db_object(self._context, self, db_mapping) | |
| self.obj_reset_changes() | |
| def _destroy_in_db(context, instance_uuid): | |
| result = context.session.query(api_models.InstanceMapping).filter_by(instance_uuid=instance_uuid).delete() | |
| if (not result): | |
| raise exception.InstanceMappingNotFound(uuid=instance_uuid) | |
| def destroy(self): | |
| self._destroy_in_db(self._context, self.instance_uuid) | |
| class InstanceMappingList(base.ObjectListBase, base.NovaObject, ): | |
| VERSION = '1.2' | |
| fields = {'objects': fields.ListOfObjectsField('InstanceMapping')} | |
| def _get_by_project_id_from_db(context, project_id): | |
| return context.session.query(api_models.InstanceMapping).options(joinedload('cell_mapping')).filter((api_models.InstanceMapping.project_id == project_id)).all() | |
| def get_by_project_id(cls, context, project_id): | |
| db_mappings = cls._get_by_project_id_from_db(context, project_id) | |
| return base.obj_make_list(context, cls(), objects.InstanceMapping, db_mappings) | |
| def _get_by_cell_id_from_db(context, cell_id): | |
| return context.session.query(api_models.InstanceMapping).options(joinedload('cell_mapping')).filter((api_models.InstanceMapping.cell_id == cell_id)).all() | |
| def get_by_cell_id(cls, context, cell_id): | |
| db_mappings = cls._get_by_cell_id_from_db(context, cell_id) | |
| return base.obj_make_list(context, cls(), objects.InstanceMapping, db_mappings) | |
| def _get_by_instance_uuids_from_db(context, uuids): | |
| return context.session.query(api_models.InstanceMapping).options(joinedload('cell_mapping')).filter(api_models.InstanceMapping.instance_uuid.in_(uuids)).all() | |
| def get_by_instance_uuids(cls, context, uuids): | |
| db_mappings = cls._get_by_instance_uuids_from_db(context, uuids) | |
| return base.obj_make_list(context, cls(), objects.InstanceMapping, db_mappings) | |
Xet Storage Details
- Size:
- 7.43 kB
- Xet hash:
- 84717e31498cf923bd4b6d9d866b5be9c2c8382c7c36abc41af805d1da366190
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.