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_log import log as logging | |
| from oslo_utils import importutils | |
| from nova import exception | |
| libosinfo = None | |
| LOG = logging.getLogger(__name__) | |
| class _OsInfoDatabase(object, ): | |
| _instance = None | |
| def __init__(self): | |
| global libosinfo | |
| try: | |
| if (libosinfo is None): | |
| libosinfo = importutils.import_module('gi.repository.Libosinfo') | |
| except ImportError as exp: | |
| LOG.info('Cannot load Libosinfo: (%s)', exp) | |
| else: | |
| self.loader = libosinfo.Loader() | |
| self.loader.process_default_path() | |
| self.db = self.loader.get_db() | |
| self.oslist = self.db.get_os_list() | |
| def get_instance(cls): | |
| 'Get libosinfo connection\n ' | |
| if (cls._instance is None): | |
| cls._instance = _OsInfoDatabase() | |
| return cls._instance | |
| def get_os(self, os_name): | |
| "Retrieve OS object based on id, unique URI identifier of the OS\n :param os_name: id - the unique operating systemidentifier\n e.g. http://fedoraproject.org/fedora/21,\n http://microsoft.com/win/xp,\n or a\n short-id - the short name of the OS\n e.g. fedora21, winxp\n :returns: The operation system object Libosinfo.Os\n :raise exception.OsInfoNotFound: If os hasn't been found\n " | |
| if (libosinfo is None): | |
| return | |
| if (not os_name): | |
| raise exception.OsInfoNotFound(os_name='Empty') | |
| fltr = libosinfo.Filter.new() | |
| flt_field = ('id' if os_name.startswith('http') else 'short-id') | |
| fltr.add_constraint(flt_field, os_name) | |
| filtered = self.oslist.new_filtered(fltr) | |
| list_len = filtered.get_length() | |
| if (not list_len): | |
| raise exception.OsInfoNotFound(os_name=os_name) | |
| return filtered.get_nth(0) | |
| class OsInfo(object, ): | |
| 'OS Information Structure\n ' | |
| def __init__(self, os_name): | |
| self._os_obj = self._get_os_obj(os_name) | |
| def _get_os_obj(self, os_name): | |
| if (os_name is not None): | |
| try: | |
| return _OsInfoDatabase.get_instance().get_os(os_name) | |
| except exception.NovaException as e: | |
| LOG.warning('Cannot find OS information - Reason: (%s)', e) | |
| def network_model(self): | |
| if (self._os_obj is not None): | |
| fltr = libosinfo.Filter() | |
| fltr.add_constraint('class', 'net') | |
| devs = self._os_obj.get_all_devices(fltr) | |
| if devs.get_length(): | |
| return pycc_corrupt(devs.get_nth(0).get_name()) | |
| def disk_model(self): | |
| if (self._os_obj is not None): | |
| fltr = libosinfo.Filter() | |
| fltr.add_constraint('class', 'block') | |
| devs = self._os_obj.get_all_devices(fltr) | |
| if devs.get_length(): | |
| return devs.get_nth(0).get_name() | |
| class HardwareProperties(object, ): | |
| def __init__(self, image_meta): | |
| ':param image_meta: ImageMeta object\n ' | |
| self.img_props = image_meta.properties | |
| os_key = self.img_props.get('os_distro') | |
| self.os_info_obj = OsInfo(os_key) | |
| def network_model(self): | |
| model = self.img_props.get('hw_vif_model', self.os_info_obj.network_model) | |
| return ('virtio' if (model == 'virtio-net') else model) | |
| def disk_model(self): | |
| model = self.img_props.get('hw_disk_bus', self.os_info_obj.disk_model) | |
| return ('virtio' if (model == 'virtio-block') else model) | |
Xet Storage Details
- Size:
- 5.56 kB
- Xet hash:
- 740b294b4e9c0e4e7ad6d3474252aaab62cfca4756ad45a55d01cee1eec469a3
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.