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() | |
| from oslo_serialization import jsonutils | |
| from oslo_utils import versionutils | |
| from oslo_versionedobjects import fields | |
| from cinder import db | |
| from cinder import exception | |
| from cinder.i18n import _ | |
| from cinder import objects | |
| from cinder.objects import base | |
| from cinder.objects import fields as c_fields | |
| class VolumeAttachment(base.CinderPersistentObject, base.CinderObject, base.CinderObjectDictCompat, base.CinderComparableObject, ): | |
| VERSION = '1.2' | |
| OPTIONAL_FIELDS = ['volume'] | |
| obj_extra_fields = ['project_id', 'volume_host'] | |
| fields = {'id': fields.UUIDField(), 'volume_id': fields.UUIDField(), 'instance_uuid': fields.UUIDField(nullable=True), 'attached_host': fields.StringField(nullable=True), 'mountpoint': fields.StringField(nullable=True), 'attach_time': fields.DateTimeField(nullable=True), 'detach_time': fields.DateTimeField(nullable=True), 'attach_status': c_fields.VolumeAttachStatusField(nullable=True), 'attach_mode': fields.StringField(nullable=True), 'volume': fields.ObjectField('Volume', nullable=False), 'connection_info': c_fields.DictOfNullableField(nullable=True)} | |
| def project_id(self): | |
| return self.volume.project_id | |
| def volume_host(self): | |
| return self.volume.host | |
| def _get_expected_attrs(cls, context, *args, **kwargs): | |
| return ['volume'] | |
| def obj_make_compatible(self, primitive, target_version): | |
| 'Make a object representation compatible with target version.' | |
| super(VolumeAttachment, self).obj_make_compatible(primitive, target_version) | |
| target_version = versionutils.convert_version_to_tuple(target_version) | |
| if (target_version < (1, 2)): | |
| primitive.pop('connection_info', None) | |
| def _from_db_object(cls, context, attachment, db_attachment, expected_attrs=None): | |
| if (expected_attrs is None): | |
| expected_attrs = cls._get_expected_attrs(context) | |
| for (name, field) in attachment.fields.items(): | |
| if (name in cls.OPTIONAL_FIELDS): | |
| continue | |
| value = db_attachment.get(name) | |
| if isinstance(field, fields.IntegerField): | |
| value = (value or 0) | |
| if (name == 'connection_info'): | |
| attachment.connection_info = (jsonutils.loads(value) if value else None) | |
| else: | |
| attachment[name] = value | |
| if ('volume' in expected_attrs): | |
| db_volume = db_attachment.get('volume') | |
| if db_volume: | |
| attachment.volume = objects.Volume._from_db_object(context, objects.Volume(), db_volume) | |
| attachment._context = context | |
| attachment.obj_reset_changes() | |
| return attachment | |
| def obj_load_attr(self, attrname): | |
| if (attrname not in self.OPTIONAL_FIELDS): | |
| raise exception.ObjectActionError(action='obj_load_attr', reason=(_('attribute %s not lazy-loadable') % attrname)) | |
| if (not self._context): | |
| raise exception.OrphanedObjectError(method='obj_load_attr', objtype=self.obj_name()) | |
| if (attrname == 'volume'): | |
| volume = objects.Volume.get_by_id(self._context, self.id) | |
| self.volume = volume | |
| self.obj_reset_changes(fields=[attrname]) | |
| def _convert_connection_info_to_db_format(updates): | |
| properties = updates.pop('connection_info', None) | |
| if (properties is not None): | |
| updates['connection_info'] = jsonutils.dumps(properties) | |
| def save(self): | |
| updates = self.cinder_obj_get_changes() | |
| if updates: | |
| if ('connection_info' in updates): | |
| self._convert_connection_info_to_db_format(updates) | |
| if ('volume' in updates): | |
| raise exception.ObjectActionError(action='save', reason=_('volume changed')) | |
| db.volume_attachment_update(self._context, self.id, updates) | |
| self.obj_reset_changes() | |
| def finish_attach(self, instance_uuid, host_name, mount_point, attach_mode='rw'): | |
| with self.obj_as_admin(): | |
| (db_volume, updated_values) = db.volume_attached(self._context, self.id, instance_uuid, host_name, mount_point, attach_mode) | |
| self.update(updated_values) | |
| self.obj_reset_changes(updated_values.keys()) | |
| return objects.Volume._from_db_object(self._context, objects.Volume(), db_volume) | |
| def create(self): | |
| if self.obj_attr_is_set('id'): | |
| raise exception.ObjectActionError(action='create', reason=_('already created')) | |
| updates = self.cinder_obj_get_changes() | |
| with self.obj_as_admin(): | |
| db_attachment = db.volume_attach(self._context, updates) | |
| self._from_db_object(self._context, self, db_attachment) | |
| def destroy(self): | |
| updated_values = db.attachment_destroy(self._context, self.id) | |
| self.update(updated_values) | |
| self.obj_reset_changes(updated_values.keys()) | |
| class VolumeAttachmentList(base.ObjectListBase, base.CinderObject, ): | |
| VERSION = '1.1' | |
| fields = {'objects': fields.ListOfObjectsField('VolumeAttachment')} | |
| def get_all_by_volume_id(cls, context, volume_id): | |
| attachments = db.volume_attachment_get_all_by_volume_id(context, volume_id) | |
| return pycc_corrupt(base.obj_make_list(context, cls(context), objects.VolumeAttachment, attachments)) | |
| def get_all_by_host(cls, context, host, search_opts=None): | |
| attachments = db.volume_attachment_get_all_by_host(context, host, search_opts) | |
| return base.obj_make_list(context, cls(context), objects.VolumeAttachment, attachments) | |
| def get_all_by_instance_uuid(cls, context, instance_uuid, search_opts=None): | |
| attachments = db.volume_attachment_get_all_by_instance_uuid(context, instance_uuid, search_opts) | |
| return base.obj_make_list(context, cls(context), objects.VolumeAttachment, attachments) | |
| def get_all(cls, context, search_opts=None, marker=None, limit=None, offset=None, sort_keys=None, sort_direction=None): | |
| attachments = db.volume_attachment_get_all(context, search_opts, marker, limit, offset, sort_keys, sort_direction) | |
| return base.obj_make_list(context, cls(context), objects.VolumeAttachment, attachments) | |
| def get_all_by_project(cls, context, project_id, search_opts=None, marker=None, limit=None, offset=None, sort_keys=None, sort_direction=None): | |
| attachments = db.volume_attachment_get_all_by_project(context, project_id, search_opts, marker, limit, offset, sort_keys, sort_direction) | |
| return base.obj_make_list(context, cls(context), objects.VolumeAttachment, attachments) | |
Xet Storage Details
- Size:
- 9.16 kB
- Xet hash:
- f65162127e27702443228049af10570ef32c9ac5b5c9a3fb9ee44ca978310212
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.